Codeforces Round #346(Div.2) 문제 해결 보고서

15943 단어 codeforces
659A. Round House
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance a and he decided that during his walk he will move around the house b entrances in the direction of increasing numbers (in this order entrance n should be followed by entrance 1). The negative value of b corresponds to moving |b| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance n). If b = 0, then Vasya prefers to walk beside his entrance. Help Vasya to determine the number of the entrance, near which he will be at the end of his walk.
Input The single line of the input contains three space-separated integers n, a and b (1 ≤ n ≤ 100, 1 ≤ a ≤ n,  - 100 ≤ b ≤ 100) — the number of entrances at Vasya’s place, the number of his entrance and the length of his walk, respectively.
Output Print a single integer k (1 ≤ k ≤ n) — the number of the entrance where Vasya will be at the end of his walk.
input 6 2 -5 output 3 input 5 1 3 output 4 input 3 2 7 output 3
제목 링크: cf-659A
제목의 대의: n개수는 작은 것부터 큰 것까지 순환을 이루고 한 사람의 시작 위치는 a이다. b보를 걷는다. 만약에 b가 플러스라면 숫자가 커지는 곳으로 가고 반대로 점수가 작은 곳으로 간다.
다음은 코드입니다.
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int n,a,b;
    cin >> n >> a >> b;
    if(b > 0)
    {
        int ans = (a + b) % n;
        if (ans == 0) ans = n;
        cout << ans << endl;
    }
    else
    {
        b = abs(b) % n;
        if (b == 0) b = n;
        if (a > b)
        {

            cout << (a - b) << endl;
        }
        else
        {
            cout << n - (b - a)<< endl;
        }
    }
    return 0;
}

659B. Qualifying Contest
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.
The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.
Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
Input The first line of the input contains two integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 10 000, n ≥ 2m) — the number of participants of the qualifying contest and the number of regions in Berland.
Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive).
It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
Output Print m lines. On the i-th line print the team of the i-th region — the surnames of the two team members in an arbitrary order, or a single character “?” (without the quotes) if you need to spend further qualifying contests in the region.
input 5 2 Ivanov 1 763 Andreev 2 800 Petrov 1 595 Sidorov 1 790 Semenov 2 503 output Sidorov Ivanov Andreev Semenov input 5 2 Ivanov 1 800 Andreev 2 763 Petrov 1 800 Sidorov 1 800 Semenov 2 503 output ? Andreev Semenov
제목 링크: cf-659B
제목 대의: n명, m개 구역.n 개인의 성명(보증이 같지 않음), 속하는 구역, 소득 점수를 제시한다.각 구역에서 성적이 가장 좋은 두 사람을 뽑아 경기에 참가시켜 두 사람의 이름을 출력한다.만약 세 번째 사람의 성적이 두 번째 사람의 성적과 같다면'?'를 출력한다.결과가 불확실하다는 것을 보증하다.
제목 사고방식:vector를 이용하여 각 구역의 사람들을 각각 잘 저장한다.비교
다음은 코드입니다.
#include <bits/stdc++.h>
using namespace std;
struct node
{
    int score;
    string name;
};
vector <node> vec[100005];
bool cmp(node a,node b)
{
    return a.score > b.score;
}
int main()
{
    int n,m;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        node tmp;
        int no;
        cin >> tmp.name >> no >> tmp.score;
        vec[no].push_back(tmp);
    }

    for (int i = 1; i <= m; i++)
    {
        sort(vec[i].begin(),vec[i].end() , cmp);
        if(vec[i].size() == 1)
        {
            cout << "?" << endl;
        }
        else if (vec[i].size() == 2)
        {
            node one = vec[i][0];
            node two = vec[i][1];
            cout << one.name << " " << two.name << endl;
        }
        else
        {
            node one = vec[i][0];
            node two = vec[i][1];
            node three = vec[i][2];
            if (three.score == two.score) cout << "?" << endl;
            else cout << one.name << " " << two.name << endl;
        }
    }
    return 0;
}

