zoukankan      html  css  js  c++  java
  • Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A B C D 水 模拟 构造

    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
    ");
    34      }
    35      else
    36      printf("home
    ");
    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
    ");
    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
    ");
    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
    ");
    24      else
    25         printf("%I64d
    ",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
    ");
    36             return 0;
    37         }
    38     }
    39     printf("%d
    ",be-1);
    40     for(int i=1;i<=n;i++)
    41         printf("%d ",h[a[i]]);
    42     printf("
    ");
    43     for(int i=1;i<be;i++)
    44         printf("%d ",g[i]);
    45     printf("
    ");
    46     return 0;
    47 }
  • 相关阅读:
    TP框架模板中IF Else 如何使用?
    Append 后如何使用 fadein淡入效果
    ThinkPad如何修改fn键默认操作
    TP框架ajax U方法不解析怎么办?
    thinkphp session如何取数组
    FTP服务搭建
    Linux系统学习之字符处理
    如何使用zabbix初级监控
    项目同步部署
    巡检常用命令
  • 原文地址:https://www.cnblogs.com/hsd-/p/6403406.html
Copyright © 2011-2022 走看看