Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)

原创 2017年02月17日 20:55:40

A. Neverending competitions

time limit per test:2 seconds

memory limit per test:512 megabytes

input:standard input

output:standard output

There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name “snookah”)! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.

Jinotega’s best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that:
• this list contains all Jinotega’s flights in this year (in arbitrary order),
• Jinotega has only flown from his hometown to a snooker contest and back,
• after each competition Jinotega flies back home (though they may attend a competition in one place several times),
• and finally, at the beginning of the year Jinotega was at home.

Please help them to determine Jinotega’s location!

Input

In the first line of input there is a single integer n: the number of Jinotega’s flights (1 ≤ n ≤ 100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega’s home airport. In the next n lines there is flight information, one flight per line, in form “XXX->YYY”, where “XXX” is the name of departure airport “YYY” is the name of arrival airport. Exactly one of these airports is Jinotega’s home airport.

It is guaranteed that flights information is consistent with the knowledge of Jinotega’s friends, which is described in the main part of the statement.

Output

If Jinotega is now at home, print “home” (without quotes), otherwise print “contest”.

Examples

Input
4
SVO
SVO->CDG
LHR->SVO
SVO->LHR
CDG->SVO

Output
home

Input
3
SVO
SVO->HKT
HKT->SVO
SVO->RAP

Output
contest

Note

In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
题意:给出一系列的行程,问最后在哪?
题解:题意题,从家出发-1,回家+1.判断是否为0即可。
代码:

#include<bits/stdc++.h>
using namespace std;
map<string,int>mp;
int n;
string s,ss,a;
int ans[10000];
int main()
{
    scanf("%d",&n);
    memset(ans,0,sizeof(ans));
    int tot=1;
    cin>>a;
    mp[a]=tot++;
    for(int i=1; i<=n; i++)
    {
        cin>>a;
        s=a.substr(0,3);
        ss=a.substr(5,6);
        if(mp.find(s)==mp.end())
            mp[s]=tot++;
        if(mp.find(ss)==mp.end())
            mp[ss]=tot++;
        ans[mp[s]]--;
        ans[mp[ss]]++;
    }
    if(ans[1]==0)
        cout<<"home"<<endl;
    else cout<<"contest"<<endl;
}

B. Code obfuscation

time limit per test:2 seconds

memory limit per test:512 megabytes

input:standard input

output:standard output

Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That’s why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.

To obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol a, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with b, and so on. Kostya is well-mannered, so he doesn’t use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs.

You are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya’s obfuscation.

Input

In the only line of input there is a string S of lowercase English letters (1 ≤ |S| ≤ 500) — the identifiers of a program with removed whitespace characters.

Output

If this program can be a result of Kostya’s obfuscation, print “YES” (without quotes), otherwise print “NO”.

Examples

Input
abacaba

Output
YES

Input
jinotega

Output
NO
题意:用a代替第一个出现的变量,用b代替第二个出现的变量。。。
问给出的串是否满足。
题解:模拟即可。注意第一个字母必须是a。
代码:

#include<bits/stdc++.h>
using namespace std;
map<char,int>mp;
int n;
string s,ss,a;
int ans[10000];
int main()
{
    char tmp='a';
    cin>>s;
    if(s[0]!='a') return 0*printf("NO\n");
    else
    {
        for(int i=0;i<s.length();i++)
        {
            if(s[i]==tmp)
            {
                tmp++;
                mp[s[i]]=1;
            }
            else if(mp[s[i]]) continue;
            else
            {
                return 0*printf("NO\n");
            }
        }
    }
    return 0*printf("YES\n");
}
版权声明:加油 加油 加油^-^

Codeforces Round #397 (Div. 1 + Div. 2 combined) D. Artsem and Saunders 映射+构造

题意:给出一个函数f(x) 属于[1,x],然后要求确定一个数m,使x属于[1,n],g[x]属于[1,m], x输入[1,m] h[x]属于[1,n], 当存在m时,求m最小时的gx和hx。 映射+...

Editorial Divide by Zero and Codeforces Round #399 (Div. 1+2, combined) (A~F)

CF #399 A题:水题 代码: #include using namespace std; int a[100010]; int main() { int n; cin>>n; for(i...

Codeforces Round #397(Div. 1 + Div. 2 combined)E. Tree Folding【思维+Dfs】dalao们的解法真巧妙系列QAQ

E. Tree Folding time limit per test 2 seconds memory limit per test 512 megabytes input ...

Codeforces Round #397(Div. 1 + Div. 2 combined)B. Code obfuscation【水题】

B. Code obfuscation time limit per test 2 seconds memory limit per test 512 megabytes inp...

Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined)

这把比赛题目不错,然而打得太挫了。。来写一发题解C. Jon Snow and his Favourite Number基本上是暴力模拟,不过排序和异或要写O(1000)O(1000)的。#inclu...

Codeforces Round #397(Div. 1 + Div. 2 combined)C. Table Tennis Game 2【贪心】

C. Table Tennis Game 2 time limit per test 2 seconds memory limit per test 512 megabytes ...

Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) -- B. Bash's Big Day (唯一分解定理)

大体题意: 给你n 个数,让你选出尽可能多的数来,使得gcd(x1,x2,x3,,,xn) != 1; 输出最大数量? 思路: 思路比较偏比较麻烦,参考一下把! gcd不是1的话,说明它们有共...

Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C. Felicity is Coming!组合学+集合

题意:给出n组数,每组gi个数,每个数属于1~m,每个数可以变化但变化前相同的数变化后依然相同,变化前不同的速变化后依然不同,且可能不变,但经过变化后每组的每种数的个数不会变化,求变化的总方案数。 组...

ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)A. A Serial Killer(水题)

题目: A. A Serial Killer time limit per test 2 seconds memory limit per test 256 mega...

ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)A+B

A. A Serial Killertime limit per test:2 secondsmemory limit per test:256 megabytesinput:standard inp...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
举报原因:
原因补充:

(最多只允许输入30个字)