首页 > 其他 > 详细

poj 1029(模拟)

时间:2021-07-28 18:28:00      阅读:38      评论:0      收藏:0      [点我收藏+]
#include<iostream>
#include<cstring>
using namespace std;
int f[1005],l[105][505],r[105][505];
char c[105];
int main(){
    int n,k,i,j,w[505],t,ans,ansi,tmp[1005];
    cin>>n>>k;
    for(i=1;i<=k;i++){
        cin>>w[i];
        for(j=1;j<=w[i];j++){
            cin>>l[i][j];
        }
        for(j=1;j<=w[i];j++){
            cin>>r[i][j];
        }
        cin>>c[i];
    }
    for(i=1;i<=n;i++){
        f[i] = -2;
    }
    for(i=1;i<=k;i++){
        memset(tmp,0,sizeof(tmp));
        if(c[i]===){
            for(j=1;j<=w[i];j++){
                f[l[i][j]] = 0;
                f[r[i][j]] = 0;
            }
        }
        else if(c[i]==<){
            for(j=1;j<=w[i];j++){
                tmp[l[i][j]] = 1;
                tmp[r[i][j]] = 1;
                if(f[l[i][j]]==-2){
                    f[l[i][j]] = -1;
                }
                else if(f[l[i][j]]==1){
                    f[l[i][j]] = 0;
                }
                if(f[r[i][j]]==-2){
                    f[r[i][j]] = 1;
                }
                else if(f[r[i][j]]==-1){
                    f[r[i][j]] = 0;
                }
            }
            for(j=1;j<=n;j++){
                if(tmp[j]==0){
                    f[j] = 0;
                }
            }
        }
        else if(c[i]==>){
            for(j=1;j<=w[i];j++){
                tmp[l[i][j]] = 1;
                tmp[r[i][j]] = 1;
                if(f[l[i][j]]==-2){
                    f[l[i][j]] = 1;
                }
                else if(f[l[i][j]]==-1){
                    f[l[i][j]] = 0;
                }
                if(f[r[i][j]]==-2){
                    f[r[i][j]] = -1;
                }
                else if(f[r[i][j]]==1){
                    f[r[i][j]] = 0;
                }
            }
            for(j=1;j<=n;j++){
                if(tmp[j]==0){
                    f[j] = 0;
                }
            }
        }
    }
    ans = n;
    ansi = 0;
    for(i=1;i<=n;i++){
        if(f[i]!=0){
            ans--;
            ansi = i;
        }
    }
    if(ans==n-1){
        cout<<ansi<<endl;
    }
    else{
        cout<<"0"<<endl;
    }
    return 0;
}

 

poj 1029(模拟)

原文:https://www.cnblogs.com/stevenzrx/p/15070863.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!