Codeforces Round #643 (Div. 2)

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

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

A.Sequence with Digits

View Code

B.Young Explorers

//
//  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.Count Triangles

 

//
//  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
    ll a,b,c,d;
    while(~scanf("%lld%lld%lld%lld",&a,&b,&c,&d)){
        ll z=a+b,y=b+c;
        if(z<c+1)
            z=c+1;
        ll sum=0;
        for(ll i=z;i<=y;i++)
        {
            ll yminn=i-a;
            ll xminn=i-b;
            if(yminn>c)
                yminn=c;
            if(xminn>b)
                xminn=b;
            xminn=i-xminn;
            ll num=min(d-c+1,i-c);
            sum+=(yminn-xminn+1)*num;
        }
        printf("%lld\n",sum);
    }
    return 0;
}
//1 2 3 4
//1 2 2 5
//500000 500000 500000 500000
View Code

 

D.Game With Array

//
//  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

 

posted @ 2020-05-17 13:11  branna  阅读(124)  评论(0编辑  收藏  举报