代码改变世界

1620. SCVs and minerals

2011-04-21 01:18  Min·zc  阅读(252)  评论(0编辑  收藏  举报
 1 #include <iostream>
 2 using namespace std;
 3 int main()
 4 {
 5         int t;
 6         cin>>t;
 7         while(t--)
 8         {
 9                 int n,m,c,p,s;
10                 cin>>n>>m>>c>>p>>s;
11                 for(int i=1;i<=s;i++)
12                 {
13                         int tem=m/p;
14                         if(tem*c*(s-i+1)>tem*p)//如果能盈利才生产
15                         {
16                                 m-=tem*p;
17                                 n+=tem;
18                         }
19                         m+=n*c;
20                 //    cout<<i<<" "<<m<<endl;
21                 }
22                 cout<<m<<endl;  
23         }
24 }