2020牛客寒假算法基础集训营1
题意:
hanayo很喜欢吃米饭。
有一天,她拿出了 n个碗,第一个碗装了 1 粒米饭,第二个碗装了 2粒米饭,以此类推,第 n碗装了 n粒米饭。
然而,爱搞恶作剧的rin把所有的碗的顺序打乱,并拿走了一个碗。hanayo想知道,rin拿走的碗里有多少粒米饭?
分析:
解法很多,我用了异或的性质,x^x=0,直接看代码吧…
代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
const int maxn=1e5+50;
const int inf=0x3f3f3f3f;
int main()
{
int n,x,a,b;
scanf("%d",&n);
int ans=0;
for(int i=1;i<=n;i++)
ans^=i;
for(int i=1;i<=n-1;i++){
scanf("%d",&x);
ans^=x;
}
printf("%d\n",ans);
return 0;
}