HDU5190

杭電的BestCoder  34, 第一題,水題很簡單:

 題意,找一個電影院使話費最少,由於是團購,所以票的個數可能大於人的個數,水題,直接按照題意排序就好了

貼代碼:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;

int n, m;

typedef struct node
{
    int a, b;
};

node sq[200];

int cmp(node x, node y)
{
    int x1, y1;

    x1 = n%x.a==0 ? n/x.a : n/x.a+1;
    y1 = n%y.a==0 ? n/y.a : n/y.a+1;

    return x1*x.b < y1*y.b;
}

int main()
{
    while(~scanf("%d%d", &n, &m))
    {
        for(int i=0; i<m; ++i)
        {
            scanf("%d%d", &sq[i].a, &sq[i].b);
        }

        sort(sq, sq+m, cmp);

        int x = 0;

        if(n % sq[0].a == 0)
            x = (n/sq[0].a) * sq[0].b;
        else
            x = (n/(sq[0].a)+1)*sq[0].b;

        printf("%d\n",x);
    }

    return 0;
}

順便吐槽下,爲什麼cb的比賽中的數據這麼弱,我代碼根本就是錯誤的,但是提交上竟然AC了。。。結果可想而知,

悲劇的第一道題WA了。。。唉,還是自己太弱了。。。

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