【题目链接】:http://codeforces.com/contest/527/problem/A

【题意】



让你每次从一个长方形里面截出一个边长为长方形的较短边的正方形;

然后留下的部分重复上述步骤;

直到剩下的部分为正方形为止;

问你一共截出了多少个正方形

【题解】



写个递归求解就好;

每次短边的边长不变;

然后答案递增长边长度/短边长度

长边的边长变为长边%短边->为0的话就改为短边长度,下一次递归结束就好;



【完整代码】

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,m,rt<<1
  4. #define rson m+1,r,rt<<1|1
  5. #define LL long long
  6. #define rep1(i,a,b) for (int i = a;i <= b;i++)
  7. #define rep2(i,a,b) for (int i = a;i >= b;i--)
  8. #define mp make_pair
  9. #define ps push_back
  10. #define fi first
  11. #define se second
  12. #define rei(x) scanf("%d",&x)
  13. #define rel(x) scanf("%lld",&x)
  14. #define ref(x) scanf("%lf",&x)
  15. typedef pair<int, int> pii;
  16. typedef pair<LL, LL> pll;
  17. const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
  18. const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
  19. const double pi = acos(-1.0);
  20. const int N = 110;
  21. LL a, b,ans = 0;
  22. void dfs(LL a, LL b)
  23. {
  24. //a>b
  25. if (a == b)
  26. {
  27. ans++;
  28. return;
  29. }
  30. LL t = a / b;
  31. a = a%b;
  32. if (a == 0)
  33. {
  34. a = b;
  35. t--;
  36. }
  37. ans += t;
  38. dfs(b, a);
  39. }
  40. int main()
  41. {
  42. //freopen("F:\\rush.txt", "r", stdin);
  43. rel(a), rel(b);
  44. dfs(max(a,b),min(a, b));
  45. printf("%lld\n", ans);
  46. //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
  47. return 0;
  48. }

【codeforces 527A】Playing with Paper的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 755B】PolandBall and Game

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【codeforces 754B】 Ilya and tic-tac-toe game

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【codeforces 546D】Soldier and Number Game

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 546C】Soldier and Cards

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【13.77%】【codeforces 734C】Anton and Making Potions

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【32.89%】【codeforces 574D】Bear and Blocks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【26.67%】【codeforces 596C】Wilbur and Points

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【22.73%】【codeforces 606D】Lazy Student

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. bzoj 3301 Cow Line

    题目大意: n的排列,K个询问 为P时,读入一个数x,输出第x个全排列 为Q时,读入N个数,求这是第几个全排列 思路: 不知道康拓展开是什么,手推了一个乱七八糟的东西 首先可以知道 把排列看成是一个每 ...

  2. [Django基础] gunicorn启动django时静态文件的加载

    目前在用nginx+gunicorn对django进行部署 当我用gunicorn -w 4 -b 127.0.0.1:8080 myproject.wsig:application启动django时 ...

  3. Luogu1275魔板

    https://zybuluo.com/ysner/note/1136271 题面 有这样一种魔板:它是一个长方形的面板,被划分成\(n\)行\(m\)列的\(n*m\)个方格.每个方格内有一个小灯泡 ...

  4. openstack封装待调试

  5. 仪表盘(Speedometer) icon 设计

  6. yii登陆中添加验证码

    1.在SiteController中添加如下代码: /** * Declares class-based actions. */ public function actions() { return  ...

  7. mysql中 groupby分组

    引用自http://www.cnblogs.com/mo-beifeng/archive/2012/02/07/2341886.html#2341105 --按某一字段分组取最大(小)值所在行的数据 ...

  8. P3299 [SDOI2013]保护出题人

    传送门 全世界都会二分可海星-- 首先记\(sum[i]\)为\(a[i]\)的前缀和,那么第\(i\)个的答案就是\(max\{\frac{sum[i]-sum[j-1]}{x+(i-j)d}\}\ ...

  9. List 序列化

    序列化list http://kchen.cnblogs.com/ 通过序列化和反序列化泛型数据实体集合来实现持久化数据对象的方法 通过序列化和反序列化泛型数据实体集合来实现持久化数据对象的方法 我们 ...

  10. 在vue项目npm run build后,index.html中引入css和js 报MIME type问题

    问题: 1.在vue项目中,build打包后,index页面打开会报错, MIME type ('text/html') ;报错内容:because its MIME type ('text/html ...