9/8 small wind - thinking game

A. Reachable Numbers(codeforce1157/A)

The meaning of problems: the role of F (x) is to x + 1, 0 and then after removing the guide (after the guide end of 0 is 0); A

Seeking the number of different F (n); and

Then there is for example 3097: 3097 3,098,309,931,323,334 3,536,373,839,456,789,123

Solution: observation, when n is only one number must be 9 (been circulating);

Then each digit individually out process, there are a different number of bits of each 10-n% 10 (n% 10 when time is not 0, to 0 to continue to engage directly under a);

Note that the first treatment time, if the single-digit 0 is not the time to remove the 0, but to add this n;

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n,ans=0;
    cin>>n;
    if(n%10==0){
        ans++;
        n++;
    }
    while(1){
        if(n<10)break;
        ll x=n%10;
        if(x==0){
            n / = 10 ;
            continues ; 
        } 
        Years + = 10 - x; 
        n = n / 10 + 1 ; 
    } 
    Cout << years + 9 << endl; 


    return  0 ; 
}
View Code

B. Long Number(codeforce1157/B)

The meaning of problems: a string of numbers, can be selected to modify his string of consecutive values ​​ai, ai each number can only be modified after the first maximum value, modify the output;

Solution: From left to right first started looking, can become as high value must be greater than other low value can change;

The first face f (x)> x is changed, it has been changed until f (x) <x;

#include <bits/stdc++.h>
using namespace std;
int num[10];
int main(){
    int n;
    string s;
    cin>>n>>s;
    for(int i=1;i<=9;i++)cin>>num[i];
    int flag=0;
    for(int i=0;i<n;i++){
        int x=s[i]-'0';
        if(!flag){
            if(x<num[x]){
                flag=1;
                s[i]=num[x]+'0';
            }
            else continue;
        }
        else {
            if(x>num[x])break;
            else s[i]=num[x]+'0';
        }
    }
    cout<<s<<endl;

    return 0;
}
View Code

C. Chips Moving(codeforce1213/A)

Question is intended: to the number n, the number of each of the two operations can be performed (many times): Operation 1: x + 2 / x-2, Operation 2: x-1 / x + 1;

1 free operation, operating cost 2 1; seek to make all the numbers are the same minimum cost;

Solution: Direct count the number of odd and even, ans = min (odd, even);

#include <bits/stdc++.h>
using namespace std;
const int maxn=110;
int a[maxn];
int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int cnt1=0,cnt2=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]%2==0)cnt1++;
        else cnt2++;
    }
    cout<<min(cnt1,cnt2)<<endl;
 
 
 
 
    return 0;
}
View Code

D. Bad Prices(codeforces1213/B)

Question is intended: to the number n, the number of days required in bad day, (i.e., from the back, is greater than the number of denominations)

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
int a[maxn];
int main(){
    std::ios::sync_with_stdio(false);
    int T;
    cin>>T;
    while(T--){
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i];
        int ans=0;
        int flag=a[n];
        for(int i=n-1;i>=1;i--){
            if(a[i]>flag)ans++;
            else {
                flag=a[i];
            }
        }
        cout<<ans<<endl;
    }
 
 
 
 
    return 0;
}
View Code

E. Book Reading(codeforces1213/C)

The meaning of problems: To A n, m; 1-n in seeking all be divisible by m and the number of digits;

Solution: m is odd: one cycle every 10, 45 and is; m is an even number: 5 every a cycles, and 20; m is a multiple of 5 Japanese sentence and 10;

n divisible by m, the number in a 1-n are n / m number;

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+10;
int a[maxn];
int main(){
    std::ios::sync_with_stdio(false);
    int T;
    cin>>T;
    while(T--){
        ll n,m;
        cin>>n>>m;
        ll x=n/m;
        ll ans=0LL;
        if(m%10==0){
            cout<<0<<endl;
            continue;
        }
        if(m%5==0){
            if(x%2==0)x/=2LL;
            else x=x/2LL+1LL;
            cout<<x*5LL<<endl;
            continue;
        }
        if(m%2){
            ll y=x%10;
            ans=x/10*45;
            ll k=m;
            for(int i=0;i<y;i++){
                ans+=(k%10);
                k+=m;
            }
        }
        else {
            ll y=x%5;
            ans=x/5LL*20LL;
            ll k=m;
            for(int i=0;i<y;i++){
                ans+=(k%10);
                k+=m;
            }
        }
        cout<<ans<<endl;
 
    }
 
 
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/lin1874/p/11484808.html