poj 2586
题意:每个月或者亏损s或者盈利d 调查8次连续的5个月 问若能盈利 则最大能盈利多少
贪心算法 :先求出能使五个月亏损的最小亏亏损月数 把那些亏损月数向后靠边
#include<iostream> using namespace std; int main() { int s,d,i; while(cin>>s>>d) { for(i=1;i<=5;i++) if(d*i>(5-i)*s) break; if(i>=5) { cout<<"Deficit"<<endl; continue; } switch (i) { case 1:if(d*2<s*10) cout<<s*10-d*2<<endl; else cout<<"Deficit"<<endl;break; case 2:if(d*4<s*8) cout<<s*8-d*4<<endl; else cout<<"Deficit"<<endl;break; case 3:if(d*6<s*6) cout<<s*6-d*6<<endl; else cout<<"Deficit"<<endl;break; case 4:if(d*9<s*3) cout<<s*3-d*9<<endl; else cout<<"Deficit"<<endl;break; } } return 0; }