problem link:
Discuss: Just simply do xor of all pile. if it is non zero then jack is win otherwise jill
try your self before see the code
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(cin >>n&&n)
{
int i,j,jill=0,jack=0;
vector<int>vec;
for(i=0;i<n;i++)
{
cin >>j;
vec.push_back(j);
}
jack=vec[0];
for(i=1;i<n;i++)
{
jack=jack^vec[i];
}
if(jack)
cout <<"Yes"<<endl;
else
cout <<"No"<<endl;
}
return 0;
}
Discuss: Just simply do xor of all pile. if it is non zero then jack is win otherwise jill
try your self before see the code
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(cin >>n&&n)
{
int i,j,jill=0,jack=0;
vector<int>vec;
for(i=0;i<n;i++)
{
cin >>j;
vec.push_back(j);
}
jack=vec[0];
for(i=1;i<n;i++)
{
jack=jack^vec[i];
}
if(jack)
cout <<"Yes"<<endl;
else
cout <<"No"<<endl;
}
return 0;
}
No comments:
Post a Comment