A. Array with Odd Sum
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given an array a consisting of n integers.

In one move, you can choose two indices 1≤i,j≤n such that i≠j and set ai:=aj. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace ai with aj).

Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.

You have to answer t independent test cases.

Input
The first line of the input contains one integer t (1≤t≤2000) — the number of test cases.

The next 2t lines describe test cases. The first line of the test case contains one integer n (1≤n≤2000) — the number of elements in a. The second line of the test case contains n integers a1,a2,…,an (1≤ai≤2000), where ai is the i-th element of a.

It is guaranteed that the sum of n over all test cases does not exceed 2000 (∑n≤2000).

Output
For each test case, print the answer on it — “YES” (without quotes) if it is possible to obtain the array with an odd sum of elements, and “NO” otherwise.

题意:给了n个数,现在就是说可以选择两个数让其中一个的值等于另一个的值
这种操作无限次 问是不是能让这n个数操作后的总和为奇数

思路:我们都知道奇数+奇数等于偶数 所以奇数=偶数-奇数 所以只要有奇数有偶数就可以

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define me(a,x) memset(a,x,sizeof a)
#define pb(a) push_back(a)
#define pa pair<int,int>
#define fi first
#define se second

int main()
{
    int t;cin>>t;
    while(t--){

        int n;cin>>n;
        int odd=0,even=0,sum=0;
        for(int i=0,x;i<n;i++){
            cin>>x,sum+=x;
            if(x&1) odd++;
            else even++;
        }
        puts((odd&&even || sum&1)?"YES":"NO");
    }
    return 0;
}

B. Food Buying
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Mishka wants to buy some food in the nearby shop. Initially, he has s burles on his card.

Mishka can perform the following operation any number of times (possibly, zero): choose some positive integer number 1≤x≤s, buy food that costs exactly x burles and obtain ⌊x10⌋ burles as a cashback (in other words, Mishka spends x burles and obtains ⌊x10⌋ back). The operation ⌊ab⌋ means a divided by b rounded down.

It is guaranteed that you can always buy some food that costs x for any possible value of x.

Your task is to say the maximum number of burles Mishka can spend if he buys food optimally.

For example, if Mishka has s=19 burles then the maximum number of burles he can spend is 21. Firstly, he can spend x=10 burles, obtain 1 burle as a cashback. Now he has s=10 burles, so can spend x=10 burles, obtain 1 burle as a cashback and spend it too.

You have to answer t independent test cases.

Input
The first line of the input contains one integer t (1≤t≤104) — the number of test cases.

The next t lines describe test cases. Each test case is given on a separate line and consists of one integer s (1≤s≤109) — the number of burles Mishka initially has.

Output
For each test case print the answer on it — the maximum number of burles Mishka can spend if he buys food optimally.

题意:给了n块钱 每花10块 都能得到一块 问可以当多少钱花

思路:循环。。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define me(a,x) memset(a,x,sizeof a)
#define pb(a) push_back(a)
#define pa pair<int,int>
#define fi first
#define se second
int main()
{
 
    int t;cin>>t;
    while(t--){
    
        int n;cin>>n;
        int sum=n;
        while(n>=10){
 
            int r=n/10;
            sum+=r;
            n=n%10+r;
        }
        cout<<sum<<endl;
 
    }
 
    return 0;
}

C. Yet Another Walking Robot
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
There is a robot on a coordinate plane. Initially, the robot is located at the point (0,0). Its path is described as a string s of length n consisting of characters ‘L’, ‘R’, ‘U’, ‘D’.

Each of these characters corresponds to some move:

‘L’ (left): means that the robot moves from the point (x,y) to the point (x−1,y);
‘R’ (right): means that the robot moves from the point (x,y) to the point (x+1,y);
‘U’ (up): means that the robot moves from the point (x,y) to the point (x,y+1);
‘D’ (down): means that the robot moves from the point (x,y) to the point (x,y−1).
The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn’t want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point (xe,ye), then after optimization (i.e. removing some single substring from s) the robot also ends its path at the point (xe,ye).

