• Codeforces Round 857


    Portal.

    A. Likes

    Portal.

    赛时代码:

    #include 
    using namespace std;
    #define int long long
    
    const int maxn=1e5+5;
    int b[maxn],n,cnt1,cnt2;
    bool qwq[maxn];
    
    //b数组无序 
    
    signed main()
    {
    	int t;cin>>t;
    	while(t--)
    	{
    		cin>>n;
    		memset(b,0,sizeof(b));cnt1=0;cnt2=0;
    		for(int i=1;i<=n;i++) 
    		{
    			cin>>b[i];
    			if(b[i]>0) cnt1++;
    			else cnt2++;
    		}
    		int tmp=cnt1;
    		for(int i=1;i<=n;i++)
    		{
    			if(i<=cnt1) cout<<i<<' ';
    			else tmp--,cout<<tmp<<' '; 
    		}
    		cout<<endl;
    	//	int tmp=abs(cnt1-cnt2);
    		for(int i=1;i<=n;i++)
    		{
    			if(i%2==1&&i<min(cnt1,cnt2)*2) cout<<1<<' ';
    			else if(i%2==0&&i<=min(cnt1,cnt2)*2) cout<<0<<' ';
    			else cout<<i-min(cnt1,cnt2)*2<<' ';
    		}
    		cout<<endl;
    	}
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41

    B. Settlement of Guinea Pigs

    Portal.

    设已知 x x x 只豚鼠的性别,未知 y y y 只豚鼠的性别。

    • x = 0 x=0 x=0,此时所有豚鼠的性别都未知,则需要 y y y 个笼子。
    • 否则,最坏情况是 1 1 1 只 A 性别豚鼠, x − 1 x-1 x1 只 B 性别豚鼠,需要 1 + ⌈ x − 1 2 ⌉ + y 1+\lceil \dfrac{x-1}{2}\rceil+y 1+2x1+y 个笼子。
    #include 
    using namespace std;
    
    const int maxn=1e5+5;
    int b[maxn];
    
    void solve()
    {
        int n;cin>>n;
        for(int i=1;i<=n;i++) cin>>b[i];
        int x=0,y=0,ans=0;
        for(int i=1;i<=n;i++)
        {
            if(b[i]==1) y++;
            else x+=y,y=0;
            if(!x) ans=max(ans,y+x);
            else ans=max(ans,y+x/2+1);
        }
        cout<<ans<<endl;
    }
    
    int main()
    {
        int t;cin>>t;
        while(t--) solve();
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
  • 相关阅读:
    Flink容错机制
    前后端分离 后端获取不到header解决方案
    servlet
    史上最全 结构型模式之 桥接 外观 组合 享元模式
    LeetCode28.找出字符串中第一个匹配项
    SQL中WITH AS语法的使用
    Redhat 恢复模式重置root用户密码
    Nginx基础教程
    机器学习评估指标 - f1, precision, recall, acc, MCC
    【flutter】架构之商城main入口
  • 原文地址:https://blog.csdn.net/ncwzdlsd/article/details/134017252