【题目链接】:
【题意】
一开始骨头在1号位置; 然后有m个洞,给出洞的下标; 然后有k个交换操作; 如果骨头到洞里了,就不能再交换了; 骨头就一直待在洞的下标位置; 问你k个操作后骨头在哪里【题解】
用个一维数组模拟; 1代表骨头,0代表不是骨头; 然后开个map记录哪里是洞; 如果骨头到洞里面去了;就结束; 否则输出k次操作后1的下标就好了 【Number Of WA】 0 【完整代码】#includeusing namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define LL long long#define rep1(i,a,b) for (int i = a;i <= b;i++)#define rep2(i,a,b) for (int i = a;i >= b;i--)#define mp make_pair#define ps push_back#define fi first#define se second#define rei(x) scanf("%d",&x)#define rel(x) scanf("%lld",&x)#define ref(x) scanf("%lf",&x)#define ms(x,y) memset(x,y,sizeof x)typedef pair pii;typedef pair pll;const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1};const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1};const double pi = acos(-1.0);const int N = 1e6+100;map dic;int n,m,k,a[N];int main(){ //freopen("F:\\rush.txt","r",stdin); rei(n),rei(m),rei(k); ms(a,0); a[1] = 1; rep1(i,1,m) { int x; rei(x); dic[x] = 1; } if (dic[1]) return puts("1"),0; bool down = false; rep1(i,1,k) { int x1,y1; rei(x1),rei(y1); swap(a[x1],a[y1]); if (a[x1]==1 || a[y1]==1) { if (dic[x1] || dic[y1]) break; } } rep1(i,1,n) if (a[i]==1) return printf("%d\n",i),0; //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC); return 0;}