Educational Codeforces Round 15
来源:互联网 发布:怎么查域名是否备案 编辑:程序博客网 时间:2024/06/08 15:53
A
题意:最长的连续LIS。
dp 跑一发即可
#include <cstdio>#include <algorithm>#include <cmath>#include <vector>#include <cstring>#include <queue>#include <map>#include <set>#include <string>#define CLR(a, b) memset(a, (b), sizeof(a))#define ll o<<1#define rr o<<1|1using namespace std;typedef long long LL;typedef pair<int, int> pii;const int MAXN = 1e5 + 10;const int MAXM = 1e5 + 1;const int INF = 1e9 + 10;const int MOD = 1e9 + 7;void add(LL &x, LL y) {x += y; x %= MOD;}int dp[MAXN], a[MAXN];int main(){ int n; while(scanf("%d", &n) != EOF) { int ans = 0; dp[0] = 0; for(int i = 1; i <= n; i++) { scanf("%d", &a[i]); if(i == 1 || a[i] > a[i-1]) { dp[i] = dp[i-1] + 1; } else { dp[i] = 1; } ans = max(ans, dp[i]); } printf("%d\n", ans); } return 0;}
B
题意:问你有多少对a[i],a[j]使得二者和是2的幂。
#include <cstdio>#include <algorithm>#include <cmath>#include <vector>#include <cstring>#include <queue>#include <map>#include <set>#include <string>#define CLR(a, b) memset(a, (b), sizeof(a))#define ll o<<1#define rr o<<1|1using namespace std;typedef long long LL;typedef pair<int, int> pii;const int MAXN = 1e5 + 10;const int MAXM = 1e5 + 1;const int INF = 1e9 + 10;const int MOD = 1e9 + 7;void add(LL &x, LL y) {x += y; x %= MOD;}map<LL, int> num;LL f[35];LL a[MAXN];int main(){ f[0] = 1LL; for(int i = 1; i <= 31; i++) { f[i] = f[i-1] * 2; } int n; while(scanf("%d", &n) != EOF) { num.clear(); for(int i = 1; i <= n; i++) { scanf("%lld", &a[i]); num[a[i]]++; } LL ans = 0; for(int i = 1; i <= n; i++) { for(int j = 1; j <= 31; j++) { if(a[i] + a[i] == f[j]) { ans += num[a[i]] - 1; } else { ans += num[f[j] - a[i]]; } } } printf("%lld\n", ans / 2); } return 0;}
C
题意:n个城市,m个塔在一条直线上。问塔最小的覆盖半径使得所有城市都被覆盖。
二分即可,比较坑的是,二分会爆int。。。
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <vector>#include <cstring>#include <queue>#include <map>#include <set>#include <string>#define CLR(a, b) memset(a, (b), sizeof(a))#define ll o<<1#define rr o<<1|1using namespace std;typedef long long LL;typedef pair<int, int> pii;const int MAXN = 1e5 + 10;const int MAXM = 1e5 + 1;const int INF = 1e9 + 10;const int MOD = 1e9 + 7;void add(LL &x, LL y) {x += y; x %= MOD;}int x1[MAXN], x2[MAXN];int n, m;bool judge(int o) { int i = 1, j; for(j = 1; j <= m; j++) { while(i <= n && abs(x1[i] - x2[j]) <= o) { i++; } } return i > n;}int main(){ while(scanf("%d%d", &n, &m) != EOF) { int l1 = 1e9 + 10, r1 = -1e9 - 10; for(int i = 1; i <= n; i++) { scanf("%d", &x1[i]); l1 = min(l1, x1[i]); r1 = max(r1, x1[i]); } int l2 = 1e9 + 10, r2 = -1e9 - 10; for(int i = 1; i <= m; i++) { scanf("%d", &x2[i]); l2 = min(l2, x2[i]); r2 = max(r2, x2[i]); } LL l = 0, r = max(abs(r1 - l2), abs(r2 - l1)), ans; while(r >= l) { LL mid = (l + r) >> 1; if(judge(mid)) { ans = mid; r = mid - 1; } else { l = mid + 1; } } printf("%lld\n", ans); } return 0;}
D
题意:一个人要走d千米的路,开车每千米花费a秒,步行每千米花费b秒。开车每次最多走k千米,而且走完k千米后必须花费t秒修车才可以继续开车,他可以在任意时刻丢下车步行(之后不能继续乘车)。问你最少需要多少时间到达目的地。
思路:特判d <= k。
走k千米开车最优时就开车,最后一段看是否等于k,不等于的话,取步行和开车(少一次修车时间)的最优值。走k千米步行最优时,就先开车k千米,然后开始步行。
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <vector>#include <cstring>#include <queue>#include <map>#include <set>#include <string>#define CLR(a, b) memset(a, (b), sizeof(a))#define ll o<<1#define rr o<<1|1using namespace std;typedef long long LL;typedef pair<int, int> pii;const int MAXN = 1e5 + 10;const int MAXM = 1e5 + 1;const int INF = 1e9 + 10;const int MOD = 1e9 + 7;void add(LL &x, LL y) {x += y; x %= MOD;}int main(){ LL d, k, a, b, t; while(scanf("%lld%lld%lld%lld%lld", &d, &k, &a, &b, &t) != EOF) { if(d <= k) { printf("%lld\n", d * a); continue; } LL kk = k * (a - b) + t; if(kk > 0) { LL ans = kk + d * b - t; printf("%lld\n", ans); } else { LL ans = d / k * k * a + (d / k - 1) * t; LL yu = d - d / k * k; ans += min(t + yu * a, yu * b); printf("%lld\n", ans); } } return 0;}
E
题意:给你一个有向图以及边权,可能存在自环。问每个点的s和m信息
s信息:从当前点出发的长度为k的路径上的边权和。
m信息:同上,只不过找的是路径最小边权。
题目没有说长度为k的路径一定存在,出题人的意思应该是一定存在的。
思路:类似于倍增。
然后统计所有的信息。
查询
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <vector>#include <cstring>#include <queue>#include <map>#include <set>#include <string>#define CLR(a, b) memset(a, (b), sizeof(a))#define ll o<<1#define rr o<<1|1using namespace std;typedef long long LL;typedef pair<int, int> pii;const int MAXN = 1e5 + 10;const int MAXM = 1e5 + 1;const int INF = 1e9 + 10;const int MOD = 1e9 + 7;void add(LL &x, LL y) {x += y; x %= MOD;}LL sum[MAXN][36];LL Min[MAXN][36];int g[MAXN][36];LL f[36];int main(){ f[0] = 1LL; for(int i = 1; i <= 35; i++) { f[i] = f[i-1] * 2; } int n; LL k; while(scanf("%d%lld", &n, &k) != EOF) { for(int i = 0; i < n; i++) { scanf("%d", &g[i][0]); } for(int i = 0; i < n; i++) { scanf("%lld", &Min[i][0]); sum[i][0] = Min[i][0]; } for(int j = 1; j <= 35; j++) { for(int i = 0; i < n; i++) { g[i][j] = g[g[i][j-1]][j-1]; sum[i][j] = sum[i][j-1] + sum[g[i][j-1]][j-1]; Min[i][j] = min(Min[i][j-1], Min[g[i][j-1]][j-1]); } } for(int i = 0; i < n; i++) { LL ans1 = 0, ans2 = 1e9; int s = i; for(int j = 0; j <= 35; j++) { if(k & f[j]) { ans1 += sum[s][j]; ans2 = min(ans2, Min[s][j]); s = g[s][j]; } } printf("%lld %lld\n", ans1, ans2); } } return 0;}
0 0
- Educational Codeforces Round 15
- Educational Codeforces Round 15
- Educational Codeforces Round 15
- Educational Codeforces Round 15
- Educational Codeforces Round 15
- Educational Codeforces Round 15
- Educational Codeforces Round 15 7.29
- 【解题报告】Educational Codeforces Round 15
- Educational Codeforces Round 15(简单题)
- Educational Codeforces Round 15 C. Cellular Network
- Educational Codeforces Round 15 D 数学推导
- CF Educational Codeforces Round 15(C)
- Educational Codeforces Round 1
- Educational Codeforces Round 2
- Educational Codeforces Round 2
- Educational Codeforces Round 2
- Educational Codeforces Round 3
- Codeforces Educational Round 3
- Android M(SDK 6.0)新特性
- 杭电HDOJ2023-求平均成绩
- TCP协议中的三次握手和四次挥手(图解)
- JavaScript节点操作
- DataBinding学习入门篇
- Educational Codeforces Round 15
- Fedora 24下安装Chrome浏览器
- C++ IO库
- 生活感触
- 几个常见的DP问题及解法
- Android 消息推送
- Android SQLite数据库版本升级原理解析
- 2016/8/1 报道
- Android客户端和php+mysql+apache搭建的服务器之间的简单交互