#30383: C++ 資測也AC, 但還是覺得很奇怪


e002933 (徐MAN)

學校 : 不指定學校
編號 : 158405
來源 : [111.71.113.217]
最後登入時間 :
2023-11-18 16:56:51
b231. TOI2009 第三題:書 -- 2009TOI研習營初選 | From: [118.150.201.99] | 發表日期 : 2022-05-17 22:59

我參考這個網址:

https://sites.google.com/site/zsgititit/home/c-cheng-shi-she-ji/b042-a-shui-xian-wan-can

寫出來的程式碼如下:

#include<iostream>
using namespace std;
#include<algorithm>

struct book {
    int p;
    int m;
    int c;
};

bool compare(struct book a, struct book b) {
    if(a.c == b.c)
        return a.m > b.m;
    else
        return a.c > b.c;
}

int main() {
    int n;
    while(cin>>n) {
        struct book a[n];
        int time = 0, f = 0;
        for(int i = 0; i < n; i++) {
            cin>>a[i].p>>a[i].m;
            a[i].c = a[i].m*10000+a[i].p;
        }
        sort(a, a+n, compare);
        for(int i = 0; i < n; i++) {
        //    a[i].p = a[i].c/10000;
        //    a[i].m = a[i].c%10000;
            time+=a[i].p;
            if(f < time+a[i].m)
                f = time+a[i].m;
        }
        cout<<f<<endl;
        cout<<endl;
    }
    return 0;
}

資測都AC

剛我試丟一組資測:

3

5 2

1 1

3 8

結果回傳是11

這三組資料怎麼也不可能只要11分鐘就可以完成吧?

2+1+8就等於11了,但它一開始要印刷啊

想請問是我對題目的理解有誤嗎?

 

 

 
#30384: Re: C++ 資測也AC, 但還是覺得很奇怪


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
b231. TOI2009 第三題:書 -- 2009TOI研習營初選 | From: [118.160.184.173] | 發表日期 : 2022-05-18 00:57

我參考這個網址:

https://sites.google.com/site/zsgititit/home/c-cheng-shi-she-ji/b042-a-shui-xian-wan-can

寫出來的程式碼如下:

#include
using namespace std;
#include

struct book {
    int p;
    int m;
    int c;
};

bool compare(struct book a, struct book b) {
    if(a.c == b.c)
        return a.m > b.m;
    else
        return a.c > b.c;
}

int main() {
    int n;
    while(cin>>n) {
        struct book a[n];
        int time = 0, f = 0;
        for(int i = 0; i < n; i++) {
            cin>>a[i].p>>a[i].m;
            a[i].c = a[i].m*10000+a[i].p;
        }
        sort(a, a+n, compare);
        for(int i = 0; i < n; i++) {
        //    a[i].p = a[i].c/10000;
        //    a[i].m = a[i].c%10000;
            time+=a[i].p;
            if(f < time+a[i].m)
                f = time+a[i].m;
        }
        cout<        cout<    }
    return 0;
}

資測都AC

剛我試丟一組資測:

3

5 2

1 1

3 8

結果回傳是11

這三組資料怎麼也不可能只要11分鐘就可以完成吧?

2+1+8就等於11了,但它一開始要印刷啊

想請問是我對題目的理解有誤嗎?

 

 


有n台裝訂機,所以不能這樣加

 
ZeroJudge Forum