P2913 [USACO08OCT]车轮旋转Wheel Rotation

传送门

初始状态是 0,如果有 1 的连接,0 就变 1,如果还有 1 的连接,1 就变 0,如果是 0 的连接就不变

所以就是把答案异或上所有连接,不用考虑顺序,反正最终是一样的

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
    return x*f;
}
int n,ans;
int main()
{
    int a;
    n=read();
    for(int i=1;i<n;i++)
        a=read(),a=read(),a=read(),ans^=a;
    printf("%d",ans);
    return 0;
}

 

posted @ 2018-10-28 10:06  LLTYYC  阅读(226)  评论(0编辑  收藏  举报