ZOJ 3717 HDU 3622 binary + 2-SAT

Source: Internet
Author: User

Question: Here are N groups of balloons. Each group has 2 balloons. Each group has a balloon. If N balloons do not meet each other, the maximum radius of the balloon is R.

Idea: directly bind the radius to 2-sat to determine the feasibility. If there are two points in the same group in the same strong Unicom component after SCC, it is not feasible.

Note that after the last decimal point, you need to take three decimal places to check whether the result is correct. The last operation is to check whether the result is correct .. My WA is dead ..

I think this question is too difficult...

# Include <iostream> # include <cstdio> # include <algorithm> # include <string> # include <cmath> # include <cstring> # include <queue> # include <set> # include <vector> # include <stack> # include <map> # include <iomanip> # define PI acos (-1.0) # define Max 2505 # define inf 1 <28 # define LL (x) (x <1) # define RR (x) (x <1 | 1) # define REP (I, s, t) for (int I = (s); I <= (t); ++ I) # define ll long Long # define mem (a, B) memset (a, B, sizeof (a) # define mp (a, B) make_pair (a, B) # define PII pair <int, int> using namespace std; int t; # define N 2005 double x [N <1], y [N <1], z [N <1]; struct kdq {int e, next;} ed [N * 100]; int head [N], num; int dfn [N <1], low [N <1], st [N <1], top, dp, inst [N <1], ca, belong [N <1]; void add (int s, int e) {ed [num]. e = e; ed [num]. next = head [s ]; Head [s] = num ++;} void init () {mem (head,-1); num = 0; mem (dfn, 0); mem (low, 0); mem (st, 0); mem (inst, 0); mem (belong, 0); top = dp = ca = 0;} inline double getdis (int I, int j) {return sqrt (x [I]-x [j]) * (x [I]-x [j]) + (y [I]-y [j]) * (y [I]-y [j]) + (z [I]-z [j]) * (z [I]-z [j]);} void tarjan (int now) {low [now] = dfn [now] = ++ dp; st [top ++] = now; inst [now] = 1; for (I Nt I = head [now]; ~ I; I = ed [I]. next) {int e = ed [I]. e; if (! Dfn [e]) {tarjan (e); low [now] = min (low [now], low [e]);} else if (inst [e]) {low [now] = min (low [now], dfn [e]) ;}} if (low [now] = dfn [now]) {ca ++; int xx; do {xx = st [-- top]; belong [xx] = ca; inst [xx] = 0;} while (xx! = Now) ;}} void build (double mid) {init (); for (int I = 0; I <t; I ++) {for (int j = I + 1; j <t; j ++) {if (getdis (LL (I), LL (j) <mid) {add (LL (I), LL (j) ^ 1); add (LL (j), LL (I) ^ 1 );} if (getdis (LL (I), RR (j) <mid) {add (LL (I), RR (j) ^ 1); add (RR (j ), LL (I) ^ 1);} if (getdis (RR (I), LL (j) <mid) {add (RR (I), LL (j) ^ 1); add (LL (j), RR (I) ^ 1);} if (getdis (RR (I), RR (j) <mid ){ Add (RR (I), RR (j) ^ 1); add (RR (j), RR (I) ^ 1) ;}}} int fuckit () {for (int I = 0; I <t <1; I ++) {top = dp = 0; if (! Dfn [I]) tarjan (I) ;}for (int I = 0; I <t; I ++) {if (belong [LL (I)] = belong [RR (I)]) return 0;} return 1;} int main () {while (cin> t) {for (int I = 0; I <t; I ++) {cin> x [LL (I)]> y [LL (I)]> z [LL (I)]; cin> x [RR (I)]> y [RR (I)]> z [RR (I)];} // cout <getdis (0, 1) <endl; double l = 0, r = 20000; double mid; while (r-l> 1e-5) {mid = (l + r)/2; build (mid); if (fuckit ()) {L = mid;} else r = mid;} double ans = mid/2; // directly output mid/2 and then WA is dead. Char aa [222]; // too disgusting. Sprintf (aa, "%. 3f", ans); sscanf (aa, "% lf", & ans); build (ans * 2); if (! Fuckit () ans-= 0.001; printf ("%. 3f \ n ", ans);} return 0 ;} # include <iostream> # include <cstdio> # include <algorithm> # include <string> # include <cmath> # include <cstring> # include <queue> # include <set> # include <vector> # include <stack> # include <map> # include <iomanip> # define PI acos (-1.0) # define Max 2505 # define inf 1 <28 # define LL (x) (x <1) # define RR (x) (x <1 | 1) # define REP (I, s, t) for (int I = (S); I <= (t); ++ I) # define ll long # define mem (a, B) memset (a, B, sizeof ()) # define mp (a, B) make_pair (a, B) # define PII pair <int, int> using namespace std; int t; # define N 2005 double x [N <1], y [N <1], z [N <1]; struct kdq {int e, next ;} ed [N * 100]; int head [N], num; int dfn [N <1], low [N <1], st [N <1], top, dp, inst [N <1], ca, belong [N <1]; void add (int s, int e) {ed [nu M]. e = e; ed [num]. next = head [s]; head [s] = num ++;} void init () {mem (head,-1); num = 0; mem (dfn, 0); mem (low, 0); mem (st, 0); mem (inst, 0); mem (belong, 0); top = dp = ca = 0 ;} inline double getdis (int I, int j) {return sqrt (x [I]-x [j]) * (x [I]-x [j]) + (y [I]-y [j]) * (y [I]-y [j]) + (z [I]-z [j]) * (z [I]-z [j]);} void tarjan (int now) {low [now] = dfn [now] = ++ dp; st [top ++] = no W; inst [now] = 1; for (int I = head [now]; ~ I; I = ed [I]. next) {int e = ed [I]. e; if (! Dfn [e]) {tarjan (e); low [now] = min (low [now], low [e]);} else if (inst [e]) {low [now] = min (low [now], dfn [e]) ;}} if (low [now] = dfn [now]) {ca ++; int xx; do {xx = st [-- top]; belong [xx] = ca; inst [xx] = 0;} while (xx! = Now) ;}} void build (double mid) {init (); for (int I = 0; I <t; I ++) {for (int j = I + 1; j <t; j ++) {if (getdis (LL (I), LL (j) <mid) {add (LL (I), LL (j) ^ 1); add (LL (j), LL (I) ^ 1 );} if (getdis (LL (I), RR (j) <mid) {add (LL (I), RR (j) ^ 1); add (RR (j ), LL (I) ^ 1);} if (getdis (RR (I), LL (j) <mid) {add (RR (I), LL (j) ^ 1); add (LL (j), RR (I) ^ 1);} if (getdis (RR (I), RR (j) <mid) {ad D (RR (I), RR (j) ^ 1); add (RR (j), RR (I) ^ 1) ;}}} int fuckit () {for (int I = 0; I <t <1; I ++) {top = dp = 0; if (! Dfn [I]) tarjan (I) ;}for (int I = 0; I <t; I ++) {if (belong [LL (I)] = belong [RR (I)]) return 0;} return 1;} int main () {while (cin> t) {for (int I = 0; I <t; I ++) {cin> x [LL (I)]> y [LL (I)]> z [LL (I)]; cin> x [RR (I)]> y [RR (I)]> z [RR (I)];} // cout <getdis (0, 1) <endl; double l = 0, r = 20000; double mid; while (r-l> 1e-5) {mid = (l + r)/2; build (mid); if (fuckit () {l = Mid;} else r = mid;} double ans = mid/2; // directly output mid/2 and then WA to death. Char aa [222]; // too disgusting. Sprintf (aa, "%. 3f", ans); sscanf (aa, "% lf", & ans); build (ans * 2); if (! Fuckit () ans-= 0.001; printf ("%. 3f \ n", ans);} return 0 ;}

