Codeforces Round #440
来源:互联网 发布:诺亚网络萝卜街 编辑:程序博客网 时间:2024/06/06 03:02
CF872A Search for Pretty Integers(贪心)
#include <bits/stdc++.h>#define ll long long#define mod 1000000007#define N 2010#define inf 0x3f3f3f3fusing namespace std;inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f;}int n,m,mna=100,mnb=100,cnt[11];int main(){// freopen("a.in","r",stdin); n=read();m=read(); for(int i=1;i<=n;++i){ int x=read();cnt[x]++;mna=min(mna,x); } for(int i=1;i<=m;++i){ int x=read();cnt[x]++;mnb=min(mnb,x); }for(int i=1;i<=9;++i) if(cnt[i]==2){printf("%d\n",i);return 0;} if(mna>mnb) swap(mna,mnb); printf("%d\n",mna*10+mnb); return 0;}
CF872B Maximum of Maximums of Minimums(贪心)
分成三及以上部分,则一定能保证最大值为最大值(把他单独分一组)。分一部分,则只能是最小值。分两部分,则最优的一定是首尾的最大值。
#include <bits/stdc++.h>#define ll long long#define mod 1000000007#define N 100010#define inf 0x3f3f3f3fusing namespace std;inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f;}int n,k,a[N],mx=-inf,mn=inf;int main(){// freopen("a.in","r",stdin); n=read();k=read(); for(int i=1;i<=n;++i) a[i]=read(),mx=max(a[i],mx),mn=min(mn,a[i]); if(k>=3) printf("%d\n",mx); else if(k==1) printf("%d\n",mn); else printf("%d\n",max(a[1],a[n])); return 0;}
CF871A Maximum splitting(贪心+数学)
把一个数分成尽量多的合数的和。那当然是都分成最小的合数4最多啦,但是这样有可能分不完,根据模4的余数,换一个来补就好了。
#include <bits/stdc++.h>#define ll long long#define mod 1000000007#define N 100010#define inf 0x3f3f3f3fusing namespace std;inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f;}int q,n;int main(){// freopen("a.in","r",stdin); q=read(); while(q--){ n=read(); if(n==1||n==2||n==3||n==5||n==7||n==11){puts("-1");continue;} if(n%4==0){printf("%d\n",n/4);continue;} if(n%4==1){printf("%d\n",(n-9)/4+1);continue;} if(n%4==2){printf("%d\n",(n-6)/4+1);continue;} if(n%4==3){printf("%d\n",(n-15)/4+2);continue;} }return 0;}
阅读全文
0 0
- Codeforces Round #440
- Codeforces Round #440
- Codeforces Round #440(div2)
- Codeforces Round #440 D详解
- 【codeforces】Codeforces Round #363
- Codeforces round 440 div2 总结&&题解
- Codeforces Round #440 (A-C ) 题解
- Codeforces Round #440 div2 C. Maximum splitting
- Codeforces Round #440 (Div. 2) A B
- Codeforces Round #440 C. Maximum splitting
- Codeforces Round #270 Codeforces Round #270
- 【Codeforces】Codeforces Round #271 div2
- 【CODEFORCES】 Educational Codeforces Round 1
- Codeforces Educational Codeforces Round 5
- Codeforces Round #403 div2 (CodeForces
- Codeforces Round #404 div2 (CodeForces
- Codeforces Educational Codeforces Round 22
- Codeforces Educational Codeforces Round 27
- idea for mac 最全快捷键整理
- CentOS7和CentOS6怎样开启MySQL远程访问
- Java8 I/O源码-BufferedInputStream与BufferedOutputStream
- cocos2dx JNI 中 C++层与Java层之间的交互
- http请求头(响应头)、http2、https
- Codeforces Round #440
- 面向对象技术---学习总结
- [NOI2015]荷马史诗 哈夫曼树
- (转载)正向代理与反向代理的区别2
- 在ubuntu17.04下安装最新版QQ教程
- 卓越的教练是如何训练高手的?
- 资源共享与知识产权
- Aaron Swartz:早逝的编程天才
- 第5章 STM32新建工程及配置