659C. Tanya and Toys
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the i-th type costs i bourles.
Tania has managed to collect n different types of toys a1, a2, …, an from the new collection. Today is Tanya’s birthday, and her mother decided to spend no more than m bourles on the gift to the daughter. Tanya will choose several different types of toys from the new collection as a gift. Of course, she does not want to get a type of toy which she already has.
Tanya wants to have as many distinct types of toys in her collection as possible as the result. The new collection is too diverse, and Tanya is too little, so she asks you to help her in this.
Input The first line contains two integers n (1 ≤ n ≤ 100 000) and m (1 ≤ m ≤ 109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys.
The next line contains n distinct integers a1, a2, …, an (1 ≤ ai ≤ 109) — the types of toys that Tanya already has.
Output In the first line print a single integer k — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed m.
In the second line print k distinct space-separated integers t1, t2, …, tk (1 ≤ ti ≤ 109) — the types of toys that Tanya should choose.
If there are multiple answers, you may print any of them. Values of ti can be printed in any order.
input 3 7 1 3 4 output 2 2 5 input 4 14 4 6 12 8 output 4 7 2 3 1
제목 링크: cf-659C
제목: 총 10^9종의 선물이 있는데 가격은 1~10^9입니다. 여자는 이미 n종이 있습니다. 엄마는 m원으로 여자에게 선물을 사주겠다고 약속했습니다. 여자는 가능한 한 많은 선물을 원합니다. 이미 있는 것은 필요 없고 최대 몇 개를 사냐고 물었습니다.
제목 사고방식: 오랫동안 최적화를 생각하다가 직접 폭력을 발견하면 된다.
다음은 코드입니다.
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int a[100005];
map <int,int> mp;
vector <int> ans;
int main()
{
    int n,m;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        mp[a[i]] = 1;
    }
    for (int i = 1;; i++)
    {
        if (m < i) break;
        if (mp[i] == 0)
        {
            ans.push_back(i);
            m -= i;
        }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
    {
        cout << ans[i] << " ";
    }
    return 0;
}

659D. Bicycle Race
Maria participates in a bicycle race.
The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west.
Let’s introduce a system of coordinates, directing the Ox axis from west to east, and the Oy axis from south to north. As a starting position of the race the southernmost point of the track is selected (and if there are several such points, the most western among them). The participants start the race, moving to the north. At all straight sections of the track, the participants travel in one of the four directions (north, south, east or west) and change the direction of movement only in bends between the straight sections. The participants, of course, never turn back, that is, they do not change the direction of movement from north to south or from east to west (or vice versa).
Maria is still young, so she does not feel confident at some turns. Namely, Maria feels insecure if at a failed or untimely turn, she gets into the water. In other words, Maria considers the turn dangerous if she immediately gets into the water if it is ignored.
Help Maria get ready for the competition — determine the number of dangerous turns on the track.
Input The first line of the input contains an integer n (4 ≤ n ≤ 1000) — the number of straight sections of the track.
The following (n + 1)-th line contains pairs of integers (xi, yi) ( - 10 000 ≤ xi, yi ≤ 10 000). The first of these points is the starting position. The i-th straight section of the track begins at the point (xi, yi) and ends at the point (xi + 1, yi + 1).
It is guaranteed that:
the first straight section is directed to the north; the southernmost (and if there are several, then the most western of among them) point of the track is the first point; the last point coincides with the first one (i.e., the start position); any pair of straight sections of the track has no shared points (except for the neighboring ones, they share exactly one point); no pair of points (except for the first and last one) is the same; no two adjacent straight sections are directed in the same direction or in opposite directions. Output Print a single integer — the number of dangerous turns on the track.
input 6 0 0 0 1 1 1 1 2 2 2 2 0 0 0 output 1 input 16 1 1 1 5 3 5 3 7 2 7 2 9 6 9 6 7 5 7 5 3 4 3 4 4 3 4 3 2 5 2 5 1 1 1 output 6
제목 링크: cf-659D
제목 사고방식: 알 수 있듯이 오목점이 떨어진다.처음에 직사각형으로 가정하면 매번 오목하거나 튀어나올 때마다 반드시 4개의 점이 증가하고 두 개의 튀어나온 점과 두 개의 오목점이 증가한다.그래서 정답은 (n-4)/2입니다.
다음은 코드입니다.
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    cout << (n - 4) / 2 << endl;
    return 0;
}

좋은 웹페이지 즐겨찾기