zoukankan      html  css  js  c++  java
  • Codeforces Round #640 (Div. 4)

    还想着Div 4 能不能ak一下,看来还是菜了。。。

    A. Sum of Round Numbers

    题目大意

    题目意思大概就是给你一个数,把它分解成各个 (n imes 10^x) 相加。

    思路

    对10求余,分别乘以(10^x ; x geq 0),计数共有几个就行了。

    代码

    /*********************
    *@Author:   CKang    *
    *@Language: C++11    *
    *********************/
    #include<bits/stdc++.h>
    #pragma comment(linker, "/STACK:102400000,102400000")
    //#define DEBUG
    #define RI register int
    #define endl "
    "
    
    using namespace std;
    
    typedef long long ll;
    //typedef __int128 lll;
    //const int N=100000+10;
    const int M=100000+10;
    const int MOD=1e9+7;
    const double PI = acos(-1.0);
    const double EXP = 1E-9;
    const int INF = 0x3fffffff;
    const ll LINF = 0x3fffffffffffffff;
    
    inline ll read(){
        long long x=0,f=1;
        char ch=getchar();
        while(ch<'0'||ch>'9'){
            if(ch=='-')
                f=-1;
            ch=getchar();
        }
        while(ch>='0'&&ch<='9'){
            x=(x<<1)+(x<<3)+(ch^48);
            ch=getchar();
        }
        return x*f;
    }
    
    void solve(){
        ll a=read(),ans=0,now=1,anss[5]={0};
        while(a){
            if(a%10){
                anss[ans++]=(a%10*now);
            }
                a/=10;
                now*=10;
    
        }
        cout<<ans<<endl;
        for(int i=0;i<ans;i++){
            cout<<anss[i]<<' ';
        }
        cout<<endl;
        return ;
    }
    
    int main()
    {
    #ifdef DEBUG
        freopen("input.in", "r", stdin);
        //freopen("output.out", "w", stdout)
    #endif
        //cout.tie(0);
        for(ll t=read();t;t--)
            solve();
    #ifdef DEBUG
        printf("Time cost : %lf s
    ",(double)clock()/CLOCKS_PER_SEC);
    #endif
        //cout << "Fuck You !" << endl;
        return 0;
    }
    

    B. Same Parity Summands

    题目大意

    题目意思大概就是给你一个数n,要求你表示为k个正奇数或者是k个正偶数的和

    思路

    分奇偶考虑,奇x偶=偶,奇x奇=奇,偶x偶=偶。
    然后奇数用1填,偶数用2填,注意考虑全部用最小数字的时候和到不了n的情况。

    代码

    /*********************
    *@Author:   CKang    *
    *@Language: C++11    *
    *********************/
    #include<bits/stdc++.h>
    #pragma comment(linker, "/STACK:102400000,102400000")
    //#define DEBUG
    #define RI register int
    #define endl "
    "
    
    using namespace std;
    
    typedef long long ll;
    //typedef __int128 lll;
    //const int N=100000+10;
    const int M=100000+10;
    const int MOD=1e9+7;
    const double PI = acos(-1.0);
    const double EXP = 1E-9;
    const int INF = 0x3fffffff;
    const ll LINF = 0x3fffffffffffffff;
    
    inline ll read(){
        long long x=0,f=1;
        char ch=getchar();
        while(ch<'0'||ch>'9'){
            if(ch=='-')
                f=-1;
            ch=getchar();
        }
        while(ch>='0'&&ch<='9'){
            x=(x<<1)+(x<<3)+(ch^48);
            ch=getchar();
        }
        return x*f;
    }
    
    void solve(){
        ll n=read(),m=0,init=3,st=0;
        if(n<4){
            puts("-1");
            return ;
        }
        else if(n==4){
            puts("2 4 1 3");
            return ;
        }
        else {
            for(int i=n/2*2;i>4;i-=2){
                printf("%d ",i);
            }
            printf("2 4 1 3 ");
            for(int i=5;i<=n;i+=2){
                printf("%d ",i);
            }
            puts("");
        }
        return ;
    }
    
    int main()
    {
    #ifdef DEBUG
        freopen("input.in", "r", stdin);
        //freopen("output.out", "w", stdout)
    #endif
        //cout.tie(0);
        for(ll t=read();t;t--)
            solve();
    #ifdef DEBUG
        printf("Time cost : %lf s
    ",(double)clock()/CLOCKS_PER_SEC);
    #endif
        //cout << "Fuck You !" << endl;
        return 0;
    }
    

    C. K-th Not Divisible by n

    题目大意

    从1开始数找到第k个不能被n整除的数

    思路

    直接观察到从1开始每n个数就有一个数能被n整除,(n-1)个不能被n整除的数,那么就可以知道我们要找的数就是(k/(n-1)*(n)+kmod(n-1))。其实还有一点就是(kmod(n-1)==0)的时候我们要找的是(k/(n-1)*(n)-1)

    代码

    /*********************
    *@Author:   CKang    *
    *@Language: C++11    *
    *********************/
    #include<bits/stdc++.h>
    #pragma comment(linker, "/STACK:102400000,102400000")
    //#define DEBUG
    #define RI register int
    #define endl "
    "
    
    using namespace std;
    
    typedef long long ll;
    //typedef __int128 lll;
    //const int N=100000+10;
    const int M=100000+10;
    const int MOD=1e9+7;
    const double PI = acos(-1.0);
    const double EXP = 1E-9;
    const int INF = 0x3fffffff;
    const ll LINF = 0x3fffffffffffffff;
    
    inline ll read(){
        long long x=0,f=1;
        char ch=getchar();
        while(ch<'0'||ch>'9'){
            if(ch=='-')
                f=-1;
            ch=getchar();
        }
        while(ch>='0'&&ch<='9'){
            x=(x<<1)+(x<<3)+(ch^48);
            ch=getchar();
        }
        return x*f;
    }
    
    void solve(){
        ll n=read(),k=read();
        int a=k/(n-1),b=k%(n-1);
        if(b)
        cout<<a*n+b<<endl;
        else
        cout<<a*n-1<<endl;
        return ;
    }
    
    int main()
    {
    #ifdef DEBUG
        freopen("input.in", "r", stdin);
        //freopen("output.out", "w", stdout)
    #endif
        //cout.tie(0);
        for(ll t=read();t;t--)
            solve();
    #ifdef DEBUG
        printf("Time cost : %lf s
    ",(double)clock()/CLOCKS_PER_SEC);
    #endif
        //cout << "Fuck You !" << endl;
        return 0;
    }
    

    D. Alice, Bob and Candies

    题目大意

    题目意思大概就是A从左边开始拿数字,B从右边开始拿,从A开始轮流进行;拿数字的要求是本次拿到的数字之和大于另一个人上次拿的数字之和的时候停下来,一开始默认两人都是拿了0.

    思路

    模拟了.....

    代码

    /*********************
    *@Author:   CKang    *
    *@Language: C++11    *
    *********************/
    #include<bits/stdc++.h>
    #pragma comment(linker, "/STACK:102400000,102400000")
    //#define DEBUG
    #define RI register int
    #define endl "
    "
    
    using namespace std;
    
    typedef long long ll;
    //typedef __int128 lll;
    //const int N=100000+10;
    const int M=100000+10;
    const int MOD=1e9+7;
    const double PI = acos(-1.0);
    const double EXP = 1E-9;
    const int INF = 0x3fffffff;
    const ll LINF = 0x3fffffffffffffff;
    
    inline ll read(){
        long long x=0,f=1;
        char ch=getchar();
        while(ch<'0'||ch>'9'){
            if(ch=='-')
                f=-1;
            ch=getchar();
        }
        while(ch>='0'&&ch<='9'){
            x=(x<<1)+(x<<3)+(ch^48);
            ch=getchar();
        }
        return x*f;
    }
    
    int num[1005]={0},n;
    
    void init(){
        for(int i=0;i<1005;i++)num[i]=0;
        return ;
    }
    
    void solve(){
        int n=read();
        init();
        int ans=0,a=0,aa=0,b=0,bb=0,l=0,r=n-1,dt=0,dtt=0,mov=0;
        for(int i=0;i<n;i++)num[i]=read();
        while(l<=r){
            if(!mov){
                do {
                    aa+=num[l];
                    l++;
                    if(l>r)break;
                }while(aa<=dt);
                ans++;
                dt=aa;
                a+=aa;
                aa=0;
                mov^=1;
            }
            else {
                do{
                    bb+=num[r];
                    r--;
                    if(l>r)break;
                }while(bb<=dt);
                ans++;
                dt=bb;
                b+=bb;
                bb=0;
                mov^=1;
            }
        }
        cout<<ans<<' '<<a<<' '<<b<<endl;
        return ;
    }
    
    int main()
    {
    #ifdef DEBUG
        freopen("input.in", "r", stdin);
        //freopen("output.out", "w", stdout)
    #endif
        //cout.tie(0);
        for(ll t=read();t;t--)
            solve();
    #ifdef DEBUG
        printf("Time cost : %lf s
    ",(double)clock()/CLOCKS_PER_SEC);
    #endif
        //cout << "Fuck You !" << endl;
        return 0;
    }
    

    E. Special Elements

    题目大意

    题目意思大概就是给你n个数,统计里面有多少个数能表示为这n个数里面长度大于等于2的子串的值。这里子串的值是指子串里面所有数的和

    思路

    因为数据大小关系,来个8000的桶(然而一开始用map爆空间了)

    代码

    /*********************
    *@Author:   CKang    *
    *@Language: C++11    *
    *********************/
    #include<bits/stdc++.h>
    #pragma comment(linker, "/STACK:102400000,102400000")
    //#define DEBUG
    #define RI register int
    #define endl "
    "
    
    using namespace std;
    
    typedef long long ll;
    //typedef __int128 lll;
    //const int N=100000+10;
    const int M=100000+10;
    const int MOD=1e9+7;
    const double PI = acos(-1.0);
    const double EXP = 1E-9;
    const int INF = 0x3fffffff;
    const ll LINF = 0x3fffffffffffffff;
    
    inline ll read(){
        long long x=0,f=1;
        char ch=getchar();
        while(ch<'0'||ch>'9'){
            if(ch=='-')
                f=-1;
            ch=getchar();
        }
        while(ch>='0'&&ch<='9'){
            x=(x<<1)+(x<<3)+(ch^48);
            ch=getchar();
        }
        return x*f;
    }
    
    int nums[8005]={0},has[8005]={0},n;
    void init(){
        for(int i=0;i<8005;i++)has[i]=0;
        return ;
    }
    
    void solve(){
        n=read();
        init();
        for(int i=0;i<n;i++){
            nums[i]=read();
        }
        nums[n]=0;
        for(int len=2;len<=n;len++){
            int sum=0;
            for( int i=0; i<len;i++ )sum+=nums[i];
            if(sum<=n)has[sum]++;
            int l=0,r=len;
            while(l!=n-len){
                sum-=nums[l];
                sum+=nums[r];
                l++;
                r++;
                if(sum<=n)has[sum]++;
            }
        }
        int ans=0;
        for(int i=0;i<n;i++){
            if(has[nums[i]])ans++;
        }
        cout<<ans<<endl;
        return ;
    }
    
    int main()
    {
    #ifdef DEBUG
        freopen("input.in", "r", stdin);
        //freopen("output.out", "w", stdout)
    #endif
        //cout.tie(0);
        for(ll t=read();t;t--)
            solve();
    #ifdef DEBUG
        printf("Time cost : %lf s
    ",(double)clock()/CLOCKS_PER_SEC);
    #endif
        //cout << "Fuck You !" << endl;
        return 0;
    }
    
    

    F. Binary String Reconstruction

    题目大意

    题目意思大概就是定义三种长度为2的字符串(n_0),(n_1),(n_2),分别表示有几个1,比如(00)这里是0个1,(01)(10)是1个1,(11)是两个1。
    给定这三个字符串的个数a,b,c,要求你构造一个长字符串,里面严格包含a个(n_0),b个(n_1),c个(n_2)

    思路

    首先构造1111111和0000000来满足a和c,发现拼起来必有(n_1),于是就对于(n_1)分类

    由于题目保证有解,那么对于(n_1==0)(n_0),(n_2)必有一个为0,则直接构造00000000或者11111

    对于(n_1!=0)时,则找规律构造.....10101010.....模式的字符串,其中左边全填1右边全填0。

    代码

    /*********************
    *@Author:   CKang    *
    *@Language: C++11    *
    *********************/
    #include<bits/stdc++.h>
    #pragma comment(linker, "/STACK:102400000,102400000")
    //#define DEBUG
    #define RI register int
    #define endl "
    "
    
    using namespace std;
    
    typedef long long ll;
    //typedef __int128 lll;
    //const int N=100000+10;
    const int M=100000+10;
    const int MOD=1e9+7;
    const double PI = acos(-1.0);
    const double EXP = 1E-9;
    const int INF = 0x3fffffff;
    const ll LINF = 0x3fffffffffffffff;
    
    inline ll read(){
        long long x=0,f=1;
        char ch=getchar();
        while(ch<'0'||ch>'9'){
            if(ch=='-')
                f=-1;
            ch=getchar();
        }
        while(ch>='0'&&ch<='9'){
            x=(x<<1)+(x<<3)+(ch^48);
            ch=getchar();
        }
        return x*f;
    }
    
    void solve(){
        int a=read(),b=read(),c=read();b--;
        if(b>=0){
    
        for(int i=0;i<c+1;i++)printf("1");
        for(int i=0;i<a+1;i++)printf("0");
        for(int i=0;i<b;i++){
            if(i%2==0){
                printf("1");
            }
            else printf("0");
        }
    
        }
    
        else{
    
            if(c){
                for(int i=0;i<c+1;i++)printf("1");
            }
    
            if(a)
                for(int i=0;i<a+1;i++)printf("0");
        }
    
        printf("
    ");
        return ;
    }
    
    int main()
    {
    #ifdef DEBUG
        freopen("input.in", "r", stdin);
        //freopen("output.out", "w", stdout)
    #endif
        //cout.tie(0);
        for(ll t=read();t;t--)
            solve();
    #ifdef DEBUG
        printf("Time cost : %lf s
    ",(double)clock()/CLOCKS_PER_SEC);
    #endif
        //cout << "Fuck You !" << endl;
        return 0;
    }
    

    G. Special Permutation

    题目大意

    构造全排列,使得相邻的元素之差的绝对值大于等于2且小于等于4

    思路

    首先发现裴烈的长度必大于4,且长度为4时的唯一排列是2 4 1 3(倒过来也行) ,不难发现左边是偶数右边是奇数,那么按照这个扩展下去就是......8 6 2 4 1 3 5 7......就很容易看出规律了

    代码

    /*********************
    *@Author:   CKang    *
    *@Language: C++11    *
    *********************/
    #include<bits/stdc++.h>
    #pragma comment(linker, "/STACK:102400000,102400000")
    //#define DEBUG
    #define RI register int
    #define endl "
    "
    
    using namespace std;
    
    typedef long long ll;
    //typedef __int128 lll;
    //const int N=100000+10;
    const int M=100000+10;
    const int MOD=1e9+7;
    const double PI = acos(-1.0);
    const double EXP = 1E-9;
    const int INF = 0x3fffffff;
    const ll LINF = 0x3fffffffffffffff;
    
    inline ll read(){
        long long x=0,f=1;
        char ch=getchar();
        while(ch<'0'||ch>'9'){
            if(ch=='-')
                f=-1;
            ch=getchar();
        }
        while(ch>='0'&&ch<='9'){
            x=(x<<1)+(x<<3)+(ch^48);
            ch=getchar();
        }
        return x*f;
    }
    
    void solve(){
        ll n=read(),m=0,init=3,st=0;
        if(n<4){
            puts("-1");
            return ;
        }
        else if(n==4){
            puts("2 4 1 3");
            return ;
        }
        else {
            for(int i=n/2*2;i>4;i-=2){
                printf("%d ",i);
            }
            printf("2 4 1 3 ");
            for(int i=5;i<=n;i+=2){
                printf("%d ",i);
            }
            puts("");
        }
        return ;
    }
    
    int main()
    {
    #ifdef DEBUG
        freopen("input.in", "r", stdin);
        //freopen("output.out", "w", stdout)
    #endif
        //cout.tie(0);
        for(ll t=read();t;t--)
            solve();
    #ifdef DEBUG
        printf("Time cost : %lf s
    ",(double)clock()/CLOCKS_PER_SEC);
    #endif
        //cout << "Fuck You !" << endl;
        return 0;
    }
    
  • 相关阅读:
    PLSQL13
    01.Spring引入
    验证码重构
    短信验证码登录思路
    记住我 token保存到数据库
    图形验证码及其重构
    个性化用户认证流程
    01.Spring Security初识,表单认证
    堆和栈的区别
    系统分析与设计第二次作业
  • 原文地址:https://www.cnblogs.com/--ChenShou--/p/12862448.html
Copyright © 2011-2022 走看看