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");
}
版权声明:加油 加油 加油^-^

Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)A+B

A. Gotta Catch Em’ All!time limit per test:1 secondmemory limit per test:256 megabytesinput:standard...
  • qq_33183401
  • qq_33183401
  • 2017年01月16日 17:12
  • 239

ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) E. The Holmes Children

E. The Holmes Children time limit per test 2 seconds memory limit per test 256 megabytes...
  • mystery_guest
  • mystery_guest
  • 2017年03月04日 18:40
  • 284

Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) A. Gotta Catch Em' All!(水题)

题目链接:http://codeforces.com/contest/757/problem/AA. Gotta Catch Em’ All! time limit per test1 second...
  • qq_32866009
  • qq_32866009
  • 2017年01月13日 09:17
  • 199

【解题报告】Codeforces Round #401 (Div. 2)

简略的解题报告。
  • TRiddle
  • TRiddle
  • 2017年02月25日 17:55
  • 410

Codeforces Round #258 (Div. 2)-(A,B,C,D,E)

A:Game With Sticks 水题。。。每次操作,都会拿走一个横行,一个竖行。 所以一共会操作min(横行,竖行)次。 #include #include #include #include ...
  • rowanhaoa
  • rowanhaoa
  • 2014年07月25日 14:39
  • 1471

Codeforces Round #395 (Div. 2)(ABCD)

ps:打完这场cf才知道自己真的很菜,还是停留在AB题的水平,有时候CD其实很简单,但就是想不到,别人一眼看出而我就是想不到,有时候想到了点子上但就是突破不了 题目链接:  Codeforc...
  • qq_34731703
  • qq_34731703
  • 2017年02月03日 12:50
  • 488

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

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

Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) -- C. Destroying Array (并查集)

大体题意: 给你n 个数字,告诉你破坏每个数字的顺序,每次破坏后你要求一个线段,使得线段不包含破坏的点,并且线段上的值和最大? 思路: 正着删除感觉不好处理,就反过来求了,相当于从一个空序列往上...
  • aozil_yang
  • aozil_yang
  • 2016年10月02日 00:37
  • 372

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

题意: Artsem想买一些纪念品给他的两个队友,现在有n家商店排成一排,每家商店固定出售一个价值的物品,Artsem每次任意选择一个区间的商店,他会在这个区间内选择两家不同的商店,购买这两样纪念品...
  • CRZbulabula
  • CRZbulabula
  • 2017年02月20日 12:17
  • 130

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

A.Neverending competitions#include using namespace std; #define For(i,n) for(int i=1;i
  • nike0good
  • nike0good
  • 2017年02月15日 00:10
  • 154
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
举报原因:
原因补充:

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