题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5512

学习菊苣的博客,只粘链接,不粘题目描述了。

题目大意就是给了初始的集合{a, b},然后取集合里的两个元素进行加或者减的操作,生成新的元素。问最后最多能生成多少个元素。问答案的奇偶性。

首先一开始有a, b。那么如果生成了b-a(b>a),自然原来的数同样可以由b-a, a生成(b != 2a)。

于是如此反复下去,最后的数必然是可以由两个数p, 2p生成的。

于是所有的数肯定可以表示成xp+y*2p = (x+2y)p (x >= 0 && y >= 0)

很显然,最后集合里面所有的数都是p的倍数。而且p的所有小于等于n的倍数构成的集合就是原题中的集合。

于是只需要判断n/p的奇偶性。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <vector>
#define LL long long using namespace std; int n, a, b; void turn(int &a, int &b)
{
while (b)
{
if (a > b) swap(a, b);
b = b%a;
}
} int main()
{
//freopen("test.in", "r", stdin);
int T;
scanf("%d", &T);
for (int times = ; times < T; ++times)
{
scanf("%d%d%d", &n, &a, &b);
turn(a, b);
printf("Case #%d: ", times+);
if (n/a%) printf("Yuwgna\n");
else printf("Iaka\n");
}
return ;
}

ACM学习历程—HDU 5512 Pagodas(数学)的更多相关文章

  1. ACM学习历程—HDU 5073 Galaxy(数学)

    Description Good news for us: to release the financial pressure, the government started selling gala ...

  2. ACM学习历程—HDU5587 Array(数学 && 二分 && 记忆化 || 数位DP)(BestCoder Round #64 (div.2) 1003)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5587 题目大意就是初始有一个1,然后每次操作都是先在序列后面添加一个0,然后把原序列添加到0后面,然后 ...

  3. ACM学习历程—HDU 3915 Game(Nim博弈 && xor高斯消元)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3915 题目大意是给了n个堆,然后去掉一些堆,使得先手变成必败局势. 首先这是个Nim博弈,必败局势是所 ...

  4. ACM学习历程—HDU 5536 Chip Factory(xor && 字典树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目大意是给了一个序列,求(si+sj)^sk的最大值. 首先n有1000,暴力理论上是不行的. ...

  5. ACM学习历程—HDU 5534 Partial Tree(动态规划)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 题目大意是给了n个结点,让后让构成一个树,假设每个节点的度为r1, r2, ...rn,求f(x ...

  6. ACM学习历程—HDU 3949 XOR(xor高斯消元)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3949 题目大意是给n个数,然后随便取几个数求xor和,求第k小的.(重复不计算) 首先想把所有xor的 ...

  7. ACM学习历程—HDU1030 Delta-wave(数学)

    Description A triangle field is numbered with successive integers in the way shown on the picture be ...

  8. ACM学习历程—HDU 5317 RGCDQ (数论)

    Problem Description Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more an ...

  9. ACM学习历程—HDU 2112 HDU Today(map && spfa && 优先队列)

    Description 经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强.这时候,XHD夫妇也退居了二线 ...

随机推荐

  1. 圆环自带动画进度条ColorfulRingProgressView

    这是项目中遇到了,我也是借鉴大神的, 下载地址:https://github.com/oooohuhu/ColorfulRingProgressView 我把它导入了github中了,里面有详细的使用 ...

  2. Ubuntu 12.04使用uginx+fastcgi-mono-server2部署asp.net 网站

    Ubuntu 12.04使用uginx+fastcgi-mono-server2部署asp.net 网站 1.安装nginx和mono-fastcgi-server2 sodu apt-get  in ...

  3. Go 学习笔记

    官网: https://golang.org/ 环境: $GOROOT: GOROOT环境变量指定了Go的安装目录. $GOPATH: GOPATH 环境变量指定workspace的目录. 命令行: ...

  4. java中枚举类型的使用

    Java 枚举(enum) 详解7种常见的用法 JDK1.5引入了新的类型——枚举.在 Java 中它虽然算个“小”功能,却给我的开发带来了“大”方便. web项目里实体类使用枚举类型: 一般在该实体 ...

  5. sqlite增删改查 SimpleCursorAdapter 事务

    <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=&q ...

  6. R语言做正态性检验

    摘自:吴喜之:<非参数统计>(第二版),中国统计出版社,2006年10月:P164-165 1.ks.test()    例如零假设为N(15,0.2),则ks.test(x," ...

  7. xpath取最后一个元素

    取xpath最后一个book元素 book[last()] 取xpath最后第二个book元素 book[last()-1]

  8. 改善程序与设计的55个具体做法 day6

    条款13:以对象管理资源 资源,包括但不限于内存.句柄.GDI对象.数据库连接等. 内存要记得释放,句柄要记得closehandle, GDI对象要记得删除,数据库连接要记得关闭,等等等等. 以对象来 ...

  9. LeetCode:零钱兑换【322】【DP】

    LeetCode:零钱兑换[322][DP] 题目描述 给定不同面额的硬币 coins 和一个总金额 amount.编写一个函数来计算可以凑成总金额所需的最少的硬币个数.如果没有任何一种硬币组合能组成 ...

  10. rails跨域请求配置

    gem 'rack-cors', '~> 0.3.1'application.rb config.middleware.insert_before 0, "Rack::Cors&quo ...