题目链接
这题是tm一个翻译题吧。
即使这样我也WA了
翻译:感谢康文骐的Blog。
思路:
- 因为后两个月是盈利的关键,并且依然要保证连续 5 个月亏损,所以要把每组中的亏损月往后放。
- 首先给大家逐字逐句翻译一遍:
Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc. (ACM公司因为Y2K故障丢失了重要数据)
All what they remember is that MS Inc. posted a surplus or a deficit each month of 1999 and each month when MS Inc. posted surplus, the amount of surplus was s and each month when MS Inc. posted deficit, the deficit was d.(现在只知道1999年里每个月要么盈利s,要么亏损d,没有其他可能) They do not remember which or how many months posted surplus or deficit. (不知道哪个或多少个月份是亏损盈利,换言之任意月份既可能盈利s,又可能亏损d) MS Inc., unlike other companies, posts their earnings for each consecutive 5 months during a year. (这个公司蛮奇怪,它会报道一年中的连续5个月的盈利和,注意是一年中的,换言之本公司只有5~12月份会有这个报告) ACM knows that each of these 8 postings reported a deficit but they do not know how much. (公司知道这8份报表每一份都是亏损的 这公司开的) The chief accountant is almost sure that MS Inc. was about to post surplus for the entire year of 1999. Almost but not quite. (主会计师觉得这一年总体上大概率是盈利的,但他也不确定 说了跟没说一样)
Write a program, which decides whether MS Inc. suffered a deficit during 1999, or if a surplus for 1999 was possible, what is the maximum amount of surplus that they can post.(请您给看看今年有没有可能盈利啊,有可能您再给算算最多能赚多少呗,没有就算了,唉)
- 然后第一遍写还没写对:
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int s,d;
while(cin>>s>>d){
if(d > 4*s)
cout<<10*s - 2*d<<endl;
else if(2*d > 3*s)
cout<<8*s - 4*d<<endl;
else if(3*d > 2*s)
cout<<6*s - 6*d<<endl;
else if(4*d > s)
cout<<4*s - 8*d<<endl;
else
cout<<"Deficit"<<endl;
}
return 0;
}
- 忘记了判断如果可能,是否真的能盈利。
- 改一遍,提交,WA:
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int s,d;
int ans;
while(cin>>s>>d){
if(d > 4*s)
ans = 10*s - 2*d;
else if(2*d > 3*s)
ans = 8*s - 4*d ;
else if(3*d > 2*s)
ans = 6*s - 6*d ;
else if(4*d > s)
ans = 4*s - 8*d ;
else
ans = -1;
if(ans >= 0)
cout<<ans<<endl;
else
cout<<"Deficit"<<endl;
}
return 0;
}
- 再仔细看看,原来这种情况:sddddsddddss 并不能亏损。因为后面有了 2s - 3d。应改成 sddddsddddsd。改完AC。
- 660K 47MS
//660K 47MS
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int s,d;
int ans;
while(cin>>s>>d){
if(d > 4*s)
ans = 10*s - 2*d;
else if(2*d > 3*s)
ans = 8*s - 4*d ;
else if(3*d > 2*s)
ans = 6*s - 6*d ;
else if(4*d > s)
ans = 3*s - 9*d ;
else
ans = -1;
if(ans >= 0)
cout<<ans<<endl;
else
cout<<"Deficit"<<endl;
}
return 0;
}
总结:
- 提高英语水平。
- 注意each是每个。
- 有可能盈利的情况也可能不盈利;一串连下来的枚举也可能有变化。
- 要认真。