hdu 1259 ZJUTACM

很水~

就是记录j的位置就行了,可是第一次WA了,以为是自己理解有误,上网上看了一下,原来是并行的问题。

//这样写是错的

if(x==s)

s=y;

if(y==s)

s=x;

要用if...else if

代码:

 1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<string.h>
4 int main()
5 {
6 int t,m,x,y,s;
7 scanf("%d",&t);
8 while(t--)
9 {
10 scanf("%d",&m);
11 s=2;
12 while(m--)
13 {
14 scanf("%d%d",&x,&y);
15 if(x==s)
16 {
17 s=y;
18 }
19 else if(y==s)
20 {
21 s=x;
22 }
23 }
24 printf("%d\n",s);
25 }
26 return 0;
27 }



原文地址:https://www.cnblogs.com/misty1/p/2291150.html