码迷,mamicode.com
首页 > Web开发 > 详细

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A B C D 水 模拟 构造

时间:2017-02-15 21:59:46      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:ber   nsis   rac   other   http   ict   term   bae   following   

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.

题意:给你n张机票 包含机票的起点与终点  判断当前是否在家或在外

题解:水

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <stack>
 6 #include <queue>
 7 #include <cmath>
 8 #include <map>
 9 #define ll __int64
10 using namespace  std;
11 int n;
12 char  a[105];
13 char b[105],c[105];
14 int main()
15 {
16      scanf("%d",&n);
17      getchar();
18      scanf("%s",a);
19      int ans=0;
20      for(int i=1;i<=n;i++)
21      {
22          scanf("%s->%s",c);
23          b[0]=c[0];
24          b[1]=c[1];
25          b[2]=c[2];
26          if(strcmp(a,b)==0)
27          {
28               ans++;
29          }
30      }
31      if(n%2!=0||ans!=(n/2))
32      {
33          printf("contest\n");
34      }
35      else
36      printf("home\n");
37     return 0;
38 }

 

 

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
Note

In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program:

  • replace all occurences of number with a, the result would be "a string a character a string a",
  • replace all occurences of string with b, the result would be "a b a character a b a",
  • replace all occurences of character with c, the result would be "a b a c a b a",
  • all identifiers have been replaced, thus the obfuscation is finished.

题意:规定了一种字符串的处理方式 对于遇到的第一个字符用‘a’替换之后出现的相同字符 之后找到下一个未被替换的字符 替换为‘b’ 规则同上

题解:给你一段处理过的字符串 判断是否合法. 直接模拟即可。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <stack>
 6 #include <queue>
 7 #include <cmath>
 8 #include <map>
 9 #define ll __int64
10 using namespace  std;
11 char a[505];
12 map<char,int> mp;
13 int main()
14 {
15     scanf("%s",a);
16     int len=strlen(a);
17     char be=a;
18     mp.clear();
19     for(int i=0;i<len;i++)
20     {
21         if(mp[a[i]]==1)
22             continue;
23         if(a[i]==be)
24         {
25             be++;
26         }
27         else
28         {
29             printf("NO\n");
30             return 0;
31         }
32         for(int j=i;j<len;j++)
33         {
34             if(a[i]==a[j])
35             {
36                 mp[a[i]]=1;
37             }
38         }
39     }
40     printf("YES\n");
41     return 0;
42 }

 

 

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

Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.

Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.

Note that the game consisted of several complete sets.

Input

The first line contains three space-separated integers ka and b (1 ≤ k ≤ 109, 0 ≤ a, b ≤ 109, a + b > 0).

Output

If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.

Examples
input
11 11 5
output
1
input
11 2 3
output
-1
Note

Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.

题意:两人打乒乓球比赛 双方中只要有一人得k分则本局结束  给你a b分别为两人的总得分 问 最多打了多少局比赛 不可能则输出-1

题解:重点是考虑两人对k取余的结果 

若余数不为零 则 对方的获胜场数一定大于零。考虑一下。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <stack>
 6 #include <queue>
 7 #include <cmath>
 8 #include <map>
 9 #define ll __int64
10 using namespace  std;
11 int main()
12 {
13     ll k,a,b;
14      scanf("%I64d %I64d %I64d",&k,&a,&b);
15      ll ans=0,ansa,ansb;
16      ans=a/k;
17      ansa=ans;
18      a=a%k;
19      ans+=(b/k);
20      ansb=b/k;
21      b=b%k;
22      if((ansb==0&&a!=0)||(ansa==0&&b!=0))
23         printf("-1\n");
24      else
25         printf("%I64d\n",ans);
26     return 0;
27 }

 

 

D. Artsem and Saunders
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.

Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.

Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all 技术分享, and h(g(x)) = f(x) for all 技术分享, or determine that finding these is impossible.

Input

The first line contains an integer n (1 ≤ n ≤ 105).

The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).

Output

If there is no answer, print one integer -1.

Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).

If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.

Examples
input
3
1 2 3
output
3
1 2 3
1 2 3
input
3
2 2 2
output
1
1 1 1
2
input
2
2 1
output
-1

 题意:一个没有想出的构造题  给你长度为n的f(x) 构造 序列 g(n) h(m)

使得 m最小并且g(h(x)) = x  技术分享,  h(g(x)) = f(x)技术分享

 题解:

g(h(x))= x

h(g(x)) = f(x)

h(g(h(x)))=f(h(x))

得h(x) = f(h(x))

继而得到f(x) = f(f(x))

h(m)为f(x)去重排序

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <stack>
 6 #include <queue>
 7 #include <cmath>
 8 #include <map>
 9 #define ll __int64
10 using namespace  std;
11 int n;
12 int a[100005];
13 int g[1000006];
14 int h[1000006];
15 int main()
16 {
17     scanf("%d",&n);
18     for(int i=1;i<=n;i++)
19         scanf("%d",&a[i]);
20     int be=1;
21     memset(h,0,sizeof(h));
22     for(int i=1;i<=n;i++)
23     {
24         if(i==a[i])
25         {
26             g[be]=i;
27             h[i]=be;
28             be++;
29         }
30     }
31     for(int i=1;i<=n;i++)
32     {
33         if(h[a[i]]==0)
34         {
35             printf("-1\n");
36             return 0;
37         }
38     }
39     printf("%d\n",be-1);
40     for(int i=1;i<=n;i++)
41         printf("%d ",h[a[i]]);
42     printf("\n");
43     for(int i=1;i<be;i++)
44         printf("%d ",g[i]);
45     printf("\n");
46     return 0;
47 }

 

 

 

 

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A B C D 水 模拟 构造

标签:ber   nsis   rac   other   http   ict   term   bae   following   

原文地址:http://www.cnblogs.com/hsd-/p/6403406.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!