Codeforces Round#278 Div.2
来源:互联网 发布:mac qq黑名单在哪里找 编辑:程序博客网 时间:2024/06/05 23:50
场内只做出来一个B题。。居然涨了127分。。。
A,暴力枚举。。。
n = input()c = 1while '8' not in str(n + c): c += 1print c
B,分情况讨论,如果n=0,随意发挥就好。。。。如果n=1.,假设给你一个x,那么就是x,x,3x,3x。如果n=2,那么看那个大的数是不是小于等于那个小的数的三倍,如果是,输出x, y,4x-y,3x。如果n=3,你也不知道缺哪个数,索性就都尝试一遍然后验证。。。如果n=4,验证就好。。。
#include <cstdio>#include <vector>#include <climits>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;int n;int a[5];bool judge() { int t[5]; for (int i = 0; i < 4; i++) t[i] = a[i]; sort(t, t + 4); double s1 = 0, s2 = 0, s3 = t[3] - t[0]; for (int i = 0; i < 4; i++) s1 += t[i]; s2 = t[1] + t[2]; s1 /= 4.0; s2 /= 2.0; return s1 == s2 && s2 == s3;}int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); if (n == 0) { puts("YES"); printf("1\n1\n3\n3\n"); } else if (n == 1) { puts("YES"); printf("%d\n%d\n%d\n", a[0], a[0] * 3, a[0] * 3); } else if (n == 2) { if (a[1] <= 3 * a[0]) { puts("YES"); a[3] = a[0] * 3; a[2] = a[0] + a[3] - a[1]; printf("%d\n%d\n", a[2], a[3]); } else puts("NO"); } else if (n == 3) { a[3] = a[0] + a[1] - a[2]; if (judge()) { puts("YES"); printf("%d\n", a[3]); return 0; } a[3] = a[0] + a[2] - a[1]; if (judge()) { puts("YES"); printf("%d\n", a[3]); return 0; } a[3] = a[1] + a[2] - a[0]; if (judge()) { puts("YES"); printf("%d\n", a[3]); return 0; } puts("NO"); } else { if (judge()) puts("YES"); else puts("NO"); }}
D。。。。应该是一个RMQ+DP,dp[i]表示前i位最少能分成几块。。。。不过需要一些辅助的量,首先是之前的状态,肯定不能枚举。。所以用RMQ来处理。。。。然后是区间的极差,那么必然是需要区间最大和最小的。。。。
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = (int)1e5 + 10;int mx[maxn][32], mn[maxn][32], preLog[maxn], dp[maxn], p[maxn], a[maxn];int n, s, l;void rmq_init() { preLog[1] = 0; for (int i = 2; i <= n; i++) { preLog[i] = preLog[i - 1]; if ((1 << preLog[i] + 1) == i) { preLog[i] += 1; } } for (int i = n; i > 0; i--) { mx[i][0] = mn[i][0] = a[i]; for (int j = 1; (i + (1 << j) - 1) <= n; j++){ mn[i][j] = min(mn[i][j - 1], mn[i + (1 << j - 1)][j - 1]); mx[i][j] = max(mx[i][j - 1], mx[i + (1 << j - 1)][j - 1]); } }}int query(int l, int r) { int k = preLog[r - l + 1]; return max(mx[l][k], mx[r - (1 << k) + 1][k]) - min(mn[l][k], mn[r - (1 << k) + 1][k]);}int main() { scanf("%d%d%d", &n, &s, &l); for (int i = 1; i <= n; i++) scanf("%d", a + i); rmq_init(); memset(dp, 0x3f, sizeof dp); dp[0] = 0; for (int i = 1; i < l; i++) dp[i] = -1; int st = 0; for (int i = 1; i <= n; i++) { bool flag = 0; for (int j = st; j <= i - l; j++, st++) { if (dp[j] != -1 && query(j + 1, i) <= s) { dp[i] = dp[j] + 1; flag = 1; break; } } if (!flag) dp[i] = -1; } printf("%d\n", dp[n]); return 0;}
0 0
- Codeforces Round#278 Div.2
- Codeforces Round #278 (Div. 2)
- Codeforces Round #278 (Div. 2) A B
- Codeforces Round #278 (Div. 2) A, B
- Codeforces Round #278 (Div. 2) B
- Codeforces Round #278 (Div. 2) C
- Codeforces Round #278 (Div. 2) D
- Codeforces Round #278 (Div. 2) D. Strip
- Codeforces Round #278 (Div. 2) D
- Codeforces Round #278 (Div. 1)
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #107 (Div. 2)
- Codeforces Round #108 (Div. 2)
- 巧用位运算实现两个整数的互换
- Nginx “413 Request Entity Too Large”错误解决方法
- Java核心API必须掌握的程度
- 用C#开发的双色球走势图(原创)值得园友拥有
- ABAP 获取 状态的两个函数 STATUS_TEXT_EDIT 和 STATUS_READ 的简单介绍
- Codeforces Round#278 Div.2
- 《JavaScript高级程序设计》学习笔记(第五章)- 上
- HDOJ 1012
- ASP 检测字符串是否包括汉字、数字、韩文、日文,以及其他语种字符的方法
- python之关键字is和操作符==
- XML文件解析工具类pull解析
- iOS 的 APP 在系统中如何适应 iPhone 5s/6/6 Plus 三种屏幕的尺寸?
- day3
- 利用三目运算符求出最大值最小值