This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot’s path such that the endpoint of his path doesn’t change. It is possible that you can’t optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string s).

Recall that the substring of s is such string that can be obtained from s by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of “LURLLR” are “LU”, “LR”, “LURLLR”, “URL”, but not “RR” and “UL”.

You have to answer t independent test cases.

Input
The first line of the input contains one integer t (1≤t≤1000) — the number of test cases.

The next 2t lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer n (1≤n≤2⋅105) — the length of the robot’s path. The second line of the test case contains one string s consisting of n characters ‘L’, ‘R’, ‘U’, ‘D’ — the robot’s path.

It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 (∑n≤2⋅105).

Output
For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot’s path doesn’t change, print -1. Otherwise, print two integers l and r such that 1≤l≤r≤n — endpoints of the substring you remove. The value r−l+1 should be minimum possible. If there are several answers, print any of them.

题意:给长度为n的字符串 让你删去一个区间的坐标 不影响终点 区间越小越好

思路:map标记下走过的点 走过了后面再走到 存下来 排序 输出区间长度最短的就好

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define me(a,x) memset(a,x,sizeof a)
#define pb(a) push_back(a)
#define pa pair<int,int>
#define fi first
#define se second
bool cmp(pa a,pa b){
 
  return a.se-a.fi<b.se-b.fi;
}
int main()
{
 
    int t;cin>>t;
    while(t--){
 
       int n;cin>>n;
       string s;cin>>s;
        map<pa,int> mp;
        int flag=0;
        int x=0,y=0;
        mp[pa(x,y)]=1;
        vector<pa> v;
        for(int i=0;i<n;i++){
 
            if(s[i]=='L') x--;
            if(s[i]=='R') x++;
            if(s[i]=='U') y++;
            if(s[i]=='D') y--;
            if(mp[pa(x,y)]){
 
              v.pb(pa(mp[pa(x,y)],i+1));
 
            }
             mp[pa(x,y)]=i+2;
        }
        if(v.empty()) {puts("-1");continue;}
        sort(v.begin(),v.end(),cmp);
        cout<<v[0].fi<<" "<<v[0].se<<endl;
 
 
    }
 
    return 0;
}

D. Fight with Monsters
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
There are n monsters standing in a row numbered from 1 to n. The i-th monster has hi health points (hp). You have your attack power equal to a hp and your opponent has his attack power equal to b hp.

You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to 0.

The fight with a monster happens in turns.

You hit the monster by a hp. If it is dead after your hit, you gain one point and you both proceed to the next monster.
Your opponent hits the monster by b hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster.
You have some secret technique to force your opponent to skip his turn. You can use this technique at most k times in total (for example, if there are two monsters and k=4, then you can use the technique 2 times on the first monster and 1 time on the second monster, but not 2 times on the first monster and 3 times on the second monster).

Your task is to determine the maximum number of points you can gain if you use the secret technique optimally.

Input
The first line of the input contains four integers n,a,b and k (1≤n≤2⋅105,1≤a,b,k≤109) — the number of monsters, your attack power, the opponent’s attack power and the number of times you can use the secret technique.

The second line of the input contains n integers h1,h2,…,hn (1≤hi≤109), where hi is the health points of the i-th monster.

Output
Print one integer — the maximum number of points you can gain if you use the secret technique optimally.

题意:你和你的对手轮流打怪,对于每只怪 都是你先手 你对手后手
有n个怪,你攻击力a,你对手攻击力b,怪的血hp_i,现在你有k个机会,可以让你对手忽略他出手的回合,就是说你用一次机会 你就能连续打两次 连续用两次次机会就能连续打三次,用的总机会次数小于等于k 现在问最多有多少只怪 只被你终结的 就是你打最后一下让hp_i<=0

