原题:
JH苦练10年,终于成为了一个神箭手,在下山之前,大师兄YZ不放心,想考验他,只给他一定时间t,同时给他n支箭,最终根据他的表现,考虑他是否能下山。 对于每发一次箭,YZ给他4种成绩(优、良、中、差),JH有三种拉弓以及瞄准时间a ,b,c(a>=b>=c)分别能拿优,良,中等级,如果不拉弓不瞄(直接射),只能拿差(不能中靶)了。 现在JH想知道,在保证自己弹无虚发(不获得差)的情况下,最多能拿多少个优。 如果JH不能做到弹无虚发,输出Oh,my god!
Input
输入数据包含T组: 对于每组数据,第一行为一个整数n,表示总共有n支箭。
(0<n<=1000)
之后n行,每行包含三个数字a,b,c,分别表示拿对应等级所需要花的时间。
(0<c<=b<=a<=1000)
之后一个数字t,表示JH有考核总时间为t
(0<=t<=1e6)Output
对于每组输入,如果JH能箭无虚发,则输出一个数字x,表示最多能拿到的优的数量。如果不能,则输出Oh,my god!
Sample Input
3
1
3 2 1
1
2
3 2 1
3 2 1
4
2
3 2 1
3 2 1
1Sample Output
0
1
Oh,my god!
代码1:
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
//DEBUG MODE
#define debug 0
//循环
#define REP(n) for(int o=0;o<n;o++)
const int maxn = 1005;
struct Time {
int PTime,MTime;
int delta;
Time(int x=0,int y=0) {
PTime = x;
MTime = y;
delta = x - y;
}
bool operator < (const Time &rhs)const {
return delta > rhs.delta;
}
};
Time UseTime[maxn];
void Do() {
int t,n,UT=0;
scanf("%d",&n);
int sum = 0;
REP(n) {
int a,c;
scanf("%d%*d%d",&a,&c);
sum += c;
UT += a;
UseTime[o] = Time(a,c);
}
scanf("%d",&t);
if(sum > t) {
printf("Oh,my god!\n");
return;
}
sort(UseTime,UseTime + n);
int ans = n;
for(int i = 0;UT > t;i++) {
ans--;
UT -= UseTime[i].delta;
}
printf("%d\n",ans);
}
int main() {
int T;
scanf("%d",&T);
while(T--)
Do();
return 0;
}
代码2:
#include <algorithm>
#include <iostream>
using namespace std;
struct TimeNode {
int a, c, delta;
TimeNode(int A = 0, int C = 0){
a = A;
c = C;
delta = a-c;
}
bool operator < (const TimeNode &rhs) const {
return delta > rhs.delta;
}
};
int main(void){
TimeNode times[1005];
int T = 0;
cin >> T;
while (T--){
int n = 0, t = 0, a = 0, b = 0, c = 0, a_plus = 0, c_plus = 0;
cin >> n;
for (int count = 0; count < n; count++){
cin >> a >> b >> c;
times[count] = TimeNode(a,c);
a_plus += a;
c_plus += c;
}
cin >> t;
if (c_plus > t){
cout << "Oh,my god!" << endl;
continue;
}
sort(times, times+n);
for (int count = 0; a_plus > t; count++){
n--;
a_plus -= times[count].delta;
}
cout << n << endl;
}
return 0;
}
程序1正确但是程序2无法通过,但是我觉得两个程序的语义是一样的,求解。