# HDU-1850 Being a Good Boy in Spring Festival(HDU-1850 Being a Good Boy in Spring Festival)-go

## HDU-1850 Being a Good Boy in Spring Festival(HDU-1850 Being a Good Boy in Spring Festival)

### Being a Good Boy in Spring Festival

tips: \(\oplus\) 的优先级比 \(>\) 低

``````#include <iostream>
using namespace std;
const int maxn = 110;
int num[maxn];

int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
while(cin >> n && n)
{
for(int i=0; i<n; i++) cin >> num[i];
int sum = 0;
for(int i=0; i<n; i++) sum ^= num[i];
int ans = 0;
for(int i=0; i<n; i++) if(num[i] > (sum ^ num[i])) ans++;
if(sum == 0) ans = 0;
cout << ans << endl;
}
return 0;
}
``````
————————

### Being a Good Boy in Spring Festival

Nimm Game

After the XOR sum is obtained, \ (sum \ oplus num [i] \) is to remove the current value, and the XOR sum of other numbers. In order to make the overall XOR 0, it is necessary to make the current \ (Num [i] \) become \ (sum \ oplus num [i] \). Therefore, if \ (Num [i] & gt; sum \ oplus num [i] \) is changed, it is feasible to change this \ (Num [i] \) when it is equal to zero, so it is not feasible

Tips: \ (\ oplus \) has a lower priority than \ (& gt; \)

``````#include <iostream>
using namespace std;
const int maxn = 110;
int num[maxn];

int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
while(cin >> n && n)
{
for(int i=0; i<n; i++) cin >> num[i];
int sum = 0;
for(int i=0; i<n; i++) sum ^= num[i];
int ans = 0;
for(int i=0; i<n; i++) if(num[i] > (sum ^ num[i])) ans++;
if(sum == 0) ans = 0;
cout << ans << endl;
}
return 0;
}
``````