首页 > 其他 > 详细

Codeforces Round #643 (Div. 2)

时间:2020-05-17 14:26:08      阅读:91      评论:0      收藏:0      [点我收藏+]

题目链接:http://codeforces.com/contest/1355

视频题解链接:https://www.bilibili.com/video/BV1GA411q7K1/

A

技术分享图片
//
//  main.cpp
//  CF
//
//  Created by 韩金宇 on 2020/5/15.
//  Copyright © 2020 韩金宇. All rights reserved.
//

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <map>
#include <cstring>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef double db;
typedef long long ll;
int main()
{
#ifdef ONLINE_JUDGE
#else
    freopen("in.txt","r",stdin);
#endif
    int t;
    scanf("%d",&t);
    while(t--){
        char str[100],str1[100];
        ll b;
        scanf("%s",str);
        scanf("%lld",&b);
        int len=strlen(str);
        //cout<<"len="<<len<<endl;
        for(int i=0;i<len;i++)
            str1[i]=str[i];
        ll val=0;
        for(int i=0;i<len;i++)
        {
           ll ten=1;
           for(int j=1;j<=len-i-1;j++)
           {
               ten*=10;
           }
          val+=(str[i]-0)*ten;
        }
       // cout<<"val="<<val<<endl;
        sort(str1,str1+len);
        int maxx=str1[len-1]-0;
        int minn=str1[0]-0;
        ll  res=val+(maxx*minn);
       // cout<<"res="<<res<<endl;
        if(b==1)
            res=val;
        else
        {
        for(ll i=1;i<=b-2;i++)
        {
            if(maxx==0||minn==0)
                break;
            char ss[100];
            sprintf(ss,"%lld",res);
            int lenn=strlen(ss);
            sort(ss,ss+lenn);
            maxx=ss[lenn-1]-0;
            //cout<<"maxx="<<maxx<<endl;
            minn=ss[0]-0;
             //cout<<"minn="<<maxx<<endl;
            res+=(maxx*minn);
        }
        }
        printf("%lld\n",res);
    }
    return 0;
}
View Code

B

技术分享图片
//
//  main.cpp
//  CF
//
//  Created by 韩金宇 on 2020/5/15.
//  Copyright © 2020 韩金宇. All rights reserved.
//

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef double db;
typedef long long ll;
const int maxn=2e5+10;
int main()
{
    #ifdef ONLINE_JUDGE
    #else
        freopen("in.txt","r",stdin);
    #endif
    int T;
    scanf("%d",&T);
    while(T--){
        int n;
        scanf("%d",&n);
        int a[maxn];
        for(int i=0;i<n;i++)
            scanf("%d",a+i);
        sort(a,a+n);
        int ops=0,foo=0,res=0;
        for(int i=0;i<n;i++){
            foo=max(foo,a[i]);
            ops++;
            if(ops==foo){
                res++;
                ops=0;
            }
        }
        printf("%d\n",res);
    }
     return 0;
}
View Code

C

 

D

技术分享图片
//
//  main.cpp
//  CF
//
//  Created by 韩金宇 on 2020/5/15.
//  Copyright © 2020 韩金宇. All rights reserved.
//

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef double db;
typedef long long ll;
const int maxn=2e5+10;
int main()
{
        #ifdef ONLINE_JUDGE
        #else
            freopen("in.txt","r",stdin);
        #endif
    int n,s;
    scanf("%d%d",&n,&s);
    if(n==1&&s!=1)
    {
        printf("YES\n");
        printf("%d\n",s);
        printf("%d\n",s-1);
    }
    else{
    if(s<(n<<1))
        printf("NO\n");
    else
    {
        printf("YES\n");
        if(s%n==0){
            for(int i=0;i<n;i++)
                printf("%d ",s/n);
            printf("\n");
            printf("%d\n",s/n-1);
        }
        else{
        for(int i=0;i<n-1;i++)
            printf("2 ");
        printf("%d\n",s-((n-1)<<1));
        printf("%d\n",s-1);
        }
    }
    }
    return 0;
}
View Code

 

Codeforces Round #643 (Div. 2)

原文:https://www.cnblogs.com/Vampire6/p/12904161.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!