20201011 Blue Bridge Training Problem Solution

The questions are all from the dotcpp
bin huge question is difficult ah ah ah

A Concatenated squares

Xiao Ming finds 49 interesting, first of all, it is a square number. It can be split into 4 and 9, and the splits are also squares. 169 also has this property, let's call them: concatenated squares.
100 can be divided into 100, which is a bit reluctant, we stipulate that 0 00 000 and so on are not square numbers.
Xiao Ming thought: What other numbers are like this?
Your task arises: find all concatenated squares of a certain interval.
Input
two positive integers ab (a<b<10^6)
Output
several lines, each line is a positive integer. Indicates the number of concatenated squares in all intervals [a, b]
Sample input
1 200
Sample output
49
169

Ideas: The following points need attention:
1. First of all, the number must be a square number.
2. Just split a number into two numbers! ! ! There will be no case of splitting into more than three numbers
3, so you can enumerate and traverse one by one.

Note that numbers like 9025 are also counted (9 025 is 25)
The following is the AC code

const int maxn=1e6+10;
int a,b;
bool con[maxn];
bool judge(int i){
    
    
    int d=1;
    while(1){
    
    
        int num1=i/d;
        if(num1==0) return false;
        int num2=i%d;
        if(con[num1]&&con[num2]) return true;
        else{
    
    
            d*=10;
        }
    }
}
int main() {
    
    
    cl(con,false);
    rep(i,1,1000) con[i*i]=true;
    sdd(a,b);
    rep(i,a,b){
    
    
        if(con[i]&&judge(i)) printf("%d\n",i);
    }
	return 0;
}

B Synthetic plants

A plantation on planet w is divided into m * n small grids (m rows in the east-west direction and n columns in the north-south direction). A plant with a synaptic root was planted in each cell.
A feature of this plant is that its roots may extend in a north-south or east-west direction, thereby merging with plants in another lattice.
If we tell you which small grids have rooting phenomenon, can you tell how many symbiotic plants there are in this garden?
Input
The first line, two integers m and n, separated by spaces, indicate the number of rows and columns of the grid (1<m,n<1000).
The next line, an integer k, indicates that there are k lines of data below (0<k<100000)
Next k lines, the second line is two integers a, b, indicating the small grid numbered a and the small grid numbered b rooted.

Idea: Consolidate the set, no need to search. And just check it out.
The following is the AC code. Note that the array should be opened to 1e6! ! ! !

const int maxn=1000010;
int n,m,k,cnt;
int pre[maxn];
bool con[maxn];
set<int> st;
inline int id(int i,int j){
    
    
    return m*(i-1)+j;//1开始
}
int find(int x){
    
    
    if(x==pre[x]) return x;
    return pre[x]=find(pre[x]);
}
void join(int a,int b){
    
    
    int fa=find(a),fb=find(b);
    pre[fa]=fb;
}
void init(){
    
    
    rep(i,1,m*n){
    
    
        pre[i]=i;
        con[i]=false;
    }
    st.clear();
}
int main() {
    
    
    sddd(n,m,k);
    init();
    rep(i,1,k){
    
    
        int u,v;
        sdd(u,v);
        join(u,v);
    }
    rep(i,1,n){
    
    
        rep(j,1,m){
    
    
            con[find(id(i,j))]=true;
        }
    }
    int cnt=0;
    rep(i,1,m*n){
    
    
        if(con[i]) cnt++;
    }
    printf("%d\n",cnt);
	return 0;
}

C modify array

Problem Description
Given an array A = [A1, A2, · · · AN] of length N, there may be repeated integers in the array.

Now Xiaoming wants to modify it into an array without repeating integers as follows. Xiao Ming will modify A2, A3, . . . , AN in turn.

When modifying Ai, Xiaoming will check whether Ai has appeared in A1 ∼ Ai−1. If it has appeared, Xiaoming will add 1 to Ai; if the new Ai has appeared before, Xiaoming will continue to add 1 to Ai until Ai has not appeared in A1 ∼ Ai−1.

When AN is also modified as above, obviously there are no repeated integers in the A array. Now given the initial A array, please calculate the final A array

The first line of input
contains an integer N. The second line contains N integers A1,A2,...,AN

Output
Output N integers, followed by the final A1, A2, ··· , AN.

Sample Input
5
2 1 1 3 4
Sample Output
2 1 3 4 5

Idea: Direct simulation will test in person.
Use and check! ! ! I have to use it and check it out! ! !
Below is the key code.

	rep(i,1,1000000) pre[i]=i;
    rep(i,1,n){
    
    
        sd(a[i]);
        int tp=find(a[i]);
        a[i]=tp;
        pre[a[i]]=find(tp+1);
    }

Explanation: first set all pre i to i
and then look at each a[i] to see who the current ancestor is, and then you are the current ancestor
and then let the current one set tp+1 as the ancestor because this has been used .
Pretty ingenious! ! !
I didn't think so, I didn't think so! ! !
Below is the AC code

using namespace std;
const int maxn=1e5+10;
int n;
int a[maxn];
int pre[maxn*10];
int find(int x){
    
    
    if(x==pre[x]) return x;
    return pre[x]=find(pre[x]);
}
int main() {
    
    
    sd(n);
    rep(i,1,1000000) pre[i]=i;
    rep(i,1,n){
    
    
        sd(a[i]);
        int tp=find(a[i]);
        a[i]=tp;
        pre[a[i]]=find(tp+1);
    }
    rep(i,1,n){
    
    
        printf("%d%c",a[i],i==n?'\n':' ');
    }

	return 0;
}

D Compensation

When the enemy's minion enters the range of our defense tower, it will continue to be damaged by the defense tower; of course, our hero can also damage it. When the minion's health drops to 0 or lower, it will be killed. To gain experience, UIM wants to kill the minion himself before the turret kills it.

To simplify things, let's assume this minion has h health points. Minions can be dealt x damage per turret attack, while your hero can deal y damage to minions per attack. Your attack speed is the same as the turret attack speed, so you can choose whether to attack the minion once before the turret attacks the minion for the first time, or after each turret attack, or you can choose not to attack.

Now wondering, given this information, is there a way for the hero to kill this minion?

enter

Each test point consists of multiple sets of data.

Enter the first line, which contains a positive integer T, representing the number of data groups.

The next T lines, each line of three non-negative integers h, x, y, the meaning of which has been given in the topic description.

Output
Outputs T lines. For each set of data, if the minion can be killed at the end, output Yes, otherwise output No

Sample Input
5
100 100 1
100 97 1
100 98 1
100 99 1
100 100 0
Sample Output
No
No
Yes
Yes
No

Ideas:
1. Consider the case of x=0 or y=0 or y>=h, and make a special judgment
2. Otherwise, calculate that the tower needs to be hit m times (if the tower can not be beaten completely, there will be a little left)
3. Then judge Can people play m+1 more times to finish h (directly judge the biggest problem solution that you see from 1 plus inexplicable really is

Below is the AC code:

using namespace std;
int main() {
    
    
    int T;
    sd(T);
    while(T--){
    
    
        ll h,x,y;
        cin>>h>>x>>y;
        if(y==0){
    
    
            printf("No\n");
            continue;
        }else if(x==0||y>=h){
    
    
            printf("Yes\n");
            continue;
        }
        bool flag=false;
        ll num=h/x;
        if(h%x==0) num--;
        if(num*x+(num+1)*y>=h) flag=true;
        if(flag) printf("Yes\n");
        else printf("No\n");
    }
	return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326042396&siteId=291194637