正睿20秋季提高十连测day8
估分:20+100+20=140
实际:20+0+0=20
T1:
20pts暴力
枚举进行几次行收割,求最大值即可
1 #include<cstdio> 2 #include<cstring> 3 #include<queue> 4 #include<iostream> 5 #include<algorithm> 6 using namespace std; 7 8 typedef long long LL; 9 10 const int N = 1000010; 11 12 int n, m, K, v0; 13 int a[1010][1010]; 14 LL ans1[N], ans2[N]; 15 priority_queue<LL>que; 16 17 int main() { 18 scanf("%d%d%d%d", &n, &m, &K, &v0); 19 for (int i = 1; i <= n; i++) 20 for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]); 21 22 for(int i=1;i<=n;i++) 23 { 24 LL cur = 0; 25 for (int j = 1; j <= m; j++) cur += a[i][j]; 26 que.push(cur); 27 } 28 29 for(int i=1;i<=K;i++) 30 { 31 LL x = que.top(); 32 que.pop(); 33 ans1[i] = ans1[i - 1] + x; 34 que.push(x - v0 * m); 35 } 36 37 while (!que.empty()) que.pop(); 38 for (int j = 1; j <= m; j++) 39 { 40 LL cur = 0; 41 for (int i = 1; i <= n; i++) cur += a[i][j]; 42 que.push(cur); 43 } 44 45 for(int i=1;i<=K;i++) 46 { 47 LL x = que.top(); 48 que.pop(); 49 ans2[i] = ans2[i - 1] + x; 50 que.push(x - v0 * n); 51 } 52 53 LL ans = -0x7fffffffffffffff; 54 for(int i=0;i<=K;i++) 55 { 56 ans = max(ans, ans1[i] + ans2[K - i] - 1LL * i * (K - i) * v0); 57 } 58 printf("%lld\n", ans); 59 return 0; 60 }
T2:
判断中途不能继续走的时候忘加了在之前走得的能量石,b0l
二分枚举多少个工具人,然后每个工具人最后一定停在同一个位置,找到这个位置然后算贡献能不能让主角走到终点就行了。知道这一性质后可以利用所有人肯定停在同一位置且单调不降来扫描一遍进行优化,线性做完
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 7 typedef long long LL; 8 9 const int N = 100005; 10 11 int n, mx[N]; 12 char s[N]; 13 14 int main() 15 { 16 int T; 17 scanf("%d", &T); 18 while (T--) 19 { 20 scanf("%s", s + 1); 21 n = strlen(s + 1); 22 if (s[1] == '0') 23 { 24 puts("-1"); 25 continue; 26 } 27 for (int i = 0; i <= n + 1; i++) mx[i] = 0; 28 for (int i = 1; i <= n; i++) mx[i] = mx[i - 1] + (s[i] == '1' ? 1 : -1); 29 for (int i = 1; i <= n; i++) mx[i] = max(mx[i], mx[i - 1]); 30 LL cur = 0, ans = 0; 31 for (int i = 1; i <= n; i++) 32 { 33 if (s[i] == '1') 34 { 35 ++cur; 36 cur += 1LL * (mx[i] - mx[i - 1]) * ans; 37 } 38 else 39 { 40 if (!cur) 41 { 42 ++ans; 43 cur += mx[i]; 44 } 45 --cur; 46 } 47 } 48 printf("%lld\n", ans); 49 } 50 return 0; 51 }
T3:
写的暴力是错的
总结:
没仔细检查代码,最后的时间都花在T3上了,而且不知道T2怎么写暴力,所以爆0了,以后要多留一点时间去检查代码