竞赛讨论区 > B题求助(只通过52%)
头像
牛客683902621号
编辑于 02-03 01:00
+ 关注

B题求助(只通过52%)

#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
        cin>>n;
        map<pair<int,int>,int> ha;
        map<int,int> mp;//标记某一列
        int l=0,r=0;//标记左右有没有已经封好
        int ll=0,rr=0,mid=0;//标记鸡的左右下
        long long lnum=0,rnum=0;//标记0左边和右边的火数量
        for(int i=1;i<=n;i++)
        {
            pair<int,int> pa;
            cin>>pa.first>>pa.second;
            ha[pa]=1;
            mp[pa.second]++;
            
            if(pa.second<=0)lnum++;
            else rnum++;
            
            if(pa.first==1&&pa.second==1)
            {
                rr=1;
            }else if(pa.first==1&&pa.second==-1)
            {
                ll=1;
            }else if(pa.first==2&&pa.second==0)
            {
                mid=1;
            }
            if(mp[pa.second]==2)
            {
                if(pa.second<0)
                {
                    l=1;
                }else r=1;
            }
            pair<int,int> now;
            now.first=pa.first^3;//1->2,2->1
            now.second=pa.second-1;
            if(ha[now]==1)
            {
                //有斜墙
            	if(pa.second<0)
                {
                    l=1;
                }else r=1;
			}
			now.second=pa.second+1;
            if(ha[now]==1)
            {
                //有斜墙
            	if(pa.second<0)
                {
                    l=1;
                }else r=1;
			}
        }
//         ha.clear();
//         mp.clear();
        //结果
        if(l==1&&r==1)
        {
            cout<<0<<endl;
        }else 
        {
            if(n==0)
            {
                cout<<3<<endl;
            }else if(n==1)
            {
                if(mid==1||ll==1||rr==1)
                {
                    cout<<2<<endl;
                }else
                {
                    cout<<3<<endl;
                }
            }else
            {
                int cnt=0;
                if(ll==1)cnt++;
                if(rr==1)cnt++;
                if(mid==1)cnt++;
                //3封
                int ans=3-cnt;
                
                if(mid==1)
                {
                    lnum++,rnum++;
                }
                if(ll)l=1;
                if(rr)r=1;
                //两边封
                int ans0 = 2, ans1 = 2;
                if(lnum>0)ans0=1;
                if(rnum>0)ans1=1;
                
                if(l==1)ans0=0;
                if(r==1)ans1=0;
                ans=min(ans,ans1+ans0);
                cout<<ans<<endl;
            }
            
        }
	}
	return 0;
}

全部评论

(0) 回帖
加载中...
话题 回帖

等你来战

查看全部

热门推荐