1. 程式人生 > 其它 >poj 1029(模擬)

poj 1029(模擬)

#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; }