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

【题意】



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

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

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

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

【题解】



写个递归求解就好;

每次短边的边长不变;

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

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



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 110; LL a, b,ans = 0; void dfs(LL a, LL b)
{
//a>b
if (a == b)
{
ans++;
return;
}
LL t = a / b;
a = a%b;
if (a == 0)
{
a = b;
t--;
}
ans += t;
dfs(b, a);
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
rel(a), rel(b);
dfs(max(a,b),min(a, b));
printf("%lld\n", ans);
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【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. Modular_exponentiation模幂运算

    https://en.wikipedia.org/wiki/Modular_exponentiation 蒙哥马利(Montgomery)幂模运算是快速计算a^b%k的一种算法,是RSA加密算法的核心 ...

  2. Android开发中常用的一些小技巧(转载)

    http://www.jb51.net/article/61135.htm Activity.startActivities() 常用于在应用程序中间启动其他的Activity. TextUtils. ...

  3. 题解报告:hdu 1233 还是畅通工程

    Problem Description 某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离.省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能 ...

  4. Python三方库xlrd,xlwd-Excel读写

    恩,我是翻译汪,主要内容来自http://www.python-excel.org/ 在xlrd,xlwt这两个库中,Excel的结构表示为workbook整个Excel对象,sheet工作表,row ...

  5. dubbo之主机绑定

    主机绑定 查找顺序 缺省主机 IP 查找顺序: 通过 LocalHost.getLocalHost() 获取本机地址. 如果是 127.* 等 loopback 地址,则扫描各网卡,获取网卡 IP. ...

  6. (转)Arcgis for javascript实现百度地图ABCD marker的效果

    概述: 在我的博客中,有一篇相关的文章,这段时间,有很多人问我求源码,只是时间过去已长,源代码已找不到,乘着这个9.3放假,又重新实现了下,并相关代码做了优化,在此贴出来,方便大家使用. 相关文章地址 ...

  7. ECC 构筑安全可靠的区块链

    现在很多基于区块链技术的数字货币系统,比如:比特币和以太坊,它们都使用了椭圆曲线密码学(ECC, Elliptic Curve Cryptography)来保证货币的安全性. ECC 是一种公开密钥密 ...

  8. iOS UIWebView 访问https绕过证书验证的方法

    @implementation NSURLRequest (NSURLRequestWithIgnoreSSL) + (BOOL)allowsAnyHTTPSCertificateForHost:(N ...

  9. AcDbTable 类

    Table 例子学习笔记在这个例子中,ARX向我们展示了ACDBTABLE类的一些基本操作方法,ACDBTABLE类是ACAD2005及其以后的产品,应该是说ACDBDATATABLE的升级产品,Ac ...

  10. CAD直接打印,不出现打印对话框(com接口VB语言)

    主要用到函数说明: MxDrawXCustomFunction::Mx_Print 直接打印,不出现打印对话框,详细说明如下: 参数 说明 double ptLBx 打印的范围左下角x double ...