poj 2586 Y2K Accounting Bug(贪心算法,水题一枚)
#include <iostream> using namespace std; /*248K 32MS*/ int main() { int s,d; while(cin>>s>>d) { int count=0; for(int i=5;i>0;i--) { if(s*i<(5-i)*d) { count=i; break; } } int total=s*count-d*(5-count); total*=2; if(count>=2) total+=2*s; else total+=count*s-(2-count)*d; if(total<0) cout<<"Deficit"<<endl; else cout<<total<<endl; } }
水题 就不多说什么了,直接枚举就能ac