AtCoder Beginner Contest 210
2021/7/21 6:10:06
本文主要是介绍AtCoder Beginner Contest 210,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
A-Cabbages
# include "iostream" # include "cstdio" using namespace std; int N,A,X,Y; int main(){ scanf("%d%d%d%d",&N,&A,&X,&Y); printf("%d",N>=A?A*X+(N-A)*Y:N*X); return 0; }
B-Bouzu Mekuri
# include "iostream" # include "cstdio" using namespace std; const int maxm=1e5+10; int N; char S[maxm]; int main(){ register int i; scanf("%d",&N); scanf("%s",S+1); for(i=1;i<=N;i++){ if(S[i]=='1'){ printf("%s",i&1?"Takahashi":"Aoki"); break; } } return 0; }
C-Colorful Candies
# include "iostream" # include "algorithm" # include "cstdio" using namespace std; const int maxm=3e5+10; int N,K; int C[maxm],A[maxm],B[maxm]; int Visit[maxm]; inline int Find(int X){ register int Left=1,Right=N,Mid; while(Left<Right){ Mid=(Left+Right)>>1; if(A[Mid]>=X) Right=Mid; else Left=Mid+1; } return Left; } int main(){ register int i,Ans=0,Now=0; scanf("%d%d",&N,&K); for(i=1;i<=N;i++){ scanf("%d",&C[i]); A[i]=C[i]; } sort(A+1,A+1+N); for(i=1;i<=N;i++){ B[i]=Find(C[i]); } for(i=1;i<=N;i++){ Visit[B[i]]++; if(Visit[B[i]]==1) Now++; if(i-K>0){ Visit[B[i-K]]--; if(Visit[B[i-K]]==0) Now--; } Ans=max(Ans,Now); } printf("%d",Ans); return 0; }
D-National Railway
# include "iostream" # include "cstdio" using namespace std; const int maxm=1e3+10; int H,W; long long C; long long A[maxm][maxm]; long long DP[maxm][maxm]; int main(){ register int i,j; register long long Ans=1ll<<60; scanf("%d%d%lld",&H,&W,&C); for(i=1;i<=H;i++){ for(j=1;j<=W;j++){ scanf("%lld",&A[i][j]); DP[i][j]=1ll<<60; } } for(i=1;i<=H;i++){ for(j=1;j<=W;j++){ if(i!=1){ DP[i][j]=min(DP[i][j],A[i][j]+A[i-1][j]+C); DP[i][j]=min(DP[i][j],DP[i-1][j]-A[i-1][j]+A[i][j]+C); } if(j!=1){ DP[i][j]=min(DP[i][j],A[i][j-1]+A[i][j]+C); DP[i][j]=min(DP[i][j],DP[i][j-1]-A[i][j-1]+A[i][j]+C); } Ans=min(Ans,DP[i][j]); } } for(i=1;i<=(H>>1);i++){ for(j=1;j<=W;j++){ swap(A[i][j],A[H-i+1][j]); } } for(i=1;i<=H;i++){ for(j=1;j<=W;j++){ DP[i][j]=1ll<<60; } } for(i=1;i<=H;i++){ for(j=1;j<=W;j++){ if(i!=1){ DP[i][j]=min(DP[i][j],A[i][j]+A[i-1][j]+C); DP[i][j]=min(DP[i][j],DP[i-1][j]-A[i-1][j]+A[i][j]+C); } if(j!=1){ DP[i][j]=min(DP[i][j],A[i][j-1]+A[i][j]+C); DP[i][j]=min(DP[i][j],DP[i][j-1]-A[i][j-1]+A[i][j]+C); } Ans=min(Ans,DP[i][j]); } } printf("%lld",Ans); return 0; }
E-Ring MST
# include "algorithm" # include "iostream" # include "cstdio" using namespace std; const int maxm=1e5+10; int N,M; long long DP[maxm],Ans; struct node{ int A; long long C; # define A(x) Node[x].A # define C(x) Node[x].C }Node[maxm]; inline bool Comp(node x,node y){ return x.C<y.C; } inline long long GCD(long long X,long long Y){ return Y?GCD(Y,X%Y):X; } int main(){ register int i; scanf("%d%d",&N,&M); for(i=1;i<=M;i++) scanf("%d%lld",&A(i),&C(i)); sort(Node+1,Node+M+1,Comp); DP[0]=N; for(i=1;i<=M;i++){ DP[i]=GCD(DP[i-1],A(i)); Ans=(Ans+(DP[i-1]-DP[i])*C(i)); } printf("%lld",DP[M]==1?Ans:-1); return 0; }
这篇关于AtCoder Beginner Contest 210的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-22怎么通过控制台去看我的页面渲染的内容在哪个文件中呢-icode9专业技术文章分享
- 2024-12-22el-tabs 组件只被引用了一次,但有时会渲染两次是什么原因?-icode9专业技术文章分享
- 2024-12-22wordpress有哪些好的安全插件?-icode9专业技术文章分享
- 2024-12-22wordpress如何查看系统有哪些cron任务?-icode9专业技术文章分享
- 2024-12-21Svg Sprite Icon教程:轻松入门与应用指南
- 2024-12-20Excel数据导出实战:新手必学的简单教程
- 2024-12-20RBAC的权限实战:新手入门教程
- 2024-12-20Svg Sprite Icon实战:从入门到上手的全面指南
- 2024-12-20LCD1602显示模块详解
- 2024-12-20利用Gemini构建处理各种PDF文档的Document AI管道