Barbarian tribes 

In a lost land two primitive tribes coexist: Gareds and Kekas. Every summer solstice they meet and compete to decide which tribe will be the favorite of the gods for the rest of the year, following an old ritual:

First, a local guru chooses three numbers at random: n, m and k.
Afterwards, n Gared maids (in the positions
1, 2,..., n)
and m Keka maids (in the positions
n + 1, n + 2,..., n + m)
are placed in a circle looking inwards.
Then the guru begins to count
1, 2,..., k starting at the first Gared maid.
When the k-th maid is reached, she is immediately sacrificed to the gods.
The guru then counts again
1, 2,..., k
starting at the maid following the one just sacrificed.
Again, the k-th maid reached this way is sacrificed.
After every two sacrifices,
the second sacrificed maid is replaced by a new maid.
In order to decide the tribe of the new maid,
the guru looks at the heads of the two maids just killed
(nothing else remains of them).
If both heads are of the same tribe, the guru calls a Gared maid.
If the heads are from different tribes, the guru calls a Keka maid.
The process then begins again
(counting and sacrificing twice and replacing once)
starting to count at the maid following the new maid
just added to the circle.
Since the number of maids reduces by one after every step
(of two sacrifices and one replacement),
after n + m - 1 steps only one maid remains.

According to the tradition,
the tribe of the last maid will be the favorite of the gods.
(What the guru does to the last maid is something you don't want to know.)
Anyway, write a program such that,
given n, m and k, writes the name of the fortunate tribe.

For example, this is what happens for n = m = 3 and k = 2
(a ``G'' denotes a Gared maid and a ``K'' denotes a Keka maid;
the subindexes mark the order the maids enter the circle):

  1. Initial content of the circle: G1 G2 G3 K4 K5 K6

    Starting to count at G1.
    First sacrifice: G2.
    Second sacrifice: K4 (replaced by K7).
  2. Content of the circle: G1 G3 K7 K5 K6

    Starting to count at K5.
    First sacrifice: K6.
    Second sacrifice: G3 (replaced by K8).
  3. Content of the circle: G1 K8 K7 K5

    Starting to count at K7.
    First sacrifice: K5.
    Second sacrifice: K8 (replaced by G9).
  4. Content of the circle: G1 G9 K7

    Starting to count at K7.
    First sacrifice: G1.
    Second sacrifice: K7 (replaced by K10).
  5. Content of the circle: G9 K10

    Starting to count at G9.
    First sacrifice: K10.
    Second sacrifice: G9 (replaced by K11).
  6. Final content of the circle: K11

Input

Input consists of zero ore more test cases.
Each test case consists of a line
with three positive integers: n, m and k.
You can assume
1n + m2000 and
1k1000.
A test case with
n = m = k = 0 ends the input and must not be processed.

Output

For every test case, print either "Gared" or "Keka" as convenient.

Sample Input

3 3 2
4 2 2
0 1 7
0 0 0

Sample Output

Keka
Gared
Keka 开始以为是约瑟夫环,TLE了...郁闷半天,后来看了题解恍然大悟。自己还是得加强下思维转换。。。

题目大意:给出n,m和k,有n个G,m个K,站成一个圈,现在有个杀手每次走k步,杀掉当前位置的人,每次杀两个人之后如果这两个人都是G或都是K,就用G补上,否则就用K补上。问说最后剩一个谁。

解题思路:在每杀两个人这个地方进行考虑。无非3种情况:杀两G,多一G,杀两K,多一G,杀一G一K,多一K。

     注意,杀一G一K,多一K时,K的数目不变,所以K的人数只会以减2的方式减少。如果K一开始是奇数的话是永远减少不完的,最终肯定剩下K。如果一开始是偶数,最终减少完的必然是K,剩下G。

代码:

 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int main()
{
int n, m, k;
while(scanf("%d%d%d", &n, &m, &k))
{
if(!n && !m && !k) break;
if(m%) printf("Keka\n");
else printf("Gared\n");
}
return ;
}

【推理】UVa 10771 - Barbarian tribes的更多相关文章

  1. uva 10771

    思路题 K的人数只能以2减少 #include <cstdio> #include <cstdlib> #include <cmath> #include < ...

  2. UVA 11246 - K-Multiple Free set(数论推理)

    UVA 11246 - K-Multiple Free set 题目链接 题意:一个{1..n}的集合.求一个子集合.使得元素个数最多,而且不存在有两个元素x1 * k = x2,求出最多的元素个数是 ...

  3. uva 1561 - Cycle Game(推理)

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=4336" style=""& ...

  4. UVA 1364 - Knights of the Round Table (获得双连接组件 + 二部图推理染色)

    尤其是不要谈了些什么,我想A这个问题! FML啊.....! 题意来自 kuangbin: 亚瑟王要在圆桌上召开骑士会议.为了不引发骑士之间的冲突. 而且可以让会议的议题有令人惬意的结果,每次开会前都 ...

  5. uva 11892 - ENimEN(推理)

    题目链接:uva 11892 - ENimEN 题目大意:给定n堆石子的个数,两人轮流选择石子堆取石子,直到不能取为失败,附加条件,假设前一次操作,即队手的操作,没有将选中石子堆中的石子取完,那么当前 ...

  6. 【推理,贪心】UVa 1319 - Maximum

    看到了大神的代码.理解了好久...真是差距. 题意:给出m, p, a, b,然后xi满足已下两个公式, 求 xp1 + xp2 +...+ xpm 的最大值. 1.-1/sqrt(a) <= ...

  7. 【置换,推理】UVa 1315 - Creaz tea party

    Dsecription n participants of «crazy tea party» sit around the table. Each minute one pair of neighb ...

  8. UVa 1614 Hell on the Markets (贪心+推理)

    题意:给定一个长度为 n 的序列,满足 1 <= ai <= i,要求确实每一个的符号,使得它们和为0. 析:首先这一个贪心的题目,再首先不是我想出来的,是我猜的,但并不知道为什么,然后在 ...

  9. UVA 11774 - Doom&#39;s Day(规律)

    UVA 11774 - Doom's Day 题目链接 题意:给定一个3^n*3^m的矩阵,要求每次按行优先取出,按列优先放回,问几次能回复原状 思路:没想到怎么推理,找规律答案是(n + m) / ...

随机推荐

  1. 使用C语言实现二维,三维绘图算法(3)-简单的二维分形

    使用C语言实现二维,三维绘图算法(3)-简单的二维分形 ---- 引言---- 每次使用OpenGL或DirectX写三维程序的时候, 都有一种隔靴搔痒的感觉, 对于内部的三维算法的实现不甚了解. 其 ...

  2. [原创]使用squish打包与混淆cocos2d-x的lua脚本

    squish是一个开源的用于打包lua脚本的小工具,它的主要功能是将多个lua文件整合成一个文件,并在此基础上做压缩和混淆等处理,混淆和压缩后的代码可以直接被执行而不需要先做解压还原等操作. 它的gi ...

  3. visual studio 中使用git

    原文链接:http://my.oschina.net/gal/blog/141442 osc终于全面开放git库了,这是我一直期待的事,也是促使我从CSDN转回OSC社区的重要原因之一.而这次我来教大 ...

  4. poj 1741 Tree(点分治)

    Tree Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15548   Accepted: 5054 Description ...

  5. Android--应用开发2(AndroidManfest.xml)

    AndroidManfest.xml 文件分析 manifest 根节点,描述package中所有内容 xmlns:android 包含命名空间声明.xmlns:android="http: ...

  6. Microsoft Dynamics CRM 数据库连接存储位置在哪里 是在注册表里

    Microsoft Dynamics CRM 数据库连接存储位置是在注册表里

  7. ubuntu 13.04下sublime text 3使用中文输入法

    主要思路参考 http://blog.yanwen.org/archives/1955.html libsublime-imfix.so 这个库自己编译和从他这下载的 md5一样.可以不用编译了.直接 ...

  8. yum cdh4

    cdh4 install for Centos6那个最美的年代,最好的时光,一路梦想,一路流泪,流的不会是懦弱的泪,而是对奋斗的寄于;1,repo配置>>>/etc/yum.repo ...

  9. 关于PCB布线的顺序到底是怎样才合理?

    有人说先布好电源线和地线,让它们尽量靠近走,然后再考虑信号线:也有人说先布好关键的信号线,然后再走电源和地线:还有人说先布好电源线,再布信号线,地线最后布.到底怎么样才算好呢?或者说,一般应按照什么顺 ...

  10. FreeModbus Slave 改进的eMbPoll()【worldsing 笔记】

    eMbPoll()的作用是FreeMod协议通信过程中不断查询事件对列有无完速数据桢,并进行地址和CRD验证,最后运行和回复主机. 为了减小代码尺寸对eMbPoll进行改进: 原版: 1:  2: e ...