ACM学习历程—HDU 5512 Pagodas(数学)
题目链接: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(数学)的更多相关文章
- ACM学习历程—HDU 5073 Galaxy(数学)
Description Good news for us: to release the financial pressure, the government started selling gala ...
- ACM学习历程—HDU5587 Array(数学 && 二分 && 记忆化 || 数位DP)(BestCoder Round #64 (div.2) 1003)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5587 题目大意就是初始有一个1,然后每次操作都是先在序列后面添加一个0,然后把原序列添加到0后面,然后 ...
- ACM学习历程—HDU 3915 Game(Nim博弈 && xor高斯消元)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3915 题目大意是给了n个堆,然后去掉一些堆,使得先手变成必败局势. 首先这是个Nim博弈,必败局势是所 ...
- ACM学习历程—HDU 5536 Chip Factory(xor && 字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目大意是给了一个序列,求(si+sj)^sk的最大值. 首先n有1000,暴力理论上是不行的. ...
- ACM学习历程—HDU 5534 Partial Tree(动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 题目大意是给了n个结点,让后让构成一个树,假设每个节点的度为r1, r2, ...rn,求f(x ...
- ACM学习历程—HDU 3949 XOR(xor高斯消元)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3949 题目大意是给n个数,然后随便取几个数求xor和,求第k小的.(重复不计算) 首先想把所有xor的 ...
- ACM学习历程—HDU1030 Delta-wave(数学)
Description A triangle field is numbered with successive integers in the way shown on the picture be ...
- ACM学习历程—HDU 5317 RGCDQ (数论)
Problem Description Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more an ...
- ACM学习历程—HDU 2112 HDU Today(map && spfa && 优先队列)
Description 经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强.这时候,XHD夫妇也退居了二线 ...
随机推荐
- IOS超强表格控件GMGridView
本文转载至 http://zyc-to.blog.163.com/blog/static/1715240020124235837247/ 介绍: iOS为我们提供UITableView类,实现了项目的 ...
- iOS base64加密解密
本文转载至 http://jingyan.baidu.com/article/93f9803fff45c9e0e46f5596.html 从参考资料的地址中下载GTMBase64.zip库文件包,并解 ...
- 计算点与x轴正半轴夹角atan2(double y,double x),返回弧度制(-PI,PI]
精度比acos , asin 什么的高些. Parameters y Value representing the proportion of the y-coordinate. x Value re ...
- c3p0;jdbc;dbcp;mybatis;ubutils;
[说明]今天还是完成了一定东西的,上午是jdbc的测试,下午是 数据库连接池 和 dbutils 的测试,晚上是mybatis的测试,都是找了一些网上的例子运行了一下,解决出现的问题. 一:今日完成 ...
- ubuntu 17 编译BTCoin
一. 安装开发环境 sudo apt-get update sudo apt-get install build-essential libtool autotools-dev autoconf pk ...
- LigerUI隐藏列
frozen: true 加入这个属性,此列不会在页面显示
- centos7 运行postgres 数据库脚本db.sql
[root@localhost ~]# su postgresbash-4.2$ psqlcould not change directory to "/root": Permis ...
- Call method 的使用
SAP学习日志---Call method 的使用 以及常见错误 转载▼ 可以通过以下方法 call method 1. 进入全局类中 找到方法,拖到程序中 2. 使用pattern 中的 AAB ...
- var妙用
var广泛使用其实也有用的.比如在一些不太确定类型的地方 (比如要区分int/uint/long/double的时候),用泛型太牛刀而不用又觉得不灵活的时候,其实是比较推荐var的比如设计某种类的时候 ...
- 多图切换jQuery图片滑块插件
在线演示 本地下载