标签:cstring algorithm inline pac cst 差分 sdi const min
由于重量只有三种情况,那么想到用差分约束。
由于范围比较小,想到可以floyed求差分约束,暴力求天平另一边
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define F(i,a,b) for(register int i=(a);i<=(b);i++)
#define E(i,u) for(register int i=head[u],v;i;i=E[i].nxt)
using namespace std;
inline int read() {
int x=0,f=1;char c=getchar();
while(!isdigit(c)) {if(c=='-')f=-f;c=getchar();}
while(isdigit(c)) x=(x<<1)+(x<<3)+c-48,c=getchar();
return x*f;
}
const int N=60;
int n,A,B,ans1,ans2,ans3;
int mx[N][N],mi[N][N];
char ch[N];
int main() {
n=read(),A=read(),B=read();
F(i,1,n) {
scanf("%s",ch+1);
F(j,1,n) if(ch[j]=='=') mx[i][j]=mi[i][j]=0;
else if(ch[j]=='-') mx[i][j]=-1,mi[i][j]=-2;
else if(ch[j]=='+') mx[i][j]=2,mi[i][j]=1;
else mx[i][j]=2,mi[i][j]=-2;
}
F(k,1,n) F(i,1,n) if(i!=k) F(j,1,n) if(i!=j&&k!=j)
mx[i][j]=min(mx[i][j],mx[i][k]+mx[k][j]),
mi[i][j]=max(mi[i][j],mi[i][k]+mi[k][j]);
F(i,1,n) if(i!=A&&i!=B) F(j,i+1,n) if(j!=A&&j!=B) {
if(mi[A][i]>mx[j][B]||mi[A][j]>mx[i][B]) ans1++;
if(mx[A][i]<mi[j][B]||mx[A][j]<mi[i][B]) ans3++;
if((mi[A][i]==mx[A][i]&&mi[B][j]==mx[B][j]&&mi[A][i]==mi[j][B])
||(mi[A][j]==mx[A][j]&&mi[B][i]==mx[B][i]&&mi[A][j]==mi[i][B])) ans2++;
}
printf("%d %d %d",ans1,ans2,ans3);
return 0;
}
[luogu2474 SCOI2008]天平(floyd差分约束)
标签:cstring algorithm inline pac cst 差分 sdi const min
原文地址:https://www.cnblogs.com/Menteur-Hxy/p/9738009.html