Codeforces 914B Conan and Agasa play a Card Game

龍威昊發表於2019-05-13

Conan and Agasa play a Card Game

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

Problem Description

Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has n cards, and the i-th card has a number ai written on it.

They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he removes all cards having a number strictly lesser than the number on the chosen card. Formally, if the player chooses the i-th card, he removes that card and removes the j-th card for all j such that aj < ai.

A player loses if he cannot make a move on his turn, that is, he loses if there are no cards left. Predict the outcome of the game, assuming both players play optimally.

Input

The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of cards Conan has.

The next line contains n integers a1, a2, …, an (1 ≤ ai ≤ 10^5), where ai is the number on the i-th card.

Output

If Conan wins, print “Conan” (without quotes), otherwise print “Agasa” (without quotes).

Sample Input

3
4 5 7
2
1 1

Sample Output

Conan
Agasa


http://codeforces.com/contest…


Accepted Code

// Author : Weihao Long
// Created : 2018/01/21

#include <bits/stdc++.h>

using namespace std;

const int maxn = 100007;

int card[maxn];

bool cmp(int a, int b) {
    return a > b;
}

int main() {
    int n;
    cin >> n;
    int value;
    for (int i = 0; i < n; i++) {
        cin >> value;
        card[value]++;
    }
    bool flag = false;
    sort(card, card + maxn, cmp);
    for (int i = 0; i < n; i++) {
        if (card[i] % 2) {
            flag = true;
            break;
        }
    }
    if (flag)
        cout << "Conan" << endl;
    else
        cout << "Agasa" << endl;
    return 0;
}

Notes

題意:
有 n 張卡牌,每張牌上都有一個數字。柯南和博士輪流操作:“選取一張牌,把牌面數字小於此牌的所有卡牌丟棄,然後把這張卡牌也丟棄”。到最後誰不能操作誰就輸了。柯南先手。

思路:
統計各數字出現的次數,如果有奇數次的則柯南贏,否則博士贏。

相關文章