BestCoder Round #86
来源:互联网 发布:惠普暗影精灵3新机优化 编辑:程序博客网 时间:2024/06/06 08:46
1001 Price List
#include <cstdio>#include <vector>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 100005;typedef long long LL;vector <int> vec;int main(){ int T; scanf("%d", &T); while(T--){ int n,m; scanf("%d%d", &n, &m); LL sum = 0,x; for(int i = 0; i < n; i++){ scanf("%I64d", &x); sum += x; } vec.clear(); while(m--){ scanf("%I64d", &x); if(x > sum) vec.push_back(1); else vec.push_back(0); } for(int i = 0; i < vec.size(); i++) printf("%d", vec[i]); printf("\n"); } return 0;}
1002 NanoApe Loves Sequence
这道题我们首先将最大值所在的地方求出来,即找到那个区间左端点位置和右端点位置,当没有删除最大值所在位置是那么直接将最大值和删除元素产生的新区间的差值进行比较,即可以得到正确结果,当删除元素正好在最大值所在位置是,我们重新求一遍就可以了,因为这种情况只存在2次,当然我们最左边和最右边的地方要特殊判断。
#include <cstdio>#include <cmath>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 100005;typedef long long LL;int a[maxn];int main(){ int T,n; scanf("%d", &T); while(T--){ scanf("%d", &n); memset(a, 0, sizeof(a)); for(int i = 1; i <= n; i++){ scanf("%d", &a[i]); } int M = 0,l,r; for(int i = 1; i < n; i++){ if(abs(a[i] - a[i+1])> M){ M = abs(a[i] - a[i+1]); l = i; r = i+1; } } LL sum = 0; for(int i = 1; i <= n; i++){ if(i != l && i != r){ if(i != 1 && i != n) sum += max(M, abs(a[i+1] - a[i-1])); else sum += (LL)M; } else{ int temp = 0; for(int j = 1; j <= n; j++){ if(j == i) continue; else if(j == i-1){ if(i+1 <= n) temp = max(temp, abs(a[i+1] - a[i-1])); } else{ if(j+1 <= n) temp = max(temp, abs(a[j+1] - a[j])); } } sum += (LL)temp; } } printf("%I64d\n", sum); } return 0;}
1003 NanoApe Loves Sequence Ⅱ
这道题刚开始觉得很难,但是想着想着就简单了,感觉像初中数学题一样,枚举左端点,找到右端点,然后在O(n)时间内求出。
#include <cstdio>#include <vector>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;const int maxn = 200005;int a[maxn];vector <int> vec;int main(){ int T,n,m,k; scanf("%d", &T); while(T--){ vec.clear(); scanf("%d%d%d", &n, &m, &k); for(int i = 1; i <= n; i++){ scanf("%d", &a[i]); if(a[i] >= m) vec.push_back(i); } if(vec.size() < k) {printf("0\n"); continue;} LL sum = 0; for(int i = 0; i < vec.size(); i++){ if((i+k-1) < vec.size()){ if(i == 0){ sum += (LL)vec[i]*((LL)n-vec[i+k-1]+1); } else{ sum += (LL)(vec[i] - vec[i-1])*((LL)n-vec[i+k-1]+1); } } } printf("%I64d\n", sum); } return 0;}
1004 Keep In Touch
这题不会,把大神代码打了一遍还是没有头绪,所以放弃了,先存在着,以后水平够了再看吧!!
#include <map>#include <set>#include <queue>#include <cmath>#include <vector>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;typedef unsigned long long ull;typedef pair<int, int> PII;#define fi first#define se second#define MP make_pairint read(){ //输入挂 int v = 0, f = 1; char c = getchar(); while(c < 48 || 57 < c) {if(c == '-') f = -1; c = getchar();} while(48 <= c && c <= 57) v = v*10 + c - 48, c = getchar(); return v*f;}const int maxn = 55;const int MOD = 998244353;int dp[maxn][maxn][maxn][4],head[maxn],a[maxn],tot;int n,m,K,q;struct Edge{ int to,next;}e[maxn*100];void addedge(int from,int to){ e[tot].to = to; e[tot].next = head[from]; head[from] = tot++;}void solve(){ n = read(), m = read(), K = read(), q = read(); for(int i = 1; i <= n; i++) a[i] = read(); memset(head, -1, sizeof(head)); tot = 0; for(int i = 1; i <= m; i++){ //建立反向边 int from = read(),to = read(); addedge(to, from); } 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++) if(abs(a[i]-a[j]) <= K && abs(a[j]-a[k]) <= K && abs(a[i]-a[k]) <= K) dp[i][j][k][0] = 1; for(int i = n; i >= 1; i--) for(int j = n; j >= 1; j--) for(int k = n; k >= 1; k--){ for(int u = head[i]; ~u; u = e[u].next){ //i走 int v = e[u].to; (dp[v][j][k][1] += dp[i][j][k][0]) %= MOD; } for(int u = head[j]; ~u; u = e[u].next){ //j走 int v = e[u].to; (dp[i][v][k][2] += dp[i][j][k][1]) %= MOD; } for(int u = head[k]; ~u; u = e[u].next){ //k走 int v = e[u].to; if(abs(a[i] - a[j]) <= K && abs(a[j] - a[v]) <= K && abs(a[v] - a[i]) <= K) (dp[i][j][v][0] += dp[i][j][k][2]) %= MOD; } } while(q--){ int a = read(), b = read(), c = read(); printf("%d\n", dp[a][b][c][0]); }}int main(){ int T = read(); while(T--) solve(); 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
- 欢迎使用CSDN-markdown编辑器
- Flask模板
- java连接hive(未完待续)
- 初学c/c++——位操作符
- request.getParameter() 和request.getAttribute() 区别
- BestCoder Round #86
- ueditor使用_3_图片视频等上传
- hdu 2955 Robberies
- 树结构练习——排序二叉树的中序遍历
- Java注解(Annotation)-注解处理器小结
- CocoaPods 安装使用
- [译] 使用流动控制器(Flow Controller )实现 MVVM 协议模型
- 偶数幻方
- vue表单元素操作