Guest User

Untitled

a guest
Oct 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. #include<string>
  4. #include<cstdio>
  5. #include<fstream>
  6. #include<iomanip>
  7. using namespace std;
  8. int mouse(int n,int m);
  9. int main()
  10. {
  11. int n,m,num;
  12. while(cin>>n>>m)
  13. {
  14. num=mouse(n,m);//數量,月數
  15. cout<<n<<" "<<m<<" "<<num<<endl;
  16. }
  17. }
  18. int mouse(int n,int m)
  19. {
  20. int month,ans[40];
  21. ans[0]=n;//第0個月
  22. for(month=1;month<=m;month++)
  23. {
  24. if(month==1)
  25. {
  26. ans[1]=ans[0]+ans[0]/2*3;
  27.  
  28. }
  29. else if(month==2)
  30. {
  31. ans[2]=ans[1]+(ans[1]/2)*3;
  32.  
  33. }
  34. else if(month==3)
  35. {
  36. ans[3]=ans[2]+(ans[2]/2*3)-n;
  37. }
  38. else//四個月後都是前一個月的老鼠量+(前一個月的老鼠量/2 * 3)-(第i個月/2 * 3)
  39. { //i=0,1,2,..n-4;
  40. ans[month]=ans[month-1]+(ans[month-1]/2*3)-(ans[month-4]/2*3);
  41. }
  42. }
  43. return ans[m];
  44.  
  45. }
Add Comment
Please, Sign In to add comment