Nebius Welcome Round (Div. 1 + Div. 2) 题解

A. Lame King

没啥好说的,先穿插着走,在直走

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fer(i,a,b) for(int i=a;i<=b;++i)
#define der(i,a,b) for(int i=a;i>=b;--i)
#define all(x) (x).begin(),(x).end()
#define pll pair<int,int>
#define et  cout<<'\n'
#define xx first
#define yy second
using namespace std;
template <typename _Tp>void input(_Tp &x){
    char ch(getchar());bool f(false);while(!isdigit(ch))f|=ch==45,ch=getchar();
    x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar();
    if(f)x=-x;
}
template <typename _Tp,typename... Args>void input(_Tp &t,Args &...args){input(t);input(args...);}     
const int N=1e6+10; 
signed main()
{
    int T;
    cin>>T;
    while(T--){
        int a,b;
        cin>>a>>b;
        a=abs(a);
        b=abs(b);
        if(a<b){
            swap(a,b);
        }
   
        cout<<b*2+max(0ll,(a-b)*2-1)<<endl;
    }
}

B. Vaccination

用一个队列存病人

原则就是,拖到最晚开一瓶药,开了之后尽量用没

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fer(i,a,b) for(int i=a;i<=b;++i)
#define der(i,a,b) for(int i=a;i>=b;--i)
#define all(x) (x).begin(),(x).end()
#define pll pair<int,int>
#define et  cout<<'\n'
#define xx first
#define yy second
using namespace std;
template <typename _Tp>void input(_Tp &x){
    char ch(getchar());bool f(false);while(!isdigit(ch))f|=ch==45,ch=getchar();
    x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar();
    if(f)x=-x;
}
template <typename _Tp,typename... Args>void input(_Tp &t,Args &...args){input(t);input(args...);}     
const int N=1e6+10; 
int a[N];
struct node{
    int canuse;
    int time;
};
signed main()
{
    int T;
    cin>>T;
    while(T--){
        int n,w,t1,tn;
        queue<int> br;
        cin>>n>>w>>t1>>tn;
        fer(i,1,n){
            cin>>a[i];
            br.push(a[i]);
        }
        int res=0;
 
        while(br.size()){
            auto noww=w;
            auto nowt=br.front()+t1+tn;
            while(noww&&nowt>=br.front()&&br.size()){
                noww--;
                br.pop();
            }
            res++;
        }
 
 
        
        
        cout<<res<<'\n';
 
    }
}

C. Pull Your Luck

等差数列求和,如果超出循环节还没有解就是No

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fer(i,a,b) for(int i=a;i<=b;++i)
#define der(i,a,b) for(int i=a;i>=b;--i)
#define all(x) (x).begin(),(x).end()
#define pll pair<int,int>
#define et  cout<<'\n'
#define xx first
#define yy second
using namespace std;
template <typename _Tp>void input(_Tp &x){
    char ch(getchar());bool f(false);while(!isdigit(ch))f|=ch==45,ch=getchar();
    x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar();
    if(f)x=-x;
}
template <typename _Tp,typename... Args>void input(_Tp &t,Args &...args){input(t);input(args...);}     
const int N=1e6+10; 
const int MX=1e6;
using namespace std;
const int mod=998244353;
int T;
int n,x,p;
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin>>T;
    while(T--){
        cin>>n>>x>>p;
        int now=1;
        int fl=0;
        while(1)
        {
            if(now>p){
                fl=0;
                break;
            }
            if(now>3*n){
                fl=0;
                break;
            }
            if(!((x+now*(now+1)/2%n)%n))
            {
                cout<<"Yes\n";
                fl=1;
                break;
            }
            now++;
        }
        if(!fl) cout<<"No\n";
    }
    return 0;
}

D. Accommodation

最少就是把所有连续的1都贪心成两室一厅

最多就是把把所有连续的0都贪心成两室一厅

注意不要超过限制(m/4,m/2)

(赛后被fst了,循环应该循环到m-1,没注意写成m了,出题人用*造数据)

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fer(i,a,b) for(int i=a;i<=b;++i)
#define der(i,a,b) for(int i=a;i>=b;--i)
#define all(x) (x).begin(),(x).end()
#define pll pair<int,int>
#define et  cout<<'\n'
#define xx first
#define yy second
using namespace std;
template <typename _Tp>void input(_Tp &x){
    char ch(getchar());bool f(false);while(!isdigit(ch))f|=ch==45,ch=getchar();
    x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar();
    if(f)x=-x;
}
template <typename _Tp,typename... Args>void input(_Tp &t,Args &...args){input(t);input(args...);}     
using namespace std;
const int N=1e6+10;
string s;
int n,m,tmp;
int vis[N];
int calc1()
{
    int res=0;
    int cnt=0;
    fer(i,1,m){
        if(s[i]=='1') cnt++;
        else
        {
            res+=cnt/2;
            cnt=0;
        }
    }
    res+=cnt/2;
    if(res>m/4){
        res=m/4;
    }
    res=tmp-res;
    return res;
}
int calc2()
{
    int res=0;
    int cnt=0;
    cnt=tmp;
    fer(i,1,m-1){
        if(s[i]=='0'||s[i+1]=='0')
        {
            if(!vis[i]&&!vis[i+1]){
                vis[i]=1;
                vis[i+1]=1;
                res+=1;
            }
        }
    }
    int dis=min(m/4,res);
    res=m/4-dis;
    return cnt-res;
}
 
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    int ans1=0;
    int ans2=0;
    fer(i,1,n){
        cin>>s;
        s='0'+s;
        tmp=0;
        for(auto t:s){
            if(t=='1'){
                tmp++;
            }
        }
        fer(j,1,m){
            vis[j]=0;
        }
        ans1+=calc1();
        ans2+=calc2();
    }
    cout<<ans1<<" "<<ans2<<'\n';
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值