我參考這個網址:
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了,但它一開始要印刷啊
想請問是我對題目的理解有誤嗎?
我參考這個網址:
https://sites.google.com/site/zsgititit/home/c-cheng-shi-she-ji/b042-a-shui-xian-wan-can
寫出來的程式碼如下:
#include
using namespace std;
#includestruct 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台裝訂機,所以不能這樣加