思路:简单贪心。。。。
显然 先对hpi取模(a+b) 如果能被整除的话就保留hp_i=a+b 这样操作之后 每一只怪的先手还是你
然后对剩余的血量进行排序 对于hp_i<=a的 你打一下他就gg 那么答案ans++
对于一下子不打死的呢,我们已经按血量排序了 那么肯定把机会优先用掉,
你用k次机会,怪会被k+1次的a的血量
所以我们计算r=hp_i/a 看需要打几次 这里要注意需要看是不是整除
整除的话 需要r–,因为用k次机会 可以连续打k+1下 不能整除就是需要用r次机会刚好

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define me(a,x) memset(a,x,sizeof a)
#define pb(a) push_back(a)
#define pa pair<int,int>
#define fi first
#define se second
bool cmp(pa a,pa b){
 
  return a.se-a.fi<b.se-b.fi;
}
int main()
{
 
    int n,a,b,k;
    cin>>n>>a>>b>>k;
    int c=a+b;
    vector<int> q(n+10);
    for(int i=1;i<=n;i++){
        cin>>q[i];
        q[i]%=c;
        if(!q[i]) q[i]=c;
    }
    sort(q.begin()+1,q.begin()+n+1);
    int ans=0;
    for(int i=1;i<=n;i++){
           // cout<<i<<" "<<q[i]<<endl;
        if(q[i]<=a)  ans++;
        else
        {
            int r=q[i]/a;
            if(q[i]%a==0) r--;
            if(r<=k) k-=r,ans++;
            else break;
        }
    }
    cout<<ans<<endl;
 
 
    return 0;
}

E1. String Coloring (easy version)
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.

You are given a string s consisting of n lowercase Latin letters.

You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in s).

After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.

The goal is to make the string sorted, i.e. all characters should be in alphabetical order.

Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.

Input
The first line of the input contains one integer n (1≤n≤200) — the length of s.

The second line of the input contains the string s consisting of exactly n lowercase Latin letters.

Output
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print “NO” (without quotes) in the first line.

Otherwise, print “YES” in the first line and any correct coloring in the second line (the coloring is the string consisting of n characters, the i-th character should be ‘0’ if the i-th character is colored the first color and ‘1’ otherwise).

题意:让你给题中给定的字符串 的每个字符染色0或者1
然后不同颜色的字符可以交换 问你是不是有一种染色方案 可以让给定的字符串进行任意次交换后是有序的

思路:因为只有两种颜色可以用来涂
相同颜色彼此不能交换
所以同一种颜色组成的序列绝对是非严格递增的
所以只要看是不是能把序列分成两个非严格递增的序列即可
详情看代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define me(a,x) memset(a,x,sizeof a)
#define pb(a) push_back(a)
#define pa pair<int,int>
#define fi first
#define se second
int main()
{
    int n;cin>>n;
    string s;cin>>s;
    vector<int> v(n,0);
    int l='a';
    for(int i=0;i<n;i++)
        if(s[i]>=l) l=s[i],v[i]=1;


    l='a';
    for(int i=0;i<n;i++)
        if(!v[i] && s[i]>=l) l=s[i],v[i]=2;
    for(int i=0;i<n;i++){
        if(!v[i]){
            return puts("NO"),0;
        }
    }
    puts("YES");
    for(int i=0;i<n;i++){
        cout<<v[i]-1;
    }

    return 0;
}

E2
意思和E1一样 只不过可以用不同的颜色,要求用的颜色越少越好
我们由E1知道 要两个非严格递增序列组成即可
那么E2就是看序列能不能由ans个非严格递增序列组成 ans越小越好
那么就一直找即可

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define me(a,x) memset(a,x,sizeof a)
#define pb(a) push_back(a)
#define pa pair<int,int>
#define fi first
#define se second
int main()
{
    int n;cin>>n;
    string s;cin>>s;
    vector<int> v(n,0);
    int ans=1,num=0;
    while(num<n){

        int l='a';
        for(int i=0;i<n;i++)
           if(!v[i] && s[i]>=l) l=s[i],v[i]=ans,num++;
        ans++;
    }

    cout<<ans-1<<endl;
    for(int i=0;i<n;i++) cout<<v[i]<<" ";
    
    return 0;
}

看完如果觉得写的还不错 能看懂 麻烦给个赞 码字不易
有更好的更简单的做法的 也欢迎大佬指教