牛客周赛 Round 81【题解未完成 EF】

54 阅读2分钟
题目难度知识点
A 麻将入门签到
B 数数入门签到
C 加法入门★★二分/思维
D 中场撸猫★★贪心/模拟
E 和+和★ ★思维
F 怎么写线性SPJ★★构造

麻将入门

#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    int a,b,c; cin>>a>>b>>c;
    if((a==b&&b==c) || ( a+1==b && b+1==c)) puts("Yes");
    else puts("No");
    return 0;
}

数数入门

#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
int a[N][N],t,n;
int main(void)
{
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=i;j++) cin>>a[i][j];
        int flag=1;
        for(int i=1;i<n;i++)
        {
            for(int j=1;j<=i;j++)
            {
                if(a[i][j]<=a[i+1][j]&&a[i][j]<=a[i+1][j+1]);
                else flag=0;
            }
        }
        if(flag) puts("Yes");
        else puts("No");
    }
    return 0;
}

加法入门

image.png 二分一下所在的区间,左右端点在一层一定可以。 否则如果在相邻层,看上面的变换的位置是不是比下面的没有动的位置少1。这样的话互换也是可以的。

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
int main(void)
{
    LL t; cin>>t;
    while(t--)
    {
        LL n,l,r; cin>>n>>l>>r;
        
        LL l1=1,r1=n;
        while(l1<r1)
        {
            LL mid=(l1+r1+1)/2;
            if(mid*(mid+1)/2>l) r1=mid-1;
            else l1=mid;
        }
        if( (l1*(l1+1)/2)<l ) l1++;
        
        LL l2=1,r2=n;
        while(l2<r2)
        {
            LL mid=(l2+r2+1)/2;
            if(mid*(mid+1)/2>r) r2=mid-1;
            else l2=mid;
        }
        if( (l2*(l2+1)/2)<r ) l2++;
        if(l1==l2) puts("Yes");
        else
        {
            LL temp1=(l1+1)*l1/2-l+1;
            LL temp2=l2-(r-l2*(l2-1)/2);
            if( (l1+1==l2)  && temp1+1<=temp2 ) puts("Yes");
            else puts("No");
        }
    }
    return 0;
}

中场撸猫

image.png 贪心,尽可能的选小的。

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int N=1e3+10;
int a[N][N],n,st[N][N];
int main(void)
{
    LL t; cin>>t;
    while(t--)
    {
       cin>>n;
       for(int i=0;i<n;i++)    
         for(int j=0;j<n;j++)
            cin>>a[i][j],st[i][j]=0;
        for(int i=0;i<n;i++) sort(a[i],a[i]+n);
        int cnt=1;
        st[0][0]=a[0][0];
        for(int i=1;i<n;i++)
        {
            int j=-1;
            while(j+1<n&&a[i][j+1]<st[i-1][0]) j++;
            int l=j+1,r=n-1;

            queue<int>q;
            for(int j=l;j<=r;j++) q.push(a[i][j]);
            vector<int>ans;
            if(q.size())
            {
                int temp=q.front(); q.pop();
                ans.push_back(temp);
            }
            int p=0;
            while(q.size())
            {
                int temp=q.front(); q.pop();
                if(p==(i-1))
                {
                    if(temp>=st[i-1][p]) 
                    {
                        ans.push_back(temp);
                        break;
                    }
                }
                else
                {
                    if(temp>=st[i-1][p]&&temp>=st[i-1][p+1]) 
                    {
                        ans.push_back(temp);
                        p++;
                    }
                }
            }
            if( ans.size() != (i+1) ) break;
            else{
                cnt=i+1;
                for(int j=0;j<=i;j++) st[i][j]=ans[j];
            }
        }
        cout<<cnt<<'\n';
    }
    return 0;
}