Q 1021 Sacretment of the Sum
Thanks for everybody for the help.
Removed code :)
Edited by author 04.08.2011 16:55
Re: Q 1021 Sacretment of the Sum
Послано
Megov 15 мар 2009 22:22
Use binary search
Re: Q 1021 Sacretment of the Sum
Like how do you do binary search?
Can you list an example?
Re: Q 1021 Sacretment of the Sum
Послано
Megov 16 мар 2009 21:29
input(a);
input(b);
bool ok = false;
for( int i = 0; i < a.size(); i++ )
if ( binary_search(b, 10000 - a[i]) )
ok = true;
Re: Q 1021 Sacretment of the Sum
What is the type of a and b?
Re: Q 1021 Sacretment of the Sum
IMHO simply Hash Table is faster =)
Re: WA Test 4 !!
// 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;}
Re: WA Test 4 !!
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
Re: WA Test 4 !!
Oh, sorry ! Now I realize my mistake.. I misunderstood the question! Thank You ! :)
Re: Q 1021 Sacretment of the Sum
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