2020 December Contest Bronze problem solution

T1 Do You Know Your ABCs?

Topic Description:

Farmer John's cow is holding a daily rally on the "mooZ" video conference platform. They invented a simple number game to add some fun to the meeting.

Elsie has three positive integers a, B and C (a ≤ B ≤ C). These figures are confidential and she will not disclose them directly to her sister Bessie. She told Bessie seven integers ranging from 1... 109 (not necessarily different), and claimed that this was some sort of arrangement of a, B, C, A+B, B+C, C+A and A+B+C.

Given these seven integers, please help Bessie find A, B and C. It can be proved that the answer is the only one.

Input format (read from terminal / standard input):

Enter a line containing seven space delimited integers.

Output format (output to terminal / standard output):

Outputs A, B, and C, separated by spaces.

Input example:

2 2 11 4 9 7 9

Output example:

2 2 7

Nature of test point:

Test points 2-3 meet C ≤ 50.
Test points 4-10 have no additional restrictions.

Problem solving ideas


\[\forall \text{A,B,C} \in \mathbb{N} \]

So, sort from small to large, and then the smallest two must be one of ABC

Then you need to judge whether the third one is another

Then you will find that if and only if A+B is just equal to the third, then the fourth is C
In other cases, C must be the third.

Simple thinking questions.


die The code was not saved,┭┮﹏┭┮

T2 Daisy Chains

Topic description

Every day, as part of her walk around the farm, the cow Bessie will pass through her favorite grassland, in which there are n flowers (colorful daisies), numbered 1... N (1 ≤ n ≤ 100), arranged in a row. The flower i has pi petals (1 ≤ pi ≤ 1000).
As a budding photographer, Bessie decided to take some pictures of the flowers. Specifically, for each pair of flowers (i,j) satisfying 1 ≤ i ≤ J ≤ N, Bessie will take a picture of all flowers (including i and j) from flower i to flower J.

Later, when Bessie looked at these photos, she noticed that there were "average" flowers in some photos - a flower with exactly P petals, where p is equal to the average number of petals of all the flowers in the photos.

How many of Bessie's photos have average flowers?

Input format (read from terminal / standard input):

The first line of input contains N. The second line contains N space delimited integers p1... pN.

Output format (output to terminal / standard output):

Output the number of photos with average flowers.

Input example:

1 1 2 3

Output example:


Example explanation

Each photo containing only one flower will be included in the answer (there are 4 in this example). In addition, in this example, the photos corresponding to (1,2) and (2,4) with (i,j) also have average flowers.

Problem solving ideas

The amount of data is very small, direct violence simulation.

Similarly, the die code is not saved..

T3 Stuck in a Rut

Topic description

Farmer John recently expanded his farm. From the perspective of cows, the farm is quite infinite! Cows think of the grazing area on the farm as an infinite two-dimensional matrix composed of square squares, each of which has delicious grass (each square is regarded as a square on the chessboard). Farmer John's N cows (1 ≤ N ≤ 50) were initially located in different squares, part towards the north and part towards the East.
Every hour, each cow performs one of the following:

If the grass in her current grid has been eaten by other cows, she will stop.
Finish all the grass in her current square and move one square in the direction she is facing.
After a period of time, a bald track will be left behind each cow.

If two cows move to the same square with grass in one move, they will share the grass in this square and continue to move in the direction they are facing in the next hour.

Ask for the amount of grass each cow eats. Some cows never stop and eat unlimited grass.

Input format (read from terminal / standard input):

The first line of input contains n. The following N lines describe the starting position of a cow, including a character n (indicating facing north) or E (indicating facing east), and two non negative integers x and Y (0 ≤ x ≤ 109, 0 ≤ y ≤ 109) indicating the coordinates of the grid. All x coordinates are different and all y coordinates are different.
In order to make the direction and coordinates as clear as possible, if a cow is in the grid (x,y) and moves north, she will reach the grid (x,y+1). If she moves East, she will reach the grid (x+1,y).

Output format (output to terminal / standard output):

Output N rows. Line i of the output contains the number of squares of grass eaten by the ith cow in the input. If a cow can eat unlimited grass, output "Infinity" for the cow.

Input example:

E 3 5
N 5 3
E 4 6
E 10 4
N 11 2
N 8 1

Output example:


Nature of test point:

In test points 2-5, all coordinates shall not exceed 100.
There are no additional restrictions on test points 6-10.

Problem solving ideas

To tell you the truth, it's really a good question.

After a long time, my personal idea is to save all the points that may meet, and then screen them one by one.

When filtering, you should note that you can't use only a book array to record which point has stopped, but you should continue to record how much the point has moved. Next time, if the movement doesn't reach the place where it should meet, pass.

Konjac die code

#include <bits/stdc++.h>
#define pb push_back
using namespace std;
template <typename T>inline void read(T& t){
    t=0; register char ch=getchar();
    while(!('0'<=ch&&ch<='9')){if(ch=='-') t=-1;ch=getchar();}
    while(('0'<=ch&&ch<='9')){t=((t<<1)+(t<<3))+ch-'0'; ch=getchar();}
template <typename T,typename... Args> inline void read(T& t, Args&... args){
template <typename T>inline void write(T x){
    if(x<0) putchar('-'),x=~(x-1); int s[40],top=0;
    while(x) s[++top]=x%10,x/=10; if(!top) s[++top]=0;
    while(top) putchar(s[top--]+'0');
int n;
int dis[114514];
vector<pair<int,pair<int,int> > >Up,Right;
struct Meet{
    int x,y,lt,rt,mint;
    bool w;
    int ai,bi;
    bool operator < (const Meet &MeEt) const{
        return mint<MeEt.mint;
    void print(){
        cout<<lt<<' '<<rt<<' '<<mint<<' '<<w<<' '<<ai<<' '<<bi<<endl;;
bool book[114514];
int boko[114514];
int main(){
    for(int i=1;i<=n;++i){
        char ch;
        int x,y;
    for(int i=0;i<Right.size();++i)
        for(int j=0;j<Up.size();++j){
            #define x first
            #define y second.first
            #define idx second.second
            if(Right[i].x>Up[j].x||Right[i].y<Up[j].y) continue;
            int bx=Up[j].x,by=Right[i].y;
            #undef x
            #undef y
            #undef idx
    for(int i=0;i<meet.size();++i){
            //If one of the two has been touched before
            if(book[meet[i].ai]&&boko[meet[i].ai]/*Maximum distance to the right*/<meet[i].x/*Than the distance I met*/) continue;
            if(book[meet[i].bi]&&boko[meet[i].bi]/*Maximum distance up*/<meet[i].y/*Than the distance I met*/) continue;
           //There is a problem with the judgment here, that is to say, even if I touch one, the grass will still be eaten. At that time, it is difficult to do it
           //What I should save a book is, if I stop, where do I eat the grass, not whether it has been touched
           //After the bo ok is saved, you just need to judge whether my touched point has reached that position.
        if(meet[i].lt==meet[i].rt) continue;
            boko[meet[i].bi]=meet[i].y;//Now I'm going up, and now I can only go to meet[i].y.
            boko[meet[i].ai]=meet[i].x;//Now I'm going up, and now I can only go to meet[i].y.
    for(int i=1;i<=n;++i) if(dis[i]==0x3f3f3f3f) cout<<"Infinity"<<'\n';
    else cout<<dis[i]<<'\n';
    return 0;


Posted on Fri, 03 Dec 2021 09:37:32 -0500 by livepjam