8月6号阿里笔试
同时附上AC代码
第一题 新世界
#include<iostream> #include<cstring> #include<algorithm> #include<cstdio> using namespace std; int d, m, w; int i, j, k; typedef long long ll; int main() { scanf("%d%d%d", &d, &m, &w); scanf("%d%d%d", &i, &j, &k); ll y = m * d; ll total = (k - 1) * y + (j - 1) * d + i; ll res = (total - 1) % w; printf("%c\n", 'a' + res); return 0; }
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> using namespace std; const int N = 10010; int p[N]; int n; int a, b, c, t; int find(int x) { if (x != p[x]) p[x] = find(p[x]); return p[x]; } int main() { scanf("%d", &n); for (int i = 0; i < N; i++) p[i] = i; while (n--) { scanf("%d", &t); if (t == 1) { scanf("%d%d", &a, &b); int pa = find(p[a]); int pb = find(p[b]); if (pa != pb) p[pa] = pb; } else { scanf("%d%d%d", &a, &b, &c); a = a % c; b = b % c; if (find(p[a]) == find(p[b])) puts("YES"); else puts("NO"); } } }