"Reasoning" UVa 10771-barbarian tribes

Source: Internet
Author: User

Barbarian Tribes

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


First, a local guru chooses three numbers at random:N,mandk. Afterwards,NGared Maids (in the positions1, 2,...,N) andmKeka Maids (in the positionsN+ 1,N+ 2,...,N+m) is placed in a circle looking inwards. Then the guru begins to count1, 2,...,kStarting at the first gared maid. When the K -th maid is reached, she's immediately sacrificed to the gods. The Guru then counts again 1, 2,..., K starting at the maid following the one just SACRIFICED.A Gain, the K -th maid reached this is sacrificed. After every, sacrifices,the second sacrificed maid was replaced by a new maid. In order to decide the tribe of the new Maid,the guru looks at the heads of the and maids just killed (nothing else remains of them). If both heads is of the same tribe, the guru calls a gared maid. If the heads is 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 th E new Maidjust added to the circle. Since the number of maids reduces by one after every step (of both sacrifices and one replacement), after n + m -1 steps only one maid remains.


According to the Tradition,the tribe of the last maid would be the favorite of the gods. (What's the Guru does to the last maid was something you don ' t want to know.) Anyway, write a program such that,given n, m and K, writes the name of the Fortunat E tribe.


For example, which is what happens for n = m = 3 and k = 2 (a ' G ' denotes a gared mai D 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 in 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 K).
  5. Content of the Circle:g9 K10
    Starting to count in G9.First sacrifice:k10.Second sacrifice:g9 (replaced by K).
  6. Final content of the Circle:k11

Input

Input consists of zero ore more test cases. Each test case consists of a linewith three positive integers: n, m and K. You can assume 1n + m# 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 24 2 20 1 70 0 0

Sample Output
Kekagaredkeka


Began to think it was Joseph Ring, Tle ... Depressed half a day, and later saw the puzzle suddenly dawned. I still have to strengthen the conversion of thinking ...

The main topic: Give N,m and K, there are n g,m K, standing in a circle, now there is a killer each walk K step, kill the current position of the person, each kill two people if these two people are g or are k, with g, or use K to fill up. Ask the last one who's left.


The idea of solving a problem: in every two people this place to consider. Nothing more than 3 cases: kill two G, more than a G, kill two K, more than a G, kill a G one k, more than one K.

Note that the number of K is not changed when you kill one K and one K, so the number of K will only be reduced by a reduction of 2. If k is an odd number at the beginning, it will never be finished, and eventually the K must be left. If the first is an even number, the final reduction must be k, leaving the G.

Code:

1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5 using namespacestd;6 intMain ()7 {8     intN, M, K;9      while(SCANF ("%d%d%d", &n, &m, &k))Ten     { One         if(!n &&!m &&!k) Break; A         if(m%2) printf ("keka\n"); -         Elseprintf"gared\n"); -     } the     return 0; -}

"Reasoning" UVa 10771-barbarian tribes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.