CodeForces Round402 补题
来源:互联网 发布:eia数据对黄金的影响 编辑:程序博客网 时间:2024/05/18 00:34
Problem A :
#include <cstdio>#include <cstring>#include <cmath>#include <iostream>using namespace std;int main(){ int n,a[6],b[6]; scanf("%d",&n); memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for(int i=0;i<n;i++){ int t; scanf("%d",&t); a[t]++; } for(int i=0;i<n;i++){ int t; scanf("%d",&t); b[t]++; } int res=0,f=0,c=0; for(int i=1;i<=5;i++){ int t=a[i]-b[i]; if(t%2!=0){ f=1; break; }else{ res += t/2; c += abs(t/2); } } if(f || res!=0) printf("-1"); else printf("%d",c/2); printf("\n"); return 0;}
Problem B :
#include <cstdio>#include <cstring>#include <cmath>#include <iostream>using namespace std;#define maxn 2000000005int main(){ string str; int k; cin>>str>>k; int len = str.length(); if(str=="0"){ printf("0\n"); return 0; } int Z=0,N=0; for(int i=len-1;i>=0;i--){ if(Z==k){ break; } if(str[i]=='0') Z++; else N++; } if(Z==k) cout<<N<<endl; else printf("%d\n",len-1); return 0;}
Problem C :
#include <cstdio>#include <iostream>#include <algorithm>using namespace std;const int maxn = 200005;struct Node{ int c,index;};bool check(Node a,Node b){ return a.c>b.c;}int main(){ int n,k,a[maxn],b[maxn]; Node c[maxn]; scanf("%d%d",&n,&k); for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=0;i<n;i++) scanf("%d",&b[i]); for(int i=0;i<n;i++){ c[i].c = b[i]-a[i]; c[i].index = i; } sort(c, c+n, check); int res=0; for(int i=0;i<k;i++) res += a[c[i].index]; for(int i=k;i<n;i++) if(c[i].c>0){ res += a[c[i].index]; }else{ res += b[c[i].index]; } cout<<res<<endl; return 0;}
Problem D:
#include <cstdio>#include <iostream>#include <algorithm>using namespace std;#define F(i,a,b) for(int i=a;i<=b;i++)#define D(i,a,b) for(int i=a;i<b;i++)const int maxn = 200005;string a,b;int len,lenl, num[maxn],vis[maxn];int check(int mid){ F(i,1,len) vis[i]=0; F(i,mid+1,len) vis[num[i]]=1; int cnt = 0; D(i,0,len){ if(!vis[i+1]) continue; if(a[i]==b[cnt]) cnt++; if(cnt>=lenl) return 1; } return 0;}int main(){ while (cin>>a>>b) { len = (int) a.length(); lenl = (int) b.length(); F(i,1,len) scanf("%d",&num[i]); int l=0,r=len-1,mid,ans; while (l<=r) { mid = (l+r)>>1; check(mid)?l=mid+1,ans=mid : r=mid-1; } cout<<ans<<endl; }}
0 0
- CodeForces Round402 补题
- CodeForces Round #403 补题
- CodeForces Round #401 补题
- CodeForces 453A-周赛4补题
- Codeforces Round #337 (Div. 2)-------补题
- Codeforces Round #340 (Div. 2)--补题
- Codeforces Round #341 (Div. 2) ---补题
- codeforces #397 problemE 解题报告 补题
- codeforces #397 problemF 解题报告 补题
- Codeforces 补题 Educational Round 19
- codeforces round 416 div2补题
- codeforces 551b[补]
- codeforces 551c[补]
- codeforces 552c[补]
- codeforces 551d[补]
- codeforces 554c[补]
- codeforces 673c[补]
- codeforces 554d[补]
- Java内存模型总结
- Android常见View之PopupWindow精解
- HTML基本标签
- jvm内存与gc
- ubuntu launch standal one sdk manager 无反应
- CodeForces Round402 补题
- Posix标准
- 什么时候使用接口?什么时候使用抽象?选择Java接口还是抽象类 (转)
- Ubuntu16.04安装jdk1.8
- Java学习计划
- 浅谈那些针对华为裁员的观点纷争
- Autodesk Forge 学习简谈
- FootballNum今日赛事(2017/3/5)预测2
- Ubuntu16.04 常用命令