[luogu2474 SCOI2008] Balance (Floyd differential constraint)

Source: Internet
Author: User

Transmission Door

Solution

Due to the weight of only three cases, the thought of using differential constraints.
Due to the small range, the thought can be floyed to seek differential constraints, the balance of violence to seek the other side

Code
#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]&GT;MX[I][B]) ans1++; if (mx[a][i]<mi[j][b]| |        MX[A][J]&LT;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] Balance (Floyd differential constraint)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.