#include<cstdio>int t, n, num;intmain(){scanf("%d",&t);while(t--){scanf("%d",&n);int odd =0;for(int i =1; i <= n; i++){scanf("%d",&num);if(num &1) odd++;}if(odd ==0||(!(odd &1)&& odd == n))printf("NO\n");elseprintf("YES\n");}return0;}
B
#include<cstdio>int t, n;intmain(){scanf("%d",&t);while(t--){scanf("%d",&n);int ans = n;while(n >=10){int t = n /10;
ans += t;
n += t - t *10;}printf("%d\n", ans);}return0;}
C
有mp记录每个位置是否被访问过。 如果访问过代表走了个环。 求出走的路径长度。
#include<cstdio>#include<algorithm>#include<map>#define mk(x,y) make_pair(x,y)usingnamespace std;constint N =2e5+5;char s[N];int t, n;intmain(){scanf("%d",&t);while(t--){scanf("%d%s",&n, s +1);
map<pair<int,int>,int> mp;
mp[mk(0,0)]=1;//作为起点 int x =0, y =0, l, r, minv =1e9;for(int i =1; i <= n; i++){if(s[i]=='L') x--;elseif(s[i]=='R') x++;elseif(s[i]=='U') y++;elseif(s[i]=='D') y--;
pair<int,int> t =mk(x, y);if(mp.count(t)){//取个最小值 int d = i - mp[t];if(d < minv){
minv = d; r = i, l = mp[t];}}
mp[mk(x, y)]= i +1;//及时更新位置 }if(minv ==1e9)printf("-1\n");elseprintf("%d %d\n", l, r);}return0;}