Contest1802

A. Remove a Progression

Description:

You have a list of numbers from (1) to (n) written from left to right on the blackboard.
You perform an algorithm consisting of several steps (steps are (1)-indexed). On the (i)-th step you wipe the (i)-th number (considering only remaining numbers). You wipe the whole number (not one digit).
When there are less than (i) numbers remaining, you stop your algorithm.
Now you wonder: what is the value of the (x)-th remaining number after the algorithm is stopped?

Input:

The first line contains one integer (T) ((1 le T le 100)) — the number of queries. The next (T) lines contain queries — one per line. All queries are independent.
Each line contains two space-separated integers (n) and (x) ((1 le x < n le 10^{9})) — the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least (x) numbers.

Output

Print (T) integers (one per query) — the values of the (x)-th number after performing the algorithm for the corresponding queries.

Sample Input:

3
3 1
4 2
69 6

Sample Output:

2
4
12

题目链接

AC代码:

#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
 
    int n,x,y;
    scanf("%d",&n);
    for (int i=1;i<=n;i++){
        scanf("%d%d",&y,&x);
        printf("%d
",x*2);
    }
}

B. Yet Another Crosses Problem

Description:

You are given a picture consisting of (n) rows and (m) columns. Rows are numbered from (1) to (n) from the top to the bottom, columns are numbered from (1) to (m) from the left to the right. Each cell is painted either black or white.
You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers (x) and (y), where (1 le x le n) and (1 le y le m), such that all cells in row (x) and all cells in column (y) are painted black.
For examples, each of these pictures contain crosses:
The fourth picture contains 4 crosses: at ((1, 3)), ((1, 5)), ((3, 3)) and ((3, 5)).
Following images don't contain crosses:
You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.
What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?
You are also asked to answer multiple independent queries.

Input:

The first line contains an integer (q) ((1 le q le 5 cdot 10^4)) — the number of queries.
The first line of each query contains two integers (n) and (m) ((1 le n, m le 5 cdot 10^4), (n cdot m le 4 cdot 10^5)) — the number of rows and the number of columns in the picture.
Each of the next (n) lines contains (m) characters — '.' if the cell is painted white and '*' if the cell is painted black.
It is guaranteed that (sum n le 5 cdot 10^4) and (sum n cdot m le 4 cdot 10^5).

Output

Print (q) lines, the (i)-th line should contain a single integer — the answer to the (i)-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.

Sample Input:

Sample Output:

0
0
0
0
0
4
1
1
2

题目链接

AC代码:

#include<bits/stdc++.h>
 
