9.21 Codeforces Round #582 (Div. 3)

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/JiangHxin/article/details/101158847

Codeforces Round # 582 (Div 3. ): Click to enter the New World

A. Chips Moving (thinking)

Link to the original question: Portal

Ideas:

  1. N required to give the title chips on a coordinate, moving the grid 2 does not consume the coin, a coin consumption of the mobile frame 1, seeking to minimize consumption of the coin all the chips in the same coordinates.
  2. Since the mobile does not consume the coin cell 2, as 1-3 / 2-4 / 1-5 / 2-6, so only a small value can be calculated both even and odd number of outputs.

    code show as below:
#include<bits/stdc++.h>
#define pi 3.1415926535898
using namespace std;
int main()
{
    int n,x,ans1=0,ans2=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        if(x%2) ans1++;
        else ans2++;
    }
    cout<<min(ans1,ans2);
    return 0;
}


B. Bad Prices (thinking)

Link to the original question: Portal

Ideas:

  1. Given n weights the number of days, there will be the case if the lower value than the right day after day, it was a bad day for several days, bad days seeking in n days.
  2. Wang Qianmian pushed from behind, res larger than any given number of days weight value, if the res <a [i], the worst days ans ++; otherwise, update res = a [i].

AC code is as follows:

#include<bits/stdc++.h>
#define pi 3.1415926535898
using namespace std;
const int manx=150005;
int a[manx];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,ans=0,res=1000005;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        for(int i=n;i>=1;i--){
            if(a[i]>res) ans++;
            res=min(res,a[i]);
        }
        printf("%d\n",ans);
    }
    return 0;
}


C. White Sheet (mathematics)

Link to the original question: Portal

Ideas:

  1. Given n and m, in seeking 1 ~ n m divisible by the number 10 and the mold.
  2. For this problem, the direct simulation is certainly overtime, do not ask me why I know?
  3. In general it is to find the law or recurrence. This question should be used to do recursive, for each divisible must be modulo 10, it is possible to start from the number of times by the first calculated by multiplying 1 to 9 times the contribution of the answer, with d [i] is recorded m * 1 m * i to contribute to the answer.
    (Here is the original contribution of each number from 0 to 9 for the answer, but the answer is 0 or 10 pairs contributions to 0, so do not write it).
  4. M is divisible in the number n have the n / m one, which is n / m in number, there are n / m / 10 m by the number of completed operations from 1 to 10, and the remaining n / m 10% the number of operations done by m from 1 to n / m% 10 a.
  5. Can get the answer to (n / m / 10) * d [9] + d [n / m% 10].

AC code is as follows:

#include<bits/stdc++.h>
#define pi 3.1415926535898
using namespace std;
typedef long long ll;
ll d[10];
int main()
{
    ll n,m;
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n>>m;
        for(int i=1;i<=9;i++) d[i]=(m*i)%10,d[i]+=d[i-1];
        cout<<(n/m/10)*d[9]+d[n/m%10]<<endl;
    }
    return 0;
}


Virtual participate.

Guess you like

Origin blog.csdn.net/JiangHxin/article/details/101158847