[bzoj4429] [NWERC2015] Math Elementary Math Elementary School

Source: Internet
Author: User

At first I thought it was 2-sat. Qaq

Membrane of the following: After discretization of each of the answers, the connection between each logarithm and the answer is to see if the maximum number of matches equals n

1#include <cstdio>2#include <iostream>3#include <cstring>4#include <algorithm>5 #definell Long Long6 using namespacestd;7 Const intmaxn=2523<<2;8 structZs1{ll v;intID;} A[MAXN];9ll B[MAXN];intcnt,n1;Ten structzs{ One     intToo,pre;BOOLflow; A}e[233333];intTOT,LAST[MAXN]; -  ShortDIS[MAXN]; - intDL[MAXN],X[MAXN],Y[MAXN]; the intI,j,k,n,m,s,t,ans; -   - intRA,FH;CharRx; -InlineintRead () { +Rx=getchar (), ra=0, fh=1; -      while((rx<'0'|| Rx>'9') &&rx!='-') rx=GetChar (); +     if(rx=='-') fh=-1, rx=GetChar (); A      while(rx>='0'&&rx<='9') ra*=Ten, ra+=rx- -, Rx=getchar ();returnTalfh; at } -InlineBOOLBFs () { -memset (DIS,0, (t+1) <<1); -     intL=0, r=1, i,now;dl[1]=s,dis[s]=1; -      while(l<r&&!Dis[t]) -          for(I=last[now=dl[++l]];i;i=e[i].pre)if(e[i].flow&&!Dis[e[i].too]) indis[e[i].too]=dis[now]+1, dl[++r]=E[i].too; - //for (i=1;i<=t;i++) printf ("0->%d%d\n", I,dis[i]); to     returnDis[t]; + } - intDfsintXintMX) { the     if(x==t)returnMX; *     intUsed=0IBOOLW; $      for(I=last[x];i;i=e[i].pre)if(e[i].flow&&dis[e[i].too]==dis[x]+1){Panax NotoginsengW=dfs (E[i].too,1);if(w) { -e[i].flow=0, e[i^1].flow=1, used+=W; the             if(USED==MX)returnused; +         } A     } thedis[x]=0;returnused; + } -InlinevoidInsertintAintb) {//printf ("%d-->%d\n", A, b); $e[++tot].too=b,e[tot].flow=1, e[tot].pre=last[a],last[a]=tot, $e[++tot].too=a,e[tot].flow=0, e[tot].pre=last[b],last[b]=tot; - } - BOOLCMP (ZS1 a,zs1 b) {returna.v<B.V;} the intMain () { -n=read ();Wuyi      for(i=1; i<=n;i++) theJ=x[i]=read (), k=y[i]=read (), -a[++n1].v=j+k,a[++n1].v=j-k,a[++n1].v=1ll*j*K, WuA[n1-2].id=a[n1-1].id=a[n1].id=i; -Sort (A +1, A +1+N1,CMP);intCnt=0; Abouttot=1; $      for(i=1; I<=n1;insert (a[i].id,cnt+n), i++) -         if(a[i].v!=a[i-1].v| | i==1) b[++cnt]=a[i].v; - //for (i=1;i<=n1;i++) printf ("%lld%d\n", a[i].v,a[i].id); -s=0, t=n+cnt+1; A      for(i=1; i<=n;i++) Insert (s,i); +      for(i=1; i<=cnt;i++) Insert (i+n,t); the      while(BFS ())) Ans+=dfs (S,1<< at); -     if(ans==N) { $          for(i=1; i<=n;i++) the              for(J=last[i];j;j=e[j].pre)if(e[j].too&&!E[j].flow) { thell k=b[e[j].too-n]; the                 if(x[i]+y[i]==k) printf ("%d +%d =%lld\n", x[i],y[i],k);Else the                 if(x[i]-y[i]==k) printf ("%d-%d =%lld\n", x[i],y[i],k);Else -                 if(1ll*x[i]*y[i]==k) printf ("%d *%d =%lld\n", x[i],y[i],k); in                  Break; the             } the}ElsePuts"Impossible"); About     return 0; the}
View Code

[bzoj4429] [NWERC2015] Math Elementary Math Elementary School

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.