HDU 3622

The two questions are actually exactly the same, but the first question is 3D, the first question is 2D, and the solution is completely the same, but after the second question, it is not necessary to determine the feasibility.


 

#include <iostream>  #include <cstdio>  #include <algorithm>  #include <string>  #include <cmath>  #include <cstring>  #include <queue>  #include <set>  #include <vector>  #include <stack>  #include <map>  #include <iomanip>  #define PI acos(-1.0)  #define Max 2505  #define inf 1<<28  #define LL(x) ( x << 1 )  #define RR(x) ( x << 1 | 1 )  #define REP(i,s,t) for( int i = ( s ) ; i <= ( t ) ; ++ i )  #define ll long long  #define mem(a,b) memset(a,b,sizeof(a))  #define mp(a,b) make_pair(a,b)  #define PII pair<int,int>  using namespace std;  #define N 105  double x[N << 1] , y[N << 1] ; struct kdq{     int e , next ; }ed[N * 1000] ; int dfn[N << 1] ,low[N << 1] , belong[N << 1] ,st[N << 1] ,inst[N << 1] ,head[N << 1] ; int dp , top , ca , num , n ; inline double getdis(int i ,int j){     return sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])) ; } void add(int s ,int e){     ed[num].e = e ;     ed[num].next = head[s] ;     head[s] = num ++ ; } void init(){     mem(dfn ,0) ;     mem(low ,0) ;     mem(st ,0) ;     mem(head,-1) ;     mem(belong ,0) ;     mem(inst ,0) ;     dp = top = ca = num = 0 ; } void build(double mid){     init() ;     for (int i = 0 ; i < n ; i ++ ){         for (int j = i + 1 ; j < n ; j ++ ){             if(getdis(LL(i) , LL(j)) < mid){                 add(LL(i) , LL(j) ^ 1) ;                 add(LL(j) , LL(i) ^ 1) ;             }             if(getdis(LL(i) , RR(j)) < mid){                 add(LL(i) , RR(j) ^ 1) ;                 add(RR(j) , LL(i) ^ 1) ;             }             if(getdis(RR(i) , LL(j)) < mid){                 add(RR(i) , LL(j) ^ 1) ;                 add(LL(j) , RR(i) ^ 1) ;             }             if(getdis(RR(i) , RR(j)) < mid){                 add(RR(i) , RR(j) ^ 1) ;                 add(RR(j) , RR(i) ^ 1) ;             }         }     } } void tarjan(int now){     dfn[now] = low[now] = ++ dp ;     st[top ++] = now ;     inst[now] = 1 ;     for (int i = head[now] ; ~i ; i = ed[i].next ){         int e = ed[i].e ;         if(!dfn[e]){             tarjan(e) ;             low[now] = min(low[now] , low[e]) ;         }         else if(inst[e]){             low[now] = min(low[now] , dfn[e]) ;         }     }     if(low[now] == dfn[now]){         ca ++ ;         int xx ;         do{             xx = st[-- top] ;             belong[xx] = ca ;             inst[xx] = 0 ;         }while(xx != now) ;     } } int doit(){     for (int i = 0 ; i < n << 1 ; i ++ )if(!dfn[i])tarjan(i) ;     for (int i = 0 ; i < n ; i ++ )if(belong[LL(i)] == belong[RR(i)])return 0 ;     return 1 ; } int main() {     while(cin >> n ){         for (int i = 0 ; i < n ; i ++ ){             cin >> x[LL(i)] >> y[LL(i)] ;             cin >> x[RR(i)] >> y[RR(i)] ;         }         double l = 0 , r = 30000 ,mid ;         while(r - l > 1e-4){             mid = (l + r) / 2 ;             build(mid) ;             if(doit())l = mid ;             else r = mid ;         }         printf("%.2f\n",mid / 2) ;     }     return 0 ; } #include <iostream>#include <cstdio>#include <algorithm>#include <string>#include <cmath>#include <cstring>#include <queue>#include <set>#include <vector>#include <stack>#include <map>#include <iomanip>#define PI acos(-1.0)#define Max 2505#define inf 1<<28#define LL(x) ( x << 1 )#define RR(x) ( x << 1 | 1 )#define REP(i,s,t) for( int i = ( s ) ; i <= ( t ) ; ++ i )#define ll long long#define mem(a,b) memset(a,b,sizeof(a))#define mp(a,b) make_pair(a,b)#define PII pair<int,int>using namespace std;#define N 105double x[N << 1] , y[N << 1] ;struct kdq{    int e , next ;}ed[N * 1000] ;int dfn[N << 1] ,low[N << 1] , belong[N << 1] ,st[N << 1] ,inst[N << 1] ,head[N << 1] ;int dp , top , ca , num , n ;inline double getdis(int i ,int j){    return sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])) ;}void add(int s ,int e){    ed[num].e = e ;    ed[num].next = head[s] ;    head[s] = num ++ ;}void init(){    mem(dfn ,0) ;    mem(low ,0) ;    mem(st ,0) ;    mem(head,-1) ;    mem(belong ,0) ;    mem(inst ,0) ;    dp = top = ca = num = 0 ;}void build(double mid){    init() ;    for (int i = 0 ; i < n ; i ++ ){        for (int j = i + 1 ; j < n ; j ++ ){            if(getdis(LL(i) , LL(j)) < mid){                add(LL(i) , LL(j) ^ 1) ;                add(LL(j) , LL(i) ^ 1) ;            }            if(getdis(LL(i) , RR(j)) < mid){                add(LL(i) , RR(j) ^ 1) ;                add(RR(j) , LL(i) ^ 1) ;            }            if(getdis(RR(i) , LL(j)) < mid){                add(RR(i) , LL(j) ^ 1) ;                add(LL(j) , RR(i) ^ 1) ;            }            if(getdis(RR(i) , RR(j)) < mid){                add(RR(i) , RR(j) ^ 1) ;                add(RR(j) , RR(i) ^ 1) ;            }        }    }}void tarjan(int now){    dfn[now] = low[now] = ++ dp ;    st[top ++] = now ;    inst[now] = 1 ;    for (int i = head[now] ; ~i ; i = ed[i].next ){        int e = ed[i].e ;        if(!dfn[e]){            tarjan(e) ;            low[now] = min(low[now] , low[e]) ;        }        else if(inst[e]){            low[now] = min(low[now] , dfn[e]) ;        }    }    if(low[now] == dfn[now]){        ca ++ ;        int xx ;        do{            xx = st[-- top] ;            belong[xx] = ca ;            inst[xx] = 0 ;        }while(xx != now) ;    }}int doit(){    for (int i = 0 ; i < n << 1 ; i ++ )if(!dfn[i])tarjan(i) ;    for (int i = 0 ; i < n ; i ++ )if(belong[LL(i)] == belong[RR(i)])return 0 ;    return 1 ;}int main() {    while(cin >> n ){        for (int i = 0 ; i < n ; i ++ ){            cin >> x[LL(i)] >> y[LL(i)] ;            cin >> x[RR(i)] >> y[RR(i)] ;        }        double l = 0 , r = 30000 ,mid ;        while(r - l > 1e-4){            mid = (l + r) / 2 ;            build(mid) ;            if(doit())l = mid ;            else r = mid ;        }        printf("%.2f\n",mid / 2) ;    }    return 0 ;}


 

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.