using namespace std;
int a[51000],b[51000],ans;
vector<vector<int> >c;
int main(){
    int T;
    scanf("%d",&T);
    while (T--){
        int n,m;
        ans=0x3f3f3f3f;
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        char s[100000];
        scanf("%d%d",&n,&m);
        c.clear();
        c.resize(n+1);
        for (int i=0;i<n;i++){
            scanf("%s",s);
            c[i].resize(m+1);
            for (int j=0;j<m;j++){
                if (s[j]=='*'){
                    c[i][j]=1;
                }else{
                a[i]++;
                b[j]++;
                }
            }
        }
        for (int i=0;i<n;i++){
            for (int j=0;j<m;j++){
                if (c[i][j]){
                    ans=min(ans,a[i]+b[j]);
                }else{
                    ans=min(ans,a[i]+b[j]-1);
                }
            }
        }
        printf("%d
",ans);
    }
}
 

C. From S To T

Description:

You are given three strings (s), (t) and (p) consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.
During each operation you choose any character from (p), erase it from (p) and insert it into string (s) (you may insert this character anywhere you want: in the beginning of (s), in the end or between any two consecutive characters).
For example, if (p) is aba, and (s) is de, then the following outcomes are possible (the character we erase from (p) and insert into (s) is highlighted):
aba ( ightarrow) ba, de ( ightarrow) ade; aba ( ightarrow) ba, de ( ightarrow) dae; aba ( ightarrow) ba, de ( ightarrow) dea; aba ( ightarrow) aa, de ( ightarrow) bde; aba ( ightarrow) aa, de ( ightarrow) dbe; aba ( ightarrow) aa, de ( ightarrow) deb; aba ( ightarrow) ab, de ( ightarrow) ade; aba ( ightarrow) ab, de ( ightarrow) dae; aba ( ightarrow) ab, de ( ightarrow) dea; Your goal is to perform several (maybe zero) operations so that (s) becomes equal to (t). Please determine whether it is possible.
Note that you have to answer (q) independent queries.

Input:

The first line contains one integer (q) ((1 le q le 100)) — the number of queries. Each query is represented by three consecutive lines.
The first line of each query contains the string (s) ((1 le |s| le 100)) consisting of lowercase Latin letters.
The second line of each query contains the string (t) ((1 le |t| le 100)) consisting of lowercase Latin letters.
The third line of each query contains the string (p) ((1 le |p| le 100)) consisting of lowercase Latin letters.

Output

For each query print YES if it is possible to make (s) equal to (t), and NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

Sample Input:

4
ab
acxb
cax
a
aaaa
aaabbcc
a
aaaa
aabbcc
ab
baaa
aaaaa

Sample Output:

YES
YES
NO
NO

题目链接

AC代码:

#include<bits/stdc++.h>
 
using namespace std;
int l1,l2,l3;
vector<vector<int> >c;
map<char,int>s;
map<char,int>t;
map<char,int>p;
map<char,int>::iterator it;
char ss[100000],tt[100000],pp[100000];
bool check(int l1,int l2)
{
    int i=0,j=0;
    while (i<l1&&j<l2)
    {
        if (ss[i]==tt[j])
        {
            i++;
            j++;
        }
        else
        {
            j++;
        }
    }
    if (i==l1)
    {
        return 1;
    }
    return 0;
}
int main()
{
    int T;
    scanf("%d",&T);
    while (T--)
    {
        scanf("%s",ss);
        scanf("%s",tt);
        scanf("%s",pp);
        s.clear();
        t.clear();
        p.clear();
        l1=strlen(ss);
        l2=strlen(tt);
        l3=strlen(pp);
        for (int i=0; i<l1; i++)
        {
            s[ss[i]]++;
        }
        for (int i=0; i<l2; i++)
        {
            t[tt[i]]++;
        }
        for (int i=0; i<l3; i++)
        {
            p[pp[i]]++;
        }
        if (!check(l1,l2))
        {
            puts("NO");
            continue;
        }
        else
        {
            for (it=t.begin(); it!=t.end(); it++)
            {
                if (!s.count(it->first))
                {
                    s[it->first]=0;
                }
                if (it->second!=s[it->first])
                {
                    int cnt=it->second-s[it->first];
                    if (cnt<0||p[it->first]<cnt)
                    {
                        puts("NO");
                        break;
                    }
                }
            }
            if (it==t.end())
            {
                puts("YES");
            }
        }
 
    }
}

D. 1-2-K Game

Description:

Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.

Input:

The first line contains the single integer T (1 ≤ T ≤ 100) — the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 ≤ n ≤ 109, 3 ≤ k ≤ 109) — the length of the strip and the constant denoting the third move, respectively.

Output

For each game, print Alice if Alice wins this game and Bob otherwise.

Sample Input:

4
0 3
3 3
3 4
4 4

Sample Output:

Bob
Alice
Bob
Alice

题目链接

AC代码:

#include<bits/stdc++.h>
 
using namespace std;
int n,k;
int main()
{
    int T;
    scanf("%d",&T);
    while (T--)
    {
        scanf("%d%d",&n,&k);
        if (k%3==0)
        {
            n=n%(k+1);
            if (n==k)
            {
                puts("Alice");
            }
            else
            {
                if (n%3==0)
                {
                    puts("Bob");
                }
                else
                {
                    puts("Alice");
                }
            }
        }
        else
        {
            if (n%3==0){
                puts("Bob");
            }else{
                puts("Alice");
            }
        }
    }
}
原文地址:https://www.cnblogs.com/Accpted/p/11271563.html