Educational Codeforces Round 24
来源:互联网 发布:网络论坛营销方案 编辑:程序博客网 时间:2024/06/09 20:46
There are n students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly k times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of n). It's possible that there are no winners.
You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.
The first (and the only) line of input contains two integers n and k (1 ≤ n, k ≤ 1012), where n is the number of students and k is the ratio between the number of certificates and the number of diplomas.
Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible.
It's possible that there are no winners.
18 2
3 6 9
9 10
0 0 9
1000000000000 5
83333333333 416666666665 500000000002
1000000000000 499999999999
1 499999999999 500000000000
题意:
总学生人数为n,就是获证书的人数为x,获文凭的人数为y,输出x,y和没有获奖的人数z,有两个要求如下:
x>=y*k
x+y<=n/2
分析:两种情况
没人获奖时:获奖的最低限度是一人获奖:也就是1+k<=n/2,自然1+ k>n/2就是没人获奖的情况0输出 0, 0,n就可以
有人获奖时:最大限度就是取等号的时候也就是x=y*k,x+y=n/2 => y=(n/2)/(k+1),x=k*y,z=n-(x+y);
Code:
#include<stdio.h>#define ll long longusing namespace std;ll n,k;int main(){ while(~scanf("%lld%lld",&n,&k)) { ll x=n/2; if(1+k>x) printf("0 0 %lld\n",n); else { x=x/(k+1); ll y=k*x; ll z=n-(x+y); printf("%lld %lld %lld\n",x,y,z); } } return 0;}
分析:首先考虑找不到每个a[i]的情况:
1.存在a[l[i]有多个不一样的值
2.存在当前a[l[i]]==0时l[i]已经被使用
3.最后找不到未被使用的j(1<=j<n),使得 a[i]找不到对应的值
Code:
#include<stdio.h>#include<string.h>using namespace std;int n,m;int b[110];int a[110];int vis[110];int main(){ while(~scanf("%d%d",&n,&m)) { for(int i=1; i<=m; i++) scanf("%d",&b[i]); memset(vis,0,sizeof(vis)); memset(a,0,sizeof(a)); int flag=0; for(int i=1; i<m; i++) { int x=b[i+1]-b[i]; if(x<=0) x+=n; if(a[b[i]]==0&&!vis[x]) { a[b[i]]=x; vis[x]=1; } else if(a[b[i]]==0&&vis[x]) { flag=1; //printf("hhhhhhhh\n"); } if(a[b[i]]!=x) { //printf("%d %d\n",a[b[i]],x); //printf("aaaaaaa\n"); flag=1; } } for(int i=1; i<=n; i++) { if(!a[i]) { for(int j=1; j<=n; j++) { if(!vis[j]) { vis[j]=1; a[i]=j; break; } } } } if(flag) printf("-1\n"); else for(int i=1; i<=n; i++) i==n?printf("%d\n",a[i]):printf("%d ",a[i]); } return 0;}
- Educational Codeforces Round 24
- Educational Codeforces Round 24
- Educational Codeforces Round 24
- Educational Codeforces Round 24 题解
- Educational Codeforces Round 24 B. Permutation Game
- Educational Codeforces Round 1
- Educational Codeforces Round 2
- Educational Codeforces Round 2
- Educational Codeforces Round 2
- Educational Codeforces Round 3
- Codeforces Educational Round 3
- Codeforces Educational Round 5
- Codeforces Educational round 5
- Educational Codeforces Round 5
- Educational Codeforces Round 6
- Educational Codeforces Round 6
- Educational Codeforces Round 7
- Educational Codeforces Round 7
- MySQL5.7性能优化系列(二)——SQL语句优化(2)——使用 Semi-Join半连接变换优化子查询,派生表和视图
- ssm批量删除和模糊查询
- Linux C线程总结(1)
- Java基础概念
- SQL替换字段中部分字符
- Educational Codeforces Round 24
- Linux C++ zookeeper创建临时节点类封装
- springData是什么,深入理解
- 在使用django 的过程中难免的会使用到format表单进行提交,如果出现“CSRF验证失败. 相应中断”.该如何解决呢?
- 数字分隔(二)
- 根据输入成绩显示相应的级别
- opencv3.1 调试错误“未加载opencv_world310.pdb”
- JavaScript中的基本数据类型
- 浏览器中输入URL发生的事情