Educational Codeforces Round 21 -DEG
来源:互联网 发布:全站仪数据.dat下载 编辑:程序博客网 时间:2024/05/15 03:37
D题大意就是把物品分成两堆然后能否从大的一堆里面拿出一个给小的一堆似的两堆数相等
题解思路:用set容维护两个堆哪一堆大就从里面找是否有一个数等于大的一堆的值 减去总值的一半
当然如果总值为奇数肯定分不了的
题目链接
#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<set>#include<vector>#include<cctype>#include<map>#include<queue>#include<stack>using namespace std;typedef long long int ll;#define mes(s) memset(s)#define FOR(i,a,n) for(i = a; i < n; i++)#define ls 2*1#define rs 2*i|1#define mid (L+R)>>1#define lson ls,L,mid#define rson rs,mid+1,Rtypedef long long int ll;const int inf = 0x3f3f3f3f;const int mx = 1e5+10;set<ll>st;ll a[mx];int n;int main(){ while(scanf("%d",&n)!=EOF){ st.clear(); ll sum = 0; for(int i = 1; i <= n; i++){ cin>>a[i]; sum += a[i]; } if(sum&1){ puts("NO"); continue; } int flag = 0; sum /= 2; ll ans = 0; for(int i = 1; i <= n; i++){ ans += a[i]; ll v = ans-sum; st.insert(a[i]); if(v > 0 &&st.find(v) != st.end()){ flag = 1; break; } } st.clear(); ans = 0; for(int i = n; i >= 1; i--){ ans += a[i]; ll v = ans - sum; st.insert(a[i]); if(v > 0 && st.find(v) != st.end()){ flag = 1; break; } } flag?puts("YES"):puts("NO"); } return 0;}
E题大意就是有一个背包承受重量为m然后又n个物品有其对应的价值和重量从中如何取使得值最大
题解思路:求重量为m只取重量为1 和重量为2 的物品的时候如何取价值最大然后枚举取最大重量为m-3*i 去i个为3的质量的物品时候最大值
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>#include<vector>#include<cstdio>using namespace std;#define dec(i,a,n) for(i = a; i <= n; i++)#define rec(i,a,n) for(i = n; i >= a; i--)const int mx = 3*1e5+5;typedef long long int ll;pair<ll,pair<ll,ll>>dp[mx];vector<ll>v[4];bool cmp(ll a,ll b){ return a>b;}int main(){ int n,m; int i,j,k; ll c,w; scanf("%d%d",&n,&m); dec(i,1,n){ cin>>c>>w; v[c].push_back(w); } dec(i,1,3) sort(v[i].begin(),v[i].end(),cmp); int len[4]; dec(i,1,3){ len[i] = v[i].size(); v[i].insert(v[i].begin(),0); dec(j,1,len[i]) v[i][j] += v[i][j-1]; } dec(i,1,m){ dp[i].first = 0; dp[i].second.first = 0; dp[i].second.second = 0; } dp[0] = {0,{0,0}}; if(len[1]) dp[1] = {v[1][1],{1,0}}; dec(i,2,m){ dp[i] = dp[i-1]; j = dp[i-2].second.first; k = dp[i-2].second.second+1; if(k <= len[2] && v[1][j] + v[2][k] > dp[i].first){ dp[i].first = v[1][j] + v[2][k]; dp[i].second.first = j; dp[i].second.second = k; } j = dp[i-1].second.first+1; k = dp[i-1].second.second; if(j <= len[1] && v[2][k] + v[1][j] > dp[i].first){ dp[i].first = v[2][k] + v[1][j]; dp[i].second.first = j; dp[i].second.second = k; } } ll ans = 0; dec(i,0,len[3]){ int ret = m-3*i; if(ret >= 0) ans = max(ans,dp[ret].first+v[3][i]); } cout<<ans<<endl; return 0;}
G题大意就是先给一串字符串中间有问号然后如何变问号使得这串字符串子串含有最多的另一个字符串
题解思路:
当这几个问号能改时候要寻找是否改或者不改例如
a????? abc 这样第四的时候可以选择不改使得子串最大
所以有两个状态这个字符串能改的时候选择不改或者选择改
同时求得另外一个字符串最大的相等程度然后用动态规划当这个取或者不取的时候最大子串数
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int mx = 1e5+5;char s1[mx],s2[mx];int f[mx];int p[mx];int dp[2][mx];int n,m;int main(){ int i,j,k; scanf("%s%s",s1+1,s2+1); n = strlen(s1+1); m = strlen(s2+1); if(m > n){ cout<<0<<endl; return 0; } memset(dp,0,sizeof(dp)); memset(p,0,sizeof(p)); memset(f,0,sizeof(f)); for(int i=1;i<m;i++){ int ok = 1; //求最大s2子串从(1-i) (m-i+1~m)是否两串相等 for(int j=1;j<=i;j++){ if(s2[j]!=s2[m-i+j]){ ok = 0; break; } } f[i]=ok; } for(int i=1;i<=n-m+1;i++){ int ok = 1; for(int j=i;j<=i+m-1;j++){ if(s1[j]=='?')continue; if(s1[j]!=s2[j-i+1]){ ok = 0; break; } } p[i+m-1] = ok; } for(int i = 1; i <= n; i++){ dp[0][i] = dp[0][i-1]; if(p[i]){ dp[1][i] = dp[0][i-m]+1; for(int j = 1; j < m; j++) //求可以改的时候最大子串数 if(f[j])dp[1][i] = max(dp[1][i],dp[1][i-m+j]+1); } dp[0][i] = max(dp[0][i],dp[1][i]);//求这个位置取或者不取两着的最大值因为等下取只会用取得位置前面m的位置两者不会相交 } cout<<dp[0][n]<<endl; return 0; }
阅读全文
0 0
- Educational Codeforces Round 21 -DEG
- Educational Codeforces Round 21
- Educational Codeforces Round 21
- Educational Codeforces Round 21
- Educational Codeforces Round 21 A
- Educational Codeforces Round 21 C
- Educational Codeforces Round 21-D
- Educational Codeforces Round 21-G
- Educational Codeforces Round 21E
- Educational Codeforces Round 21总结
- Educational Codeforces Round 21 题解
- codeforces Educational Codeforces Round 21 A
- Educational Codeforces Round 21 A. Lucky Year
- Educational Codeforces Round 21 C. Tea Party
- Educational Codeforces Round 21 A. Lucky Year
- code forces Educational Codeforces Round 21
- Educational Codeforces Round 21 D ( 二分 )
- Educational Codeforces Round 21 C. Tea Party
- 列出真分数序列
- LDA and QDA 分类:机器学习 Sklearn
- Struts2_提供的校验器列表
- POJ2992
- 【Effective C++】读书笔记 条款52:写了placement new 也要写placement delete
- Educational Codeforces Round 21 -DEG
- cookie 的简单使用
- Vuejs中nextTick()异步更新队列源码解析
- vs2013找不着mfc120d.lib咋办
- 面试问题(二)
- 01背包1004
- C# LINQ使用
- 如何输出程序段所运行时间
- 数据结构与算法(24)——堆习题