题目链接:https://ac.nowcoder.com/acm/contest/890#question
B:
cf897C跟这个题非常像。递归完事。
1 /* Nowcoder Contest 890 2 * Problem B 3 * Au: SJoshua 4 */ 5 #include <cassert> 6 #include <cstdio> 7 #include <vector> 8 #include <string> 9 #include <iostream> 10 #include <algorithm> 11 12 using namespace std; 13 14 const string A("COFFEE"), B("CHICKEN"); 15 16 vector <long long int> len(70); 17 18 char solve(int index, long long int pos) { 19 assert(1 <= index && 1 <= pos); 20 if (index == 1) { 21 if (pos <= 6) { 22 return A[pos - 1]; 23 } else { 24 return ' '; 25 } 26 } else if (index == 2) { 27 if (pos <= 7) { 28 return B[pos - 1]; 29 } else { 30 return ' '; 31 } 32 } 33 if (pos <= len[index - 2]) { 34 return solve(index - 2, pos); 35 } else { 36 return solve(index - 1, pos - len[index - 2]); 37 } 38 } 39 40 int main(void) { 41 int T; 42 cin >> T; 43 len[1] = 6; 44 len[2] = 7; 45 for (int i = 3; i <= 69; i++) { 46 len[i] = len[i - 1] + len[i - 2]; 47 } 48 while (T--) { 49 int n; 50 long long int k; 51 cin >> n >> k; 52 n = min(n, 69); 53 for (long long int pos = k; pos < k + 10; pos++) { 54 if (pos <= len[n]) { 55 cout << solve(n, pos); 56 } 57 } 58 cout << endl; 59 } 60 return 0; 61 }
D:
exCRT模板题,注意会爆long long。
1 ai = [] 2 bi = [] 3 4 for i in range(200): 5 ai.append(0) 6 bi.append(0) 7 8 def mul(a, b, mod): 9 ret = 0 10 while b > 0: 11 if b & 1: 12 ret = (ret + a) % mod 13 a = (a + a) % mod 14 b >>= 1 15 return ret 16 17 x = 0 18 y = 0 19 20 def exgcd(a, b): 21 global x, y 22 if b == 0: 23 x = 1 24 y = 0 25 return a 26 gcd = exgcd(b, a % b) 27 tp = x 28 x = y 29 y = tp - a // b * y 30 return gcd 31 32 def excrt(): 33 global x, y 34 M = bi[1] 35 ans = ai[1] 36 for i in range(2, n + 1): 37 a = M 38 b = bi[i] 39 c = (ai[i] - ans % b + b) % b 40 gcd = exgcd(a, b) 41 bg = b // gcd 42 if c % gcd != 0: 43 print("he was definitely lying") 44 exit() 45 x = mul(x, c // gcd, bg) 46 ans += x * M 47 M *= bg 48 ans = (ans % M + M) % M 49 return (ans % M + M) % M 50 51 (n, k) = map(int, input().split()) 52 for i in range(1, n + 1): 53 (t1, t2) = map(int, input().split()) 54 bi[i] = t1 55 ai[i] = t2 56 ans = excrt() 57 if ans <= k: 58 print(ans) 59 else: 60 p
E:
分治判断点的位置。
/* Nowcoder Contest 890 * Problem E * Au: SJoshua */ #include <cstdio> #include <vector> #include <string> #include <iostream> #include <algorithm> using namespace std; struct cord { int x, y; unsigned long long int dis; }; bool inRange(unsigned long long int n, unsigned long long int a, unsigned long long int b) { return a <= n && n <= b; } //LURD unsigned long long int calc(int x, int y, unsigned long long int base, int size, int mode = 2) { // cout << x << ", " << y << ": " << base << "(" << size << ")"<<mode<< endl; if (!size) { return base; } int half = 1 << (size - 1); unsigned long long int block = (unsigned long long int) half * half; if (inRange(x, 1, half) && inRange(y, 1, half)) { switch (mode) { case 1: return calc(x, y, base + block * 0, size - 1, 2); case 2: return calc(x, y, base + block * 0, size - 1, 1); case 3: return calc(x, y, base + block * 2, size - 1, 3); case 4: return calc(x, y, base + block * 2, size - 1, 4); } } else if (inRange(x, 1, half) && inRange(y, 1 + half, half + half)) { switch (mode) { case 1: return calc(x, y - half, base + block * 1, size - 1, 1); case 2: return calc(x, y - half, base + block * 3, size - 1, 3); case 3: return calc(x, y - half, base + block * 3, size - 1, 2); case 4: return calc(x, y - half, base + block * 1, size - 1, 4); } } else if (inRange(x, 1 + half, half + half) && inRange(y, 1, half)) { switch (mode) { case 1: return calc(x - half, y, base + block * 3, size - 1, 4); case 2: return calc(x - half, y, base + block * 1, size - 1, 2); case 3: return calc(x - half, y, base + block * 1, size - 1, 3); case 4: return calc(x - half, y, base + block * 3, size - 1, 1); } } else if (inRange(x, 1 + half, half + half) && inRange(y, 1 + half, half + half)) { switch (mode) { case 1: return calc(x - half, y - half, base + block * 2, size - 1, 1); case 2: return calc(x - half, y - half, base + block * 2, size - 1, 2); case 3: return calc(x - half, y - half, base + block * 0, size - 1, 4); case 4: return calc(x - half, y - half, base + block * 0, size - 1, 3); } } return 0; } int main(void) { int n, k; cin >> n >> k; vector <cord> pos(n); for (int i = 0; i < n; i++) { cin >> pos[i].x >> pos[i].y; pos[i].dis = calc(pos[i].x, pos[i].y, 0, k); } sort(pos.begin(), pos.end(), [](cord &a, cord &b)->bool { return a.dis < b.dis; }); for (auto e: pos) { cout << e.x << " " << e.y /* << "->" << e.dis*/ << endl; } return 0; }
F:
数据结构乱搞题。
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson (curpos<<1) 15 #define rson (curpos<<1|1) 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 const int maxn = 1e5 + 10; 21 int n, r, cntX[maxn * 3], cntY[maxn * 3], res; 22 struct Point { 23 int x, y; 24 bool operator<(const Point &rhs)const { 25 return x > rhs.x; 26 } 27 } a[maxn], sum[maxn]; 28 29 int main() { 30 scanf("%d%d", &n, &r); 31 for (int i = 0; i < n; i++) { 32 scanf("%d%d", &a[i].x, &a[i].y); 33 cntX[a[i].x]++; 34 } 35 for (int i = 0; i < maxn; i++) { 36 sum[i].x = cntX[i] + cntX[i + r] + cntX[i + r * 2]; 37 sum[i].y = i; 38 } 39 sort(sum, sum + maxn); 40 for (int i = 0; i < 100; i++) { 41 memset(cntY, 0, sizeof(cntY)); 42 for (int j = 0; j < n; j++) 43 if (a[j].x != sum[i].y && a[j].x != sum[i].y + r && a[j].x != sum[i].y + r * 2) 44 cntY[a[j].y]++; 45 int my = 0; 46 for (int j = 0; j < maxn; j++) 47 my = max(my, cntY[j] + cntY[j + r] + cntY[j + r * 2]); 48 res = max(res, my + sum[i].x); 49 } 50 printf("%d ", res); 51 return 0; 52 }
H:
看点的度数判一下就行。
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson (curpos<<1) 15 #define rson (curpos<<1|1) 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 int d[10], d2[10]; 21 22 int main() { 23 int t; scanf("%d", &t); 24 while (t--) { 25 vector<int>a[10]; 26 for (int i = 0; i < 7; i++) { 27 d[i] = d2[i] = 0; a[i].clear(); 28 } 29 for (int i = 1; i <= 5; i++) { 30 int x, y; scanf("%d%d", &x, &y); 31 d2[x]++, d2[y]++; d[x]++, d[y]++; 32 a[x].pb(y), a[y].pb(x); 33 } 34 sort(d2 + 1, d2 + 7); 35 if (d2[6] == 2) puts("n-hexane"); 36 else if (d2[6] == 4) puts("2,2-dimethylbutane"); 37 else if (d2[4] == 1) puts("2,3-dimethylbutane"); 38 else { 39 int pos; 40 for (pos = 1; pos < 7; pos++) 41 if (d[pos] == 3) break; 42 if (d[a[pos][0]] + d[a[pos][1]] + d[a[pos][2]] == 4) puts("2-methylpentane"); 43 else if (d[a[pos][0]] + d[a[pos][1]] + d[a[pos][2]] == 5) puts("3-methylpentane"); 44 } 45 } 46 return 0; 47 }