BestCoder Round #86
来源:互联网 发布:java方法重载和重写 编辑:程序博客网 时间:2024/06/05 03:29
A
签到
B
直接上了线段树,其实用前缀和后缀维护是最优的。
#include <iostream>#include <cstdlib>#include <cstdio>#include <algorithm>#include <string>#include <map>#include <cstring>#include <stack>#include <queue>#include <cmath>#include <vector>#include <set>#define ll o<<1#define rr o<<1|1using namespace std;typedef __int64 LL;typedef pair<int, int> pii;const int MAXN = 1e5 + 10;const int MOD = 1e9 + 7;void add(LL &x, LL y) { x += y; if(x < 0) x += MOD; x %= MOD; }int a[MAXN];struct Tree{ int l, r, Max;};Tree tree[MAXN<<2];void PushUp(int o) { tree[o].Max = max(tree[ll].Max, tree[rr].Max);}void Build(int o, int l, int r){ tree[o].l = l; tree[o].r = r; tree[o].Max = 0; if(l == r) return ; int mid = (l + r) >> 1; Build(ll, l, mid); Build(rr, mid + 1, r);}void Update(int o, int pos, int v) { if(tree[o].l == tree[o].r) { tree[o].Max = v; return ; } int mid = (tree[o].l + tree[o].r) >> 1; if(pos <= mid) Update(ll, pos, v); else Update(rr, pos, v); PushUp(o);}int Query(int o, int L, int R) { if(L > R) return 0; if(tree[o].l == L && tree[o].r == R) return tree[o].Max; int mid = (tree[o].l + tree[o].r) >> 1; if(R <= mid) return Query(ll, L, R); else if(L > mid) return Query(rr, L, R); else return max(Query(ll, L, mid), Query(rr, mid+1, R));}int main(){ int t; scanf("%d", &t); while(t--) { int n; scanf("%d", &n); LL sum = 0; Build(1, 1, n); for(int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for(int i = 1; i <= n; i++) { if(i < n) { Update(1, i, abs(a[i+1] - a[i])); } } LL ans = 0; for(int i = 1; i <= n; i++) { if(i == 1) { ans += 1LL * Query(1, i + 1, n - 1); } else if(i == n) { ans += 1LL * Query(1, 1, n - 2); } else { ans += 1LL * max(max(Query(1, 1, i - 2), Query(1, i + 1, n - 1)), abs(a[i+1] - a[i-1])); } } printf("%I64d\n", ans); } return 0;}
C
转化问题,有多少个连续区间大于或者等于m的数不少于k个。
#include <iostream>#include <cstdlib>#include <cstdio>#include <algorithm>#include <string>#include <map>#include <cstring>#include <stack>#include <queue>#include <cmath>#include <vector>#include <set>#define ll o<<1#define rr o<<1|1using namespace std;typedef __int64 LL;typedef pair<int, int> pii;const int MAXN = 2e5 + 10;const int MOD = 1e9 + 7;void add(LL &x, LL y) { x += y; if(x < 0) x += MOD; x %= MOD; }int A[MAXN];int sum[MAXN];int main(){ int t; scanf("%d", &t); while(t--) { int n, m, k; scanf("%d%d%d", &n, &m, &k); sum[0] = 0; for(int i = 1; i <= n; i++) { scanf("%d", &A[i]); sum[i] = sum[i-1] + (A[i] >= m); } LL res = 0; for(int i = 1; i <= n; i++) { int l = i, r = n, ans = -1; while(r >= l) { int mid = l + r >> 1; if(sum[mid] - sum[i-1] >= k) { ans = mid; r = mid - 1; } else { l = mid + 1; } } if(ans != -1) { res += n - ans + 1; } } printf("%I64d\n", res); } return 0;}
D
#include <iostream>#include <cstdlib>#include <cstdio>#include <algorithm>#include <string>#include <map>#include <cstring>#include <stack>#include <queue>#include <cmath>#include <vector>#include <set>#define ll o<<1#define rr o<<1|1using namespace std;typedef __int64 LL;typedef pair<int, int> pii;const int MAXN = 2e5 + 10;const int MOD = 998244353;void add(LL &x, LL y) { x += y; if(x < 0) x += MOD; x %= MOD; }LL dp[51][51][51][3];int n, m, K, q;int a[51];struct Edge { int to, next;};Edge edge[50 * 50];int head[51], edgenum;void init() { memset(head, -1, sizeof(head)); edgenum = 0; }void addEdge(int u, int v){ edge[edgenum].to = v; edge[edgenum].next = head[u]; head[u] = edgenum++;}bool judge(int i, int j, int k) { return abs(a[i] - a[j]) <= K && abs(a[i] - a[k]) <= K && abs(a[j] - a[k]) <= K;}int main(){ int t; scanf("%d", &t); while(t--) { scanf("%d%d%d%d", &n, &m, &K, &q); for(int i = 1; i <= n; i++) scanf("%d", &a[i]); memset(dp, 0, sizeof(dp)); for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { for(int k = 1; k <= n; k++) { dp[i][j][k][0] = 1LL * judge(i, j, k); } } } init(); for(int i = 1; i <= m; i++) { int u, v; scanf("%d%d", &u, &v); addEdge(v, u); } for(int i = n; i >= 1; i--) { for(int j = n; j >= 1; j--) { for(int k = n; k >= 1; k--) { //if(!judge(i, j, k)) continue; for(int p = head[i]; p != -1; p = edge[p].next) { int v = edge[p].to; //if(judge(v, j, k)) { add(dp[v][j][k][1], dp[i][j][k][0]); //} } for(int p = head[j]; p != -1; p = edge[p].next) { int v = edge[p].to; //if(judge(i, v, k)) { add(dp[i][v][k][2], dp[i][j][k][1]); //} } for(int p = head[k]; p != -1; p = edge[p].next) { int v = edge[p].to; if(judge(i, j, v)) { add(dp[i][j][v][0], dp[i][j][k][2]); } } } } } while(q--) { int x, y, z; scanf("%d%d%d", &x, &y, &z); printf("%I64d\n", dp[x][y][z][0]); } } return 0;}
0 0
- BestCoder Round #86
- BestCoder Round #86
- BestCoder Round #86
- BestCoder Round #86 1002
- BestCoder Round #86
- BestCoder Round #86
- BestCoder Round #86题解报告
- BestCoder Round #86题解报告
- hdu5804(BestCoder Round #86 A)
- bestcoder round#86解题报告
- BestCoder Round #86 1003(尺取法)
- HDU5804&BestCoder Round #86 1001 Price List
- hdoj5850 NanoApe Loves Sequence BestCoder Round #86
- HDU5804 BestCoder Round 86A 【Price List】
- 【计数】HDU5804Price List【BestCoder Round #86】
- BestCoder Round #3 BestCoder Sequence
- bestcoder round #1
- BestCoder round #1
- HDU 5826 physics(积分 找规律)——2016 Multi-University Training Contest 8
- 任意进制转换
- hdu 3999 The order of a Tree
- c++类的实例化
- 《STL系列》之map原理及实现
- BestCoder Round #86
- 解决android加载bitmap内存溢出的方法
- leetcode难度及面试频率
- Myeclipse加入反编译插件
- 建模交流学习
- spoj cot2 树上莫队
- hdu Rikka with Parenthesis II 模拟
- poj 2482 Stars in Your Window (离散化+扫描线)
- 一起去打CS