CodeForces - 557A Ilya and Diplomas

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;
    }

}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章