您的位置:首页 > 其它

CodeForces - 557A Ilya and Diplomas

2016-07-07 17:03 309 查看
Ilya and Diplomas

Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u

Submit Status

Description

不久以后,一场信息学奥林匹克竞赛将在BERLAND举行,很多学生都要参加。

赛事组委会决定,每一名参赛的选手都可以获得奖励,分别是一等奖或者二等奖或者三等奖,每个人只能获得一个奖励。

他们还决定,一等奖最少有min1人,最多有max1人,二等奖最少有min2人,最多有max2人,三等奖最少有min3人,最多有max3人。

那么现在问题出来,有n个学生参加了这个比赛,如何分配一等奖、二等奖、三等奖的名额,才能使得这些名额数量满足条件。

注意:题目给出的数据一定能够分配好。

Input

题目第一行是一个正整数n,表示学生的人数(1<=n<=3*10^6)。

第二行两个正整数表示min1和max1,1<=min1<=max1<=10^ 6。

第三行两个正整数表示min2和max2,1<=min2<=max3<=10^ 6。

第四行两个正整数表示min3和max3,1<=min2<=max3<=10^ 6。

保证:min1+min2+min3<=n<=max1+max2+max3

Output

输出一行3个整数,表示每种奖励分配的名额,中间用空格隔开。

输出的答案为:首先要保证一等奖的人数尽量多,在一等奖人数一样的情况下,二等奖人数尽量多,二等奖人数一样的情况下,三等奖尽量多。

Sample Input

输入样例1:

6

1 5

2 6

3 7

输入样例2:

10

1 2

1 3

1 5

输入样例3:

6

1 3

2 2

2 2

Sample Output

输出样例1:

1 2 3

输出样例2:

2 3 5

输出样例3:

2 2 2

题意就不用说了

大概思路就是 先满足一等奖 然后依次二等奖 三等奖 =-= 水题

import java.util.Scanner;

public class Main{
private static  int num =0,sum;
private static Node[] node = new Node[3];
private static int[] array = new int [3];
private static int[] resarray =  new int[3];

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
num = scanner.nextInt();
for (int i = 0; i < 3; i++) {
Node Tnode = new Node();
Tnode.min = scanner.nextInt();
Tnode.max = scanner.nextInt();
array[i] = Tnode.max - Tnode.min;
node[i]=Tnode;
sum += Tnode.min;
}
if (sum == num) {
System.out.printf("%d %d %d\n",node[0].min,node[1].min,node[2].min);
}else {
int m = num - sum;
if (m<=array[0]) {
resarray[0] = node[0].min+m;
m=0;
}else {
resarray[0] = node[0].max;
m-=array[0];
}
if (m<=array[1]) {
resarray[1] = node[1].min+m;
m=0;
}else {
resarray[1] = node[1].max;
m -= array[1];
}
if (m<=array[2]) {
resarray[2] = node[2].min+m;
m = 0;
}else {
m-= array[2];
}
System.out.printf("%d %d %d\n",resarray[0],resarray[1],resarray[2]);
}
}
scanner.close();
}
static class Node{
int min;
int max;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: