Codeforces Round #644 (Div. 3)

题目链接:https://codeforces.com/contest/1360

A.Minimal Square

b站链接:https://www.bilibili.com/video/BV1b54y1D7Ra/

#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=1000;
int main()
{
    #ifdef ONLINE_JUDGE
    #else
        freopen("in.txt","r",stdin);
    #endif
    int n;
    scanf("%d",&n);
    int a,b;
    while(n--)
    {
        scanf("%d%d",&a,&b);
        if(2*a<=b)
            printf("%d\n",b*b);
        else if(2*b<=a)
            printf("%d\n",a*a);
        else{
        int area=min(4*a*a,4*b*b);
        printf("%d\n",area);
        }
    }
    return 0;
}
View Code

 

B.Honest Coach 

b站链接:https://www.bilibili.com/video/BV1D5411s7FE/

//-------------------------------------------------
//Created by HanJinyu
//Created Time :三  5/20 12:29:04 2020
//File Name :question.cpp
//-------------------------------------------------

#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 = 500005;
int a[maxn],tree[4*maxn];
int main()
{
    #ifdef ONLINE_JUDGE
    #else
    freopen("in.txt","r",stdin);
    #endif
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        map<int,int>mp;
        int s[maxn];
        for(int i=0;i<n;i++)
        {
            scanf("%d",s+i);
            mp[s[i]]++;
        }
        bool flag=false;
        for(auto it:mp)
        {
            if(it.second>1)
            {
                flag=true;
                break;
            }
        }
        if(flag)
        {
            printf("0\n");
        }
        else
        {
            sort(s,s+n);
            int b[maxn];
            int ops=0;
            for(int i=1;i<n;i++)
            {
                b[ops++]=abs(s[i]-s[i-1]);
            }
            sort(b,b+n-1);
            printf("%d\n",b[0]);
        }
    }
 
     return 0;
}
View Code

 

C.Similar Pairs

b站链接:https://www.bilibili.com/video/BV1az4y1d77L

#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=3e5+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[100];
        int _J=0,_O=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",a+i);
            if(a[i]&1)
                _J++;
            else
                _O++;
        }
        if(_J%2==0&&_O%2==0)
        {
            printf("YES\n");
        }
        else
        {
            sort(a,a+n);
            bool flag=false;
            for(int i=1;i<n;i++)
            {
               if(abs(a[i]-a[i-1])==1)
               {
                   flag=true;
                   break;
               }
            }
            if(flag)
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
    return 0;
}
View Code

 

D.Buying Shovels

b站链接:https://www.bilibili.com/video/BV1SK4y1t7UT/

//
//  main.cpp
//  CF
//
//  Created by HanJinyu on 2020/5/15.
//  Copyright © 2020 by HanJinyu. 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--)
    {
        ll  n,k;
        scanf("%lld%lld",&n,&k);
        if(k>=n)
            printf("1\n");
        else if(k==1)
            printf("%lld\n",n);
        else
        {
            if(n&1)
            {
                ll b[maxn];
                int ops=0;
                for(int i=1;i<=sqrt(n);i++)
                {
                    if(n%i==0)
                    {
                        b[ops++]=i;
                        b[ops++]=n/i;
                    }
                }
                sort(b,b+ops);
                for(int i=ops-1;i>=0;i--)
                {
                    if(b[i]<=k)
                    {
                        printf("%lld\n",n/b[i]);
                        break;
                    }
                }
            }
            else
            {
                if(n/2<=k)
                    printf("2\n");
                else
                {
                    if(n%k!=0)
                    {
                        ll b[maxn];
                        int ops=0;
                        for(int i=1;i<=sqrt(n);i++)
                        {
                            if(n%i==0)
                            {
                                b[ops++]=i;
                                b[ops++]=n/i;
                            }
                        }
                        sort(b,b+ops);
                        for(int i=ops-1;i>=0;i--)
                        {
                            if(b[i]<=k)
                            {
                                printf("%lld\n",n/b[i]);
                                break;
                            }
                    }
                    }
                    else
                    {
                        printf("%lld\n",n/k);
                    }
                }
            }
        }
    }
    
    return 0;
}
View Code

 

 E. Polygon

b站链接:https://www.bilibili.com/video/av625775165/

//
//  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=sqrt(100000);
int main()
{
    #ifdef ONLINE_JUDGE
    #else
        freopen("in.txt","r",stdin);
    #endif
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        char a[400][400];
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                cin>>a[i][j];
            }
        }
        bool flag=false;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(a[i][j]=='1')
                {
                    if(i==n-1||j==n-1)
                        continue;
                    else if(a[i+1][j]=='1'||a[i][j+1]=='1')
                        continue;
                    else {
                        flag=true;
                        break;
                    }
                }
            }
        }
        if(flag)
            printf("NO\n");
        else
            printf("YES\n");
    }
     return 0;
}
View Code

 

posted @ 2020-05-25 15:37  branna  阅读(239)  评论(0编辑  收藏  举报