码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #579 (Div. 3)

时间:2019-08-16 22:37:04      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:codeforce   def   ==   长度   complete   using   ipa   while   abs   

因为校集训队以cf成绩为分队指标,所以我决定刷刷div3和div2的ABC题(不涉及算法的题),不学习新的算法了,争取把cf分数打上去,这样才能得到尊重。

之前有一场div2我看错A题题意怎么也调不出来,直接自闭了,于是掉了一百多分...赛后补题发现真的不难(上分起码没啥问题)。

反正,现在训练切简单题目的速度和正确率。


早上virtual participate了这场比赛,只AC了三题....(C题竟然没写出来!!!)

补了题现在把题解挂出来。

A.Circle of Students

扫一遍就好了

 

#include<bits/stdc++.h>
using namespace std;
int a[205];
int main()
{
    int q;
    cin>>q;
    while(q--)
    {
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
        cin>>a[i];
        bool f =true;
        for(int i=1;i<=n-1;i++)
        {
            if(a[i+1]-a[i]!=1&&a[i+1]-a[i]!=-1)
            {
                if((a[i+1]==n&&a[i]==1)||(a[i+1]==1&&a[i]==n))continue;
                else
                {
                    cout<<"NO\n";
                    f=false;
                    break;
                }
            }
        }
        if(f)cout<<"YES\n";
        
    }
    return 0;
 } 

B.Equal Rectangles

排序后,最小的乘以最大的就好了,顺便扫的过程中判断一下能不能构成矩形,即相邻的两个是否相等。

#include<bits/stdc++.h>
using namespace std;
int arr[1005];
int main()
{
    int q;
    cin>>q;
    while(q--)
    {
        int n;
        cin>>n;
        for(int i=1;i<=4*n;i++)
        cin>>arr[i];
        sort(arr+1,arr+1+4*n);
        int cnt=arr[1]*arr[4*n];
        bool f=true;
        for(int i=1;i<=2*n;i+=2)
        {
            
            if(arr[i]*arr[4*n+1-i]!=cnt||arr[i]!=arr[i+1]||arr[4*n+1-i]!=arr[4*n-i])
            {
                cout<<"NO\n";
                f=false;
                break;
            }
         }
         if(f)cout<<"YES\n";
         
        
    }
    return 0;
 } 

C.Common Divisors

WDNMD一开始先看错题目,以为是最大的公约数,看了样例半天没想明白。

后来知道是公约数的个数,结果脑子抽到了循环暴力判断???

其实这个就一直gcd迭代下去,再把结果的因子数计算输出就行...(学了一手快速gcd,以后可以当板子了)

ps:记得long long

#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int maxn = 4e5+5;
ll a[maxn];
ll qGCD(ll a, ll b)
{
    if(a == 0) return b;
    if(b == 0) return a;
    if(!(a & 1) && !(b & 1)) // a % 2 == 0 && b % 2 == 0;
        return qGCD(a >> 1, b >> 1) << 1;
    else if(!(b & 1))
        return qGCD(a, b >> 1);
    else if(!(a & 1))
        return qGCD(a >> 1, b);
    else
        return qGCD(abs(a - b), min(a, b));
}

int main()
{
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll g=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        g=qGCD(a[i],g);
    }
    ll cnt = 0;
    for(ll i=sqrt(g);i>=1;i--)
    {
        if(g%i==0)
        {
            if(i*i==g)cnt++;
            else
            cnt+=2;
        }
    }
    cout<<cnt<<\n;
    return 0;
   
}

D1.Remove the Substring (easy version)

数据范围小,所以可以从大到小枚举substring的长度,再从前往后枚举删除的位置,最后暴力判断子序列即可。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    string s,t;
    cin>>s>>t;
    int slen=s.length(),tlen=t.length();
    if(slen==tlen)
    {
        cout<<0<<\n;
        return 0;
    }
    for(int i=slen-tlen-1;i>=0;i--)
    {
        for(int pos=0;pos+i<slen;pos++)
        {
            int p1=0,p2=0;
            while(p1<slen&&p2<tlen)
            {
                if(p1>=pos&&p1<=pos+i)
                {
                    p1++;
                    continue;
                }
                if(s[p1]==t[p2])
                {
                    p1++;
                    p2++;
                }
                else
                {
                    p1++;
                }
            //    cout<<p1<<‘ ‘<<p2<<‘\n‘;
            }
            if(p2==tlen)
            {
                cout<<i+1<<\n;
                return 0;
            }
            else
            continue;
        }
        
    }
    return 0;
    
 } 

D2.Remove the Substring (hard version)

还没出,待会儿补上

E.Boxers

 

先排序,然后搞个now,从1开始循环,判断每个数字是否能够出现。

#include<bits/stdc++.h>
using namespace std;
int arr[150005];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    sort(arr+1,arr+1+n);
    int now=1,cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(now-arr[i]>=-1&&now-arr[i]<=1)
        {
            now++;
            cnt++;
        } 
        else
        {
            if(arr[i]-1>=now)

            {
            now=arr[i];
            cnt++;
            }
        }

    }
    cout<<cnt<<\n;
    
 } 

F1.Complete the Projects (easy version)

F2.Complete the Projects (hard version)

出了补。

 

 

 

 

 

 

over

 

Codeforces Round #579 (Div. 3)

标签:codeforce   def   ==   长度   complete   using   ipa   while   abs   

原文地址:https://www.cnblogs.com/wgqqq/p/11366424.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!