Общий форумSubmitting one problem I had a compilation error with making my own set comparator, although the program had succesfully been compiled by G++(GCC) 4.4.3 and Visual Studio 2008 compilers on my computer. By submitting some test programs I've found that the error is somehow related to the lower/upper_bound method of map and set containers. For instance, the code like this gets a compilation: #include <set> using namespace std; struct Less { bool operator()(pair <int,int> a, pair <int,int> b) { return a.first < b.first; } }; set <pair <int,int> , Less> s; set <pair <int,int>, Less>::iterator it; int main() { s.insert(make_pair(1,1)); it = s.lower_bound(make_pair(0,1)); return 0; }
The error message is following: 5bf1d001-ac4d-4354-a106-244d4befaf4e S:\checker\compile\\Vc7\include\xtree(988): error: no instance of function "Less::operator()" matches the argument list and object (the object has cv-qualifiers that prevent a match) argument types are: (const std::pair<int, int>, const std::_Tree<std::_Tset_traits<std::pair<int, int>, Less, std::allocator<std::pair<int, int>>, false>>::key_type) object type is: const Less if (this->comp(_Key(_Pnode), _Keyval)) ^ detected during: instantiation of "std::_Tree<_Traits>::_Nodeptr std::_Tree<_Traits>::_Lbound(const std::_Tree<_Traits>::key_type &) const [with _Traits=std::_Tset_traits<std::pair<int, int>, Less, std::allocator<std::pair<int, int>>, false>]" at line 801 instantiation of "std::_Tree<_Traits>::iterator std::_Tree<_Traits>::lower_bound(const std::_Tree<_Traits>::key_type &) [with _Traits=std::_Tset_traits<std::pair<int, int>, Less, std::allocator<std::pair<int, int>>, false>]" at line 21 of "5bf1d001-ac4d-4354-a106-244d4befaf4e" compilation aborted for 5bf1d001-ac4d-4354-a106-244d4befaf4e (code 2) So I think that it makes some STL features unavailable and wish it to be fixed. Does anybody know what can this test contain? I get WA every time I send my solution, can anybody give me some advice? If you need my code, you can connect me on the ICQ (425805594) Thanks for everybody for the help. Removed code :) Edited by author 04.08.2011 16:55 Use binary search Like how do you do binary search? Can you list an example? input(a); input(b); bool ok = false; for( int i = 0; i < a.size(); i++ ) if ( binary_search(b, 10000 - a[i]) ) ok = true; What is the type of a and b? IMHO simply Hash Table is faster =) // WHY IS THIS WRONG !! #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int n,x; vector <int> N; cin>>n; for(int a=0; a<n; a++){ cin>>x; N.push_back(x); } cin>>n; for(int a=0; a<n; a++){ cin>>x; N.push_back(x); } sort(N.begin(), N.end()); n=N.size(); bool t(1); for(int a=0; a<n; a++){ if(binary_search(N.begin(), N.end(), 10000-N[a])){ cout<<"YES"; t=0; break; } } if(t) cout<<"NO"; return 0;} why you add second list in N ? I think (i don't now c++) [code deleted] (I recieve this code ang get AC) Please reply on this messge I have to delete it after =) Edited by author 13.01.2010 20:35 Oh, sorry ! Now I realize my mistake.. I misunderstood the question! Thank You ! :) delete this: if (lista[a]+listb[x]>10000) { continue; } else if (lista[a]+listb[x]<10000) { break; } rewrite this: if(valuea[a]+valueb[x]==10000) { cout<<"YES"; break; } else break; you ca adapt this ideea good luck I think at one stop which is the start stop of another route,we can print that route start with the common stop.But this is not the solution with the minimum stops.I got wa on test 1.I'm confused.Can anybody help me? My code: [code cut out] Edited by moderator 09.08.2004 02:40 I have WA#1 too. But I think that my program must work correctly. I always output the route with a number of stops equal to the m_1+m_2+...+m_n (m_k is a number of stops in k_th route). So I have a question: for input 2 4 1 2 3 4 1 4 1 2 3 4 1 should I output 4 1 2 3 4 1 or the output 8 1 2 3 4 1 2 3 4 1 is also OK? I haven't looked November Rain's program yet, but I suspect he to have the same algorithm that I have. 2 4 1 2 3 4 1 4 1 2 3 4 1 Test is incorrect "None of the routes shared the same section of road" Who knows, what contains this test?? Please, heeeelp!!!) And tell me please - can test contain russian letters, or only latin? (*хахахах-это русский текст!!*) - answer is NO or YES? My program says (*хахахах-это русский текст!!*) // YES Test 26 is possibly consists from many '(', if you use in your program stack then size of stack must be more then 255. I think it's better to use a variable that counts open brackets '(' [UCTeam] Borzunov Alexander [hX] No subject 18 мар 2010 23:19 If solutions really will be execute faster if I will use threads (Delphi TThread)? If this possible? Edited by author 18.03.2010 23:21 Could you help me. Why the answer in first test is YES. why not -2 0 -1 4 4 0 Sorry. I have found my mistake. Please tell me why it can't be. I have the same answer on this test Nothing to wonder: log_3(2^32) < 21, thus you need to test at most 2^21 possibilities. 1.Amount of calls "BELL&RET" must be equal to K. 2.Some tests, to check & understand problem :) 1 BELL&RET 2 CALL 1 BELL&RET 3 CALL 2 CALL 2 BELL&RET 4 CALL 1 CALL 2 BELL&RET 5 CALL 3 CALL 2 CALL 3 BELL&RET 6 CALL 1 CALL 3 CALL 3 BELL&RET 7 CALL 4 CALL 2 CALL 4 CALL 4 BELL&RET поделитесь где найти какую-то инфу по этому оператору. i need any information about this op in C++. спасибо большое заранее. thanks a lot. Can I just search,or there're some other better ways? 7 is! Edited by author 18.03.2010 10:51 i am freshman in learning c. so please help me to solving this pulzz. what is the meaning of " while (!feof(stdin)) "? while(stream stdin hasn't finished) can u send me test # 1 or another test which has the same property with test#1. i think my program works correctly..... I got AC with O(n^3) solution, based on DP. I suppose, that testcases are too weak. Anyway, I think, that it's not normal to get AC for O(n^3) solution. ) My solution is n3, but it doesn't have to check all posibilities. Some part of array f[][] is never used. Besides, I don't know a better way. It is not O(n^3): the expected number of tests for each sub-interval is 2 and thus DP is O(n^2). My mail: bsc98001@yahoo.com > My mail: bsc98001@yahoo.com Try to eliminate all RGB consecutive but be aware to not "destroy" a rare node (i.e. eliminate them in descending order) What seems to be O(n^3) DP is AC as far as you remember to use "break" for N, ####...N/2times ####...N/2 times consider first half N/2 digits sum(digit root) will always be from 0 to 9 it will be 0 only if all digits are 0's and it'll will 1,2,3 .... ,9 in other cases... for N=4 first half will have 2 digits ( total 100 numbers ) 1 number(00) will have digit root = 0 99 numbers will have digit root other than 0 ( i.e 11 numberes --> digit root 1 , 11 numbers ---> digit root 2 etc ) so for N=4 , case i : first half = 00 second half =00 -----> n1 = 1 case ii: first half --> 99 ways , second half --> 11 ways n2= 99*11 total number = n1+n2 = 99*11 + 1 similarly for N=6 , we have 999*111 + 1 N=8 , 9999*1111 + 1 so on... Do not use BigInteger to calculate. Let k = n/2, then the result is 10 for k=1; otherwise it is a concatenation of "1"x(k-1), "0", "8"x(k-2), and "90": 1 10 2 1090 3 110890 4 11108890 5 1111088890 6 111110888890 7 11111108888890 8 1111111088888890 9 111111110888888890 Mine quite straightforward realization works about 1 sec. and uses almost 60 megabytes of memory. Please, give an idea how to solve it more quickly... Edited by author 17.03.2010 14:10 Input french string "Administrateurs" and compaire it with english string "Administrators". Expected result: True Sample code: string a = Environment.UserName; if (a.Equals("Administrator",StringComparison. CurrentCultureIgnoreCase)) { Console.WriteLine("Good"); } output: Good |
|