Pagodas(等差数列)

时间:2022-09-18 21:18:52

Pagodas

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 24    Accepted Submission(s): 22

Problem Description
n pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yuntai Mountain, labelled from 1 to n. However, only two of them (labelled aand b, where 1≤a≠b≤n) withstood the test of time.

Two monks, Yuwgna and Iaka, decide to make glories great again. They take turns to build pagodas and Yuwgna takes first. For each turn, one can rebuild a new pagodas labelled i (i∉{a,b} and 1≤i≤n) if there exist two pagodas standing erect, labelled j and k respectively, such that i=j+k or i=j−k. Each pagoda can not be rebuilt twice.

This is a game for them. The monk who can not rebuild a new pagoda will lose the game.

 
Input
The first line contains an integer t (1≤t≤500) which is the number of test cases.
For each test case, the first line provides the positive integer n (2≤n≤20000) and two different integers a and b.
 
Output
For each test case, output the winner (``Yuwgna" or ``Iaka"). Both of them will make the best possible decision each time.
 
Sample Input
16 2 1 2 3 1 3 67 1 2 100 1 2 8 6 8 9 6 8 10 6 8 11 6 8 12 6 8 13 6 8 14 6 8 15 6 8 16 6 8 1314 6 8 1994 1 13 1994 7 12
 
Sample Output
Case #1: Iaka Case #2: Yuwgna Case #3: Yuwgna Case #4: Iaka Case #5: Iaka Case #6: Iaka Case #7: Yuwgna Case #8: Yuwgna Case #9: Iaka Case #10: Iaka Case #11: Yuwgna Case #12: Yuwgna Case #13: Iaka Case #14: Yuwgna Case #15: Iaka Case #16: Iaka
 
 

题意:给定n个位置(1 — n),每个位置只能建造一个塔。现在位置a和b已经建好了塔,已知每次可以新建塔的前提——能够找到两个塔j和k使得 i = j-k || i = j+k。

现在给出一个博弈局面,当某个人不能再建造塔时为输。问你谁能赢。

思路:当且仅当 a和b处于某个等差数列(差值不为1)时,才无法使得所有位置都建上塔。相反,则n个位置均可建塔。等差数列的差值 d = gcd(a, b),求出可以建塔的个数就可以了。

代码:

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int gcd(int x,int y){
return !y?x:gcd(y,x%y);
}
int main(){
int T,flot=;
int n,a,b;
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&n,&a,&b);
int t=gcd(a,b);
//printf("%d\n",t);
int temp=n/t-;
if(temp&)printf("Case #%d: Yuwgna\n",++flot);
else printf("Case #%d: Iaka\n",++flot);
}
return ;
}

Pagodas(等差数列)的更多相关文章

  1. Pagodas 等差数列

    nn pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yuntai Mountain, ...

  2. HDU 5512 - Pagodas - &lbrack;gcd解决博弈&rsqb;

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5512 Time Limit: 2000/1000 MS (Java/Others) Mem ...

  3. 等差数列(bzoj 3357)

    Description     约翰发现奶牛经常排成等差数列的号码.他看到五头牛排成这样的序号:"1,4,3,5,7" 很容易看出"1,3,5,7"是等差数列. ...

  4. 3357&colon; &lbrack;Usaco2004&rsqb;等差数列

    3357: [Usaco2004]等差数列 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 321  Solved: 153[Submit][Statu ...

  5. Find Missing Term in Arithmetic Progression 等差数列缺失项

    查找等差数列中的缺失项. e.g.Input: arr[] = {2, 4, 8, 10, 12, 14} Output: 6 Input: arr[] = {1, 6, 11, 16, 21, 31 ...

  6. n个整数中,找出尽可能多的数使他们组成一个等差数列,求最长等差数列的长度

    例子:  3,8,4,5,6,2          返回值应该为 :5 这是昨天做的一道优酷土豆的编程题,和leetcode中的128/ Longest Consecutive Sequence 有点 ...

  7. 洛谷 P1147 连续自然数和 Label&colon;等差数列

    题目描述 对一个给定的自然数M,求出所有的连续的自然数段,这些连续的自然数段中的全部数之和为M. 例子:1998+1999+2000+2001+2002 = 10000,所以从1998到2002的一个 ...

  8. TYVJ P1091 等差数列 Label:dp

    背景 广东汕头聿怀初中 Train#3 Problem 3 描述 等差数列的定义是一个数列S,它满足了(S[i]-S[i-1]) = d (i>1).显然的一个单独的数字或者两个数字也可以形成一 ...

  9. 洛谷P1214 &lbrack;USACO1&period;4&rsqb;等差数列 Arithmetic Progressions

    P1214 [USACO1.4]等差数列 Arithmetic Progressions• o 156通过o 463提交• 题目提供者该用户不存在• 标签USACO• 难度普及+/提高 提交 讨论 题 ...

随机推荐

  1. Android中的通知—Notification 自定义通知

    Android中Notification通知的实现步骤: 1.获取NotificationManager对象NotificationManager的三个公共方法:①cancel(int id) 取消以 ...

  2. Java面试葵花宝典

    面向对象的特征有哪些方面  1. 抽象:抽象就是忽略一个主题中与当前目标2. 无关的那些方面,3. 以便更充分地注意与当前目标4. 有关的方面.抽象并不5. 打算了解全部问题,而6. 只是选择其中的一 ...

  3. Java 8 与 &period;Net的平台发展

    从早期版本中,我们已经可以领略到一些令人兴奋的特性.但是开发真Andrew C.Oliver表示,尽管如此,Java语言在某些特性上还是落后于.Net.比如,Java 8 中最令人期待的Lambda表 ...

  4. Javascript图片轮播

    原文链接:http://www.imooc.com/article/7393 编辑HTML代码: <div id="wrap"><!--图片展示区--> & ...

  5. iOS基础 - UITextField

    一.UITextField 1.常见属性 @property(nonatomic,retain) UIView *leftView; // 设置文本框左边显示什么控件,可以让文本框的内容往右边挪动 @ ...

  6. 运用Unity结合PolicyInjection实现拦截器

    运用Unity结合PolicyInjection实现拦截器[结合操作日志实例] 上一篇文章我们通过Unity自身Unity.InterceptionExtension.IInterceptionBeh ...

  7. 向输出到console的文字加样式

    Chrome 控制台新玩法-向输出到console的文字加样式   有兴趣的同学可以文章最后的代码复制贴到控制台玩玩. Go for Code 在正常模式下,一般只能向console 控制台输出简单的 ...

  8. 【原】如何获取Java动态生成类?

    写作目的:Java大部分框架,如Spring,Hibernate等都会利用动态代理在程序运行的时候生成新的类, 有的时候为了学习,或者深入了解动态代理,想查看动态生成类的源代码究竟长怎么个样子, 通过 ...

  9. 在 UWP 中实现 Expander 控件

    WPF 中的 Expander 控件在 Windows 10 SDK 中并不提供,本文主要说明,如何在 UWP 中创建这样一个控件.其效果如下图: 首先,分析该控件需要的一些特性,它应该至少包括如下三 ...

  10. Eclipse使用maven命令安装第三方jar包

    使用原因: 使用maven时,有些第三方jar包是不能从maven远程仓库中下载得到,因此导致在pom.xml中添加jar包依赖时会怎么添加都会报错(Missing artifact ojdbc:oj ...