# bzoj1077: [SCOI2008]天平

55 篇文章 0 订阅

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std;
int fa[55],l[55],r[55],g[55][55],v[55],q[55];
int ans1,ans2,ans3,n,A,B,top;
char ch[55][55];
int sgn(int x){return !x?0:x/abs(x);}
int get(int x){return fa[x]==x?x:fa[x]=get(fa[x]);}
int main(){
scanf("%d%d%d",&n,&A,&B);
for (int i=1;i<=n;i++) fa[i]=i;
for (int i=1;i<=n;i++){
scanf("%s",ch[i]+1);
for (int j=1;j<=n;j++)
if (ch[i][j]=='='){
int x=get(i),y=get(j);
fa[x]=y;
}
}
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
if (ch[i][j]=='+') g[get(i)][get(j)]=1;
else if (ch[i][j]=='-') g[get(i)][get(j)]=-1;
for (int i=1;i<=n;i++) if (get(i)==i) q[++top]=i;
for (int i=1;i<=top;i++){
int l=0,r=0;
for (int j=1;j<=top;j++){
if (g[q[i]][q[j]]==1) l=1;
if (g[q[i]][q[j]]==-1) r=1;
}
if (!l||!r) continue;
v[q[i]]=2;
for (int j=1;j<=top;j++)
if (g[q[i]][q[j]]==1) v[q[j]]=1;
else if (g[q[i]][q[j]]==-1) v[q[j]]=3;
}
for (int i=1;i<=top;i++){
l[q[i]]=1; r[q[i]]=3;
if (v[q[i]]) l[q[i]]=r[q[i]]=v[q[i]];
else for (int j=1;j<=top;j++)
if (g[q[i]][q[j]]==1) l[q[i]]=2;
else if (g[q[i]][q[j]]==-1) r[q[i]]=2;
}
for (int i=1;i<n;i++) if (i!=A&&i!=B)
for (int j=i+1;j<=n;j++) if (j!=A&&j!=B){
int fi=get(i),fj=get(j),fa=get(A),fb=get(B);
int t1=0,t2=0,t3=0;
for (int vi=l[fi];vi<=r[fi];vi++)
for (int vj=l[fj];vj<=r[fj];vj++)
for (int va=l[fa];va<=r[fa];va++)
for (int vb=l[fb];vb<=r[fb];vb++){
int f[4]={fi,fj,fa,fb};
int v[4]={vi,vj,va,vb};
int fl=1;
for (int x=0;x<4&&fl;x++)
for (int y=0;y<4&&fl;y++)
if (f[x]==f[y]&&v[x]!=v[y]) fl=0;
for (int x=0;x<4&&fl;x++)
for (int y=0;y<4&&fl;y++)
if (g[f[x]][f[y]]&&sgn(v[x]-v[y])!=g[f[x]][f[y]]) fl=0;
if (!fl) continue;
if (vi+vj>va+vb) t1=1;
if (vi+vj==va+vb) t2=1;
if (vi+vj<va+vb) t3=1;
}
if (t1+t2+t3==1)
ans1+=t1,ans2+=t2,ans3+=t3;
}
printf("%d %d %d",ans3,ans2,ans1);
}
• 0
点赞
• 0
收藏
• 打赏
• 0
评论
10-02 47
11-27 29
05-18 346
02-25 1284
04-18 800
09-22 527
04-21 196
02-20 636
10-07 179
03-30 158
10-27 51
01-24 1350
11-05 47
02-12 137
05-08 1399
11-07 102
06-18 1212
04-22 953
03-09 599
03-17 597

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

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

zhouyuyang233

¥2 ¥4 ¥6 ¥10 ¥20

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