跳至正文

USACO 1.3.1 Mixing Milk

  • OI路程

  这题是个纯贪心题,本来是打算使用快排的,想到考试时可能不允许使用快排,自己写又太麻烦了,所以我就懒得用快排了,题目的数据量也不是很大,直接使用数组进行排序就是!
  当然没有什么明显的问题,一次AC,代码如下:

/
LANG: C
ID: yylogoo2
PROG: milk
/
#include <stdio.h>
unsigned milk[1001];

int main(void)
{
        int n, m;
        int i, got = 0, ans = 0;
        unsigned a, b;
        freopen("milk.in""r"stdin);
        freopen("milk.out""w"stdout);
        scanf("%d%d\n", &n, &m);
        for(i = 0; i < m; i++){
                scanf("%u%u\n", &a, &b);
                milk[a] += b;
        }
        for(i = 0; got != n; i++){
                if(milk[i] != 0){
                        if(milk[i] + got > n){
                                ans += (n – got) i;
                                got = n;
                        }else{
                                ans += milk[i]
i;
                                got += milk[i];
                        }
                }
        }
        printf("%u\n", ans);
        return 0;
}

发表回复

您的电子邮箱地址不会被公开。