Codeforces Round #311 (Div. 2)(A)贪心
2016-02-01 22:27
621 查看
A. Ilya and Diplomas
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Soon a school Olympiad in Informatics will be held in Berland, n schoolchildren will participate there.
At a meeting of the jury of the Olympiad it was decided that each of the n participants,
depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly one diploma.
They also decided that there must be given at least min1 and
at most max1 diplomas
of the first degree, at least min2 and
at most max2diplomas
of the second degree, and at least min3 and
at most max3 diplomas
of the third degree.
After some discussion it was decided to choose from all the options of distributing diplomas satisfying these limitations the one that maximizes the number of participants who receive diplomas of the first degree. Of all these options they select the one which
maximizes the number of the participants who receive diplomas of the second degree. If there are multiple of these options, they select the option that maximizes the number of diplomas of the third degree.
Choosing the best option of distributing certificates was entrusted to Ilya, one of the best programmers of Berland. However, he found more important things to do, so it is your task now to choose the best option of distributing of diplomas, based on the described
limitations.
It is guaranteed that the described limitations are such that there is a way to choose such an option of distributing diplomas that all nparticipants
of the Olympiad will receive a diploma of some degree.
Input
The first line of the input contains a single integer n (3 ≤ n ≤ 3·106) — the
number of schoolchildren who will participate in the Olympiad.
The next line of the input contains two integers min1 and max1 (1 ≤ min1 ≤ max1 ≤ 106) — the
minimum and maximum limits on the number of diplomas of the first degree that can be distributed.
The third line of the input contains two integers min2 and max2 (1 ≤ min2 ≤ max2 ≤ 106) — the
minimum and maximum limits on the number of diplomas of the second degree that can be distributed.
The next line of the input contains two integers min3 and max3 (1 ≤ min3 ≤ max3 ≤ 106) — the
minimum and maximum limits on the number of diplomas of the third degree that can be distributed.
It is guaranteed that min1 + min2 + min3 ≤ n ≤ max1 + max2 + max3.
Output
In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas.
The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first degree. Of all the suitable options, the best one is the one which maximizes the number of participants who receive diplomas of the
second degree. If there are several of these options, the best one is the one that maximizes the number of diplomas of the third degree.
Sample test(s)
input
output
input
output
input
output
题意:说了一堆废话,你有三门成绩,分别给出成绩的(min,max)分,三门总分和是n,问三门各自能够最高多少分,第1门优先级>第2门优先级>第3门优先级
题解:直接模拟吧
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <algorithm>
#define LL long long
using namespace std;
#define N 1000000
int main()
{
#ifdef CDZSC
freopen("i.txt","r",stdin);
#endif
int mx[10],mn[10];
int n;
while(~scanf("%d",&n))
{
int sum=0;
for(int i=0;i<3;i++)
{
scanf("%d%d",mn+i,mx+i);
sum+=mn[i];
}
n-=sum;
for(int i=0;i<3;i++)
{
if(n>=(mx[i]-mn[i]))
{
printf("%d ",mx[i]);
n-=(mx[i]-mn[i]);
}
else
{
printf("%d ",mn[i]+n);
n=0;
}
}
puts("");
}
return 0;
}
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Soon a school Olympiad in Informatics will be held in Berland, n schoolchildren will participate there.
At a meeting of the jury of the Olympiad it was decided that each of the n participants,
depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly one diploma.
They also decided that there must be given at least min1 and
at most max1 diplomas
of the first degree, at least min2 and
at most max2diplomas
of the second degree, and at least min3 and
at most max3 diplomas
of the third degree.
After some discussion it was decided to choose from all the options of distributing diplomas satisfying these limitations the one that maximizes the number of participants who receive diplomas of the first degree. Of all these options they select the one which
maximizes the number of the participants who receive diplomas of the second degree. If there are multiple of these options, they select the option that maximizes the number of diplomas of the third degree.
Choosing the best option of distributing certificates was entrusted to Ilya, one of the best programmers of Berland. However, he found more important things to do, so it is your task now to choose the best option of distributing of diplomas, based on the described
limitations.
It is guaranteed that the described limitations are such that there is a way to choose such an option of distributing diplomas that all nparticipants
of the Olympiad will receive a diploma of some degree.
Input
The first line of the input contains a single integer n (3 ≤ n ≤ 3·106) — the
number of schoolchildren who will participate in the Olympiad.
The next line of the input contains two integers min1 and max1 (1 ≤ min1 ≤ max1 ≤ 106) — the
minimum and maximum limits on the number of diplomas of the first degree that can be distributed.
The third line of the input contains two integers min2 and max2 (1 ≤ min2 ≤ max2 ≤ 106) — the
minimum and maximum limits on the number of diplomas of the second degree that can be distributed.
The next line of the input contains two integers min3 and max3 (1 ≤ min3 ≤ max3 ≤ 106) — the
minimum and maximum limits on the number of diplomas of the third degree that can be distributed.
It is guaranteed that min1 + min2 + min3 ≤ n ≤ max1 + max2 + max3.
Output
In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas.
The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first degree. Of all the suitable options, the best one is the one which maximizes the number of participants who receive diplomas of the
second degree. If there are several of these options, the best one is the one that maximizes the number of diplomas of the third degree.
Sample test(s)
input
6 1 5 2 6 3 7
output
1 2 3
input
10 1 2 1 3 1 5
output
2 3 5
input
6 1 3 2 2 2 2
output
2 2 2
题意:说了一堆废话,你有三门成绩,分别给出成绩的(min,max)分,三门总分和是n,问三门各自能够最高多少分,第1门优先级>第2门优先级>第3门优先级
题解:直接模拟吧
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <algorithm>
#define LL long long
using namespace std;
#define N 1000000
int main()
{
#ifdef CDZSC
freopen("i.txt","r",stdin);
#endif
int mx[10],mn[10];
int n;
while(~scanf("%d",&n))
{
int sum=0;
for(int i=0;i<3;i++)
{
scanf("%d%d",mn+i,mx+i);
sum+=mn[i];
}
n-=sum;
for(int i=0;i<3;i++)
{
if(n>=(mx[i]-mn[i]))
{
printf("%d ",mx[i]);
n-=(mx[i]-mn[i]);
}
else
{
printf("%d ",mn[i]+n);
n=0;
}
}
puts("");
}
return 0;
}
相关文章推荐
- ubuntu创建快捷方式
- hadoop_7 : MapReduce续
- grep语法和正则表达式
- python学习笔记Day3
- JavaScript 使用
- FTP服务器架设(2)vsftpd 安装
- Win7系统禁止生成Thumbs.db缓存文件的方法
- 《笨办法学Python》 第30课手记
- LoadRunner监控Linux与Windows方法
- 从头认识Spring-1.13 注入properties与null
- sql语法记录 to_date函数和oracle连接写法
- perl weixin 发消息接口 webwxsendmsg
- SQLServer数据库插入记录,获取自增长的主键的值
- Xamarin.Forms之Effects的使用
- 【解题报告】2015ACM/ICPC亚洲区上海站
- 我焦躁,并不只是心里承受,还是因为我上面担着。
- Js As Ordinal
- SMACH(四)----状态State类的实现和中文注释
- android的m、mm、mmm编译命令的使用
- 1.AJAX