Loading

Nordic Collegiate Programming Contest 2019(的签到题)

比赛链接:https://www.jisuanke.com/contest/8290?view=challenges

A.

You are playing a game in which a group of players take turns saying animal names. The animal name you say when it is your turn must start with the same letter as the previously said animal ends with and it must not have been said previously in this round of the game. If there is no valid name or you cannot come up with one you are eliminated.

Given the last animal name said before your turn and a list of all names not yet used, can you make it through this turn? If so, can you make sure to eliminate the next player?Wikimedia Commons

Input

The first line of input contains a single word, the animal that theprevious player just said. The next line contains a single integer n (0 ≤ n ≤ 10⁵), the number of valid unused animal names. Each of the following n lines contains one valid unused animal name.

All animal names (including the one the previous player said) are unique and consist of at least 1 and at most 20 lower case letters‘a’-‘z’.

Output

If there is any animal name you can play that eliminates the next player, output the first such name from the input list, followed by an exclamation mark. Otherwise, if there is any animal name that you can play, output the first such name. Otherwise, output a question mark (in this case you will just have to make up a fake name in the hope that the others will trust you that this is a real animal).

分类讨论即可。开一个大小为26的cnt数组统计以xx为首字母的单词有几个。

#include <bits/stdc++.h>
using namespace std;
int main()
{
    string last;
    int vis[26]={0};
    int n;
    vector<string>v;
    cin>>last;
    cin>>n;
    int i;
    for(i=0;i<=n-1;i++)
    {
        string temp;
        cin>>temp;
        v.push_back(temp);
        vis[v[i][0]-'a']++;
    }
    bool flag=0;
    string temp_ans="";
    for(i=0;i<=n-1;i++)
    {
        if(v[i][0]==last[last.size()-1])
        {
            flag=1;
            char temp=v[i][v[i].size()-1];
            vis[v[i][0]-'a']--;
            if(temp_ans=="")temp_ans=v[i];
            if(vis[temp-'a']==0)
            {
                cout<<v[i]<<"!";
                return 0;
            }
            vis[v[i][0]-'a']++;
        }
    }
    if(!flag)
    {
        cout<<"?";
    }
    else
    {
        cout<<temp_ans;
    }
}

D.

“Eeny meeny miny moe” is a well-known nursery rhyme inEnglish, used (among other things) by kids to “randomly”select members of a team. It exists in many variations, oneof which goes like this:

Eeny, meeny, miny, moe,

Catch a tiger by the toe.

If he hollers, let him go,

Eeny, meeny, miny, moe.

team.jpg

Similar verses exist in most languages, such as “Ulle dulle dof” in Finnish, “Akka bakka bonka rakka” in Norwegian, and “Ole dole doff” in Swedish.

Two teams are to be selected for a game and the rhyme is used to select one kid for a team at a time, alternating between the two teams, until all kids have been selected. The kids are standing in a circle. In each selection round we start counting the kids in clockwise order around the circle, skipping one kid for every word in the rhyme, until the last word. The kid matching the last word is chosen for the current team and then the next round starts. In all rounds but the first, the counting starts at the next remaining kid (in clockwise order) after the one that was selected in the previous round.

Given such a rhyme, and a group of kids, can you tell which kids will be in which team?

sample1.jpg

Illustration of the first three rounds of Sample Input 1. In rounds 1 and 3, Alvar and Rakel get selected for the first team, and in round 2, Lisa is selected for the second team. In round 4 (not shown), only Kalle remains and is selected for the second team.

Input

The first line of input contains the rhyme, consisting of a list of words separated by spaces. The second line of input contains an integer n (1 ≤ n ≤ 100), the number of kids. Then follow the names of the kids, one per line. The kids are given in clockwise order and the first kid listed is the one at which counting starts in the first round.

All words and names consist only of upper and lower case letters ‘A’-‘Z’ and ‘a’-‘z’. No input line is empty or longer than 100 characters (excluding the newline character at the end of the line).

Output

Output the two teams, starting with the one whose first member is chosen first. For each team, output the number of kids in the team, followed by the names of the kids in the team, in the same order as they were chosen for the team.

输出时每行末尾的多余空格,不影响答案正确性

样例输入1

eeny meeny miny
4
Kalle
Lisa
Alvar Rakel

样例输出1

2
Alvar
Rakel
2
Lisa
Kalle

样例输入2

Every Other
3
a
b
c

样例输出2

2 
b 
c 
1 
a
有点类似约瑟夫环的意思,队列模拟即可。
#include <bits/stdc++.h>
using namespace std;
string s;
vector<string>v1,v2;
queue<string>q;
int n;
int main()
{
    getline(cin,s);
    cin>>n;
    int i,len=0;
    for(i=0;i<s.size();i++)
    {
        if(s[i]==' ')len++;
    }
    len++;
    for(i=1;i<=n;i++)
    {
        string temp;
        cin>>temp;
        q.push(temp);
    }
    int cnt=1;
    while(q.size())
    {
        int i;
        for(i=1;i<=len;i++)
        {
            string temp=q.front();
            q.pop();
            if(i!=len)
            {
                q.push(temp);
            }
            else
            {
                if(cnt&1)v1.push_back(temp);
                else v2.push_back(temp);
            }
        }
        cnt++;
    }
    cout<<v1.size()<<endl;
    for(i=0;i<v1.size();i++)
    {
        cout<<v1[i]<<endl;
    }
    cout<<v2.size()<<endl;
    for(i=0;i<v2.size();i++)
    {
        cout<<v2[i]<<endl;
    }
}

G.

In order to pass time during your vacation, you decided to go on a hike to visit a scenic lake up in the mountains. Hiking to the lake will take you a full day, then you will stay there for a day to rest and enjoy the scenery, and then spend another day hiking home, for a total of three days. However, the accursed weather this summer is ridiculously warm and sunny, and since severe dehydration is not at the top of your priority list you want to schedule the three-day trip during some days where the two hiking days are the least warm. In particular you want to minimize the maximum temperature during the two hiking days.

sun.jpg

Given the current forecast of daily maximum temperatures during your vacation, what are the best days for your trip?

Input

The first line of input contains an integer n (3 ≤ n ≤ 50), the length of your vacation in days. Then follows a line containing n integers t1, t2, …, tn ( − 20 ≤ ti ≤ 40), where ti is the temperature forecast for the ith day of your vacation.

Output

Output two integers d and t, where d is the best day to start your trip, and t is the resulting maximum temperature during the two hiking days. If there are many choices of d that minimize the value of t, then output the smallest such d.

输出时每行末尾的多余空格,不影响答案正确性

样例输入1

5
23 27 31 28 30

样例输出1

2 28

样例输入2

4
30 20 20 30

样例输出2

1 30
纯水
#include <bits/stdc++.h>
using namespace std;
int a[55];
int main()
{
    int n,i;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    int day,mmax=0x3f3f3f3f;
    for(i=2;i<=n-1;i++)
    {
        if(max(a[i-1],a[i+1])<mmax)//不能取等 
        {
            day=i-1;
            mmax=max(a[i-1],a[i+1]);
        }
    }
    cout<<day<<' '<<mmax;
}

 

posted @ 2020-05-01 21:03  脂环  阅读(285)  评论(2编辑  收藏  举报