Codeforces Round #748 (Div. 3)(A-D题)

A. Elections
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
The elections in which three candidates participated have recently ended. The first candidate received a votes, the second one received b votes, the third one received c votes. For each candidate, solve the following problem: how many votes should be added to this candidate so that he wins the election (i.e. the number of votes for this candidate was strictly greater than the number of votes for any other candidate)?

Please note that for each candidate it is necessary to solve this problem independently, i.e. the added votes for any candidate do not affect the calculations when getting the answer for the other two candidates.

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

Each test case consists of one line containing three integers a, b, and c (0≤a,b,c≤109).

Output
For each test case, output in a separate line three integers A, B, and C (A,B,C≥0) separated by spaces — the answers to the problem for the first, second, and third candidate, respectively.

Example
inputCopy
5
0 0 0
10 75 15
13 13 17
1000 0 0
0 1000000000 0
outputCopy
1 1 1
66 0 61
5 5 0
0 1001 1001
1000000001 0 1000000001
题意
有三个候选人,每个人有a,b,c张选票,问要增加几张选票才能当选(大于其它人的选票数)。
题解
水题,如果本身票数大于其它两人,输出0。否则,找到两个人中最大票数减去本身票数。

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{

    int t;
    cin>>t;
    while(t--)
    {
        int a,b,c;
        cin>>a>>b>>c;
        if(a>b&&a>c)
        cout<<0<<" ";
       else  cout<<max(b,c)+1-a<<" ";
        if(b>a&&b>c)
        cout<<0<<" ";
         else cout<<max(a,c)+1-b<<" ";
          if(c>b&&c>a)
        cout<<0<<endl;
         else  cout<<max(b,a)+1-c<<endl;
    }
}

B. Make it Divisible by 25
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
It is given a positive integer n. In 1 move, one can select any single digit and remove it (i.e. one selects some position in the number and removes the digit located at this position). The operation cannot be performed if only one digit remains. If the resulting number contains leading zeroes, they are automatically removed.

E.g. if one removes from the number 32925 the 3-rd digit, the resulting number will be 3225. If one removes from the number 20099050 the first digit, the resulting number will be 99050 (the 2 zeroes going next to the first digit are automatically removed).

What is the minimum number of steps to get a number such that it is divisible by 25 and positive? It is guaranteed that, for each n occurring in the input, the answer exists. It is guaranteed that the number n has no leading zeros.

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

Each test case consists of one line containing one integer n (25≤n≤1018). It is guaranteed that, for each n occurring in the input, the answer exists. It is guaranteed that the number n has no leading zeros.

Output
For each test case output on a separate line an integer k (k≥0) — the minimum number of steps to get a number such that it is divisible by 25 and positive.

Example
inputCopy
5
100
71345
3259
50555
2050047
outputCopy
0
3
1
3
2
Note
In the first test case, it is already given a number divisible by 25.

In the second test case, we can remove the digits 1, 3, and 4 to get the number 75.

In the third test case, it’s enough to remove the last digit to get the number 325.

In the fourth test case, we can remove the three last digits to get the number 50.

In the fifth test case, it’s enough to remove the digits 4 and 7.

题意
个你一串数字,每次可以删除一个数字。问最少可以删除几位,是这个数字变成可以被25蒸出的数字。
题解
首先,能被25整除的数字,只能是以00,25,50,75,结尾的数。
那么就可以找到分别以他们为结尾的数的长度。然后通过比较,就可以得到答案。

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long n,s=0,d1,d2,d3,d4,p=0;
        bool h1,h2,j1,j2,k1,k2,l1,l2;
        string a;
        cin>>n;
        if(n%25==0)
            cout<<0<<endl;
        else {
          while(n!=0)
          {
               p=n%10;
              a[s++]=(p+'0');
              n=n/10;
          }
 
 
            d1=d2=d3=d4=0;
             h1=h2=false;
            for(int i=0;i<s;i++)
            {  if(h2)
                    d1++;
                    if(h1&&a[i]=='0')
                    {h2=true;
                    continue;
                    }
 
                if(a[i]=='0')
                    {h1=true;
                    continue;
                    }
 
            }
 
            d1+=2;
            j1=j2=false;
            for(int i=0;i<s;i++)
            { if(j2)
                    d2++; if(j1&&a[i]=='2')
                   { j2=true;
                        continue;}
 
                if(a[i]=='5')
                    {j1=true;
                    continue;}
 
            }
            d2+=2;
            k1=k2=false;
            for(int i=0;i<s;i++)
            {
                 if(k2)
                    d3++; if(k1&&a[i]=='5')
                   { k2=true;continue;}
                   if(a[i]=='0')
                   { k1=true;continue;}
 
 
            }
            d3+=2;
            l1=l2=false;
             for(int i=0;i<s;i++)
            {if(l2)
                    d4++;if(l1&&a[i]=='7')
                    {l2=true;continue;}
                if(a[i]=='5')
                    {l1=true;continue;}
 
 
            }
            d4+=2;
 
            d1=max(d1,d2);
            d1=max(d1,d3);
            d1=max(d1,d4);
 
            cout<<s-d1<<endl;
        }
    }
}

C. Save More Mice
time limit per test4 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
There are one cat, k mice, and one hole on a coordinate line. The cat is located at the point 0, the hole is located at the point n. All mice are located between the cat and the hole: the i-th mouse is located at the point xi (0<xi<n). At each point, many mice can be located.

In one second, the following happens. First, exactly one mouse moves to the right by 1. If the mouse reaches the hole, it hides (i.e. the mouse will not any more move to any point and will not be eaten by the cat). Then (after that the mouse has finished its move) the cat moves to the right by 1. If at the new cat’s position, some mice are located, the cat eats them (they will not be able to move after that). The actions are performed until any mouse hasn’t been hidden or isn’t eaten.

In other words, the first move is made by a mouse. If the mouse has reached the hole, it’s saved. Then the cat makes a move. The cat eats the mice located at the pointed the cat has reached (if the cat has reached the hole, it eats nobody).

Each second, you can select a mouse that will make a move. What is the maximum number of mice that can reach the hole without being eaten?

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

Each test case consists of two lines. The first line contains two integers n and k (2≤n≤109, 1≤k≤4⋅105). The second line contains k integers x1,x2,…xk (1≤xi<n) — the initial coordinates of the mice.

It is guaranteed that the sum of all k given in the input doesn’t exceed 4⋅105.

Output
For each test case output on a separate line an integer m (m≥0) — the maximum number of mice that can reach the hole without being eaten.

Example
inputCopy
3
10 6
8 7 5 4 9 4
2 8
1 1 1 1 1 1 1 1
12 11
1 2 3 4 5 6 7 8 9 10 11
outputCopy
3
1
4
题意
在一个坐标轴上,猫在0点,有k只老鼠分别在xi。老鼠洞在n。众多老鼠中的一只向右移动1,如果到洞里就隐藏,然后猫也向右移动1,猫碰到老鼠就吃掉。最后问有几只老鼠可以进洞。
题解
先对数组降序排序。然后遍历。先让老鼠移动,进洞。然后,让猫移动,。当我要移动的老鼠预报相遇了,就结束遍历。

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{

    int t;
    cin>>t;
    while(t--)
    {
       int n,k,a[400005],s=0,m=0;
       cin>>n>>k;
       for(int i=0;i<k;++i)
       {
           cin>>a[i];
       }
       sort(a,a+k,greater<int>());
       for(int i=0;i<k;++i)
       { if(m>=a[i])
       break;
       else{
          s++;
           m+=(n-a[i]);
       }


       }
       cout<<s<<endl;
    }
}

D1. All are Same
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
This problem is a simplified version of D2, but it has significant differences, so read the whole statement.

Polycarp has an array of n (n is even) integers a1,a2,…,an. Polycarp conceived of a positive integer k. After that, Polycarp began performing the following operations on the array: take an index i (1≤i≤n) and reduce the number ai by k.

After Polycarp performed some (possibly zero) number of such operations, it turned out that all numbers in the array became the same. Find the maximum k at which such a situation is possible, or print −1 if such a number can be arbitrarily large.

Input
The first line contains one integer t (1≤t≤10) — the number of test cases. Then t test cases follow.

Each test case consists of two lines. The first line contains an even integer n (4≤n≤40) (n is even). The second line contains n integers a1,a2,…an (−106≤ai≤106).

It is guaranteed that the sum of all n specified in the given test cases does not exceed 100.

Output
For each test case output on a separate line an integer k (k≥1) — the maximum possible number that Polycarp used in operations on the array, or −1, if such a number can be arbitrarily large.

Example
inputCopy
3
6
1 5 3 1 1 5
8
-1 0 1 -1 0 1 -1 0
4
100 -1000 -1000 -1000
outputCopy
2
1
1100
题意
给一组数,可以任选一个数,对这个数进行减 k.是数组中的数都一样,问k最大是多少。
题解


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值