正睿20秋季提高十连测day2
估分: 40 + 100 + 0 = 140
实际: 10 + 100 + 0 = 110
T1:
错题原因:没想到正解,暴力把代码写炸了
正解:贪心,一层循环枚举月份,二层循环枚举买哪种钻石
1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<cstring> 5 using namespace std; 6 7 typedef long long LL; 8 9 const int N = 4e5 + 10, INF = 0x3f3f3f3f; 10 11 int n, m; 12 int c[N], res; 13 14 struct node 15 { 16 int p, lim; 17 }a[N]; 18 19 inline bool cmp(node x, node y) 20 { 21 return x.p < y.p; 22 } 23 24 int main() 25 { 26 scanf("%d%d", &n, &m); 27 for (int i = 1; i <= n; i++) scanf("%d", &c[i]); 28 for (int i = 1; i <= m; i++) 29 { 30 scanf("%d%d", &a[i].p, &a[i].lim); 31 if (a[i].lim < 0) 32 a[i].lim = INF; 33 } 34 35 sort(a + 1, a + m + 1, cmp); 36 37 LL ans = 0; 38 for (int i = 1; i <= m; i++) 39 { 40 res = 0; 41 LL sum = 0; 42 for (int j = 1; j <= n; j++) 43 { 44 sum += a[i].lim; 45 if (sum < c[j]) res = 1, c[j] -= sum, sum = 0; 46 else sum -= c[j], c[j] = 0; 47 } 48 ans += (n * 1ll * a[i].lim - sum) * a[i].p; 49 if (!res) break; 50 } 51 printf("%lld\n", ans); 52 53 }
T2:
简单的贪心排序;
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 7 int read() 8 { 9 int x = 0, f = 0; 10 char ch = getchar(); 11 while (!isdigit(ch)) f = ch == '-', ch = getchar(); 12 while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); 13 return f ? -x : x; 14 } 15 16 const int N = 300010; 17 18 int n; 19 string str[N]; 20 21 bool cmp(string a, string b) 22 { 23 return a + b < b + a; 24 } 25 26 int main() 27 { 28 n = read(); 29 for (int i = 1; i <= n; i++) cin >> str[i]; 30 sort(str + 1, str + 1 + n, cmp); 31 for (int i = 1; i <= n; i++) cout << str[i]; 32 }
T3:
错题原因:不会
正解:题意相当于n堆石子,每次可以选择一堆或两堆拿,拿走最后一个石子的人获胜,再进行下面一番神奇的运算得出结果

1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 7 using namespace std; 8 9 typedef long long LL; 10 typedef pair<int, int> PII; 11 12 const int mod = 1e9 + 7; 13 14 int n; 15 int b1[60]; 16 LL b2[60], b3[60], ans; 17 18 void ins(LL x, LL y, int z) 19 { 20 for (int i = 59; i + 1; i--) 21 { 22 if (x >> i & 1 || y >> i & 1) 23 { 24 if (!b2[i] && !b3[i]) 25 { 26 b2[i] = x, b3[i] = y, b1[i] = z; 27 } 28 29 if (z > b1[i]) swap(x, b2[i]), swap(y, b3[i]), swap(z, b1[i]); 30 31 LL p = b2[i], q = b3[i]; 32 if ((y ^ q) >> i & 1) swap(p, q); 33 LL u = (x & ~(p | q)) | (y & p) | (~(x | y) & q); 34 LL v = (y & ~(p | q)) | (~(x | y) & p) | (x & q); 35 x = u, y = v; 36 } 37 } 38 } 39 40 int main() 41 { 42 scanf("%d", &n); 43 for (int i = 1; i <= n; i++) 44 { 45 LL x; 46 int y; 47 scanf("%lld %d", &x, &y); 48 x ^= ans; 49 ins(x, 0, y); 50 ans = 0; 51 for (int i = 0; i < 60; i++) ans += b1[i]; 52 printf("%lld\n", ans); 53 } 54 }
总结:
代码能力还要加强,暴力不要写炸,以及想题时多换几种角度想,第一题就一直在想第一层枚举n而导致没想到正解。第三题的类似于NIM游戏的题还要多练习,许多扩展还不会以及想不到。
浙公网安备 33010602011771号