|
|
back to boardThanks 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 |
|
|