3622 Bomb Game //2--SAT

Bomb Game

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 317    Accepted Submission(s): 109


Problem Description
Robbie is playing an interesting computer game. The game field is an unbounded 2-dimensional region. There are N rounds in the game. At each round, the computer will give Robbie two places, and Robbie should choose one of them to put a bomb. The explosion area of the bomb is a circle whose center is just the chosen place. Robbie can control the power of the bomb, that is, he can control the radius of each circle. A strange requirement is that there should be no common area for any two circles. The final score is the minimum radius of all the N circles.
Robbie has cracked the game, and he has known all the candidate places of each round before the game starts. Now he wants to know the maximum score he can get with the optimal strategy.
 

Input
The first line of each test case is an integer N (2 <= N <= 100), indicating the number of rounds. Then N lines follow. The i-th line contains four integers x 1i, y 1i, x 2i, y 2i, indicating that the coordinates of the two candidate places of the i-th round are (x 1i, y 1i) and (x 2i, y 2i). All the coordinates are in the range [-10000, 10000].
 

Output
Output one float number for each test case, indicating the best possible score. The result should be rounded to two decimal places.
 

Sample Input
   
   
   
   
2 1 1 1 -1 -1 -1 -1 1 2 1 1 -1 -1 1 -1 -1 1
 

Sample Output
   
   
   
   
1.41 1.00
 

Source
The 35th ACM/ICPC Asia Regional Tianjin Site —— Online Contest
 

Recommend
lcy
 

Statistic |  Submit |  Discuss  | Back

 

 

 

#include<cstdio>

#include<cstring>

#include<cmath>

const double eps=1e-7;//注意这个要开大

struct T_T

{

    int x,y;

}q[505];

 

struct Node

{

    int adj,next;

}node[505*505];

 

struct TT

{

    int DFN,LOW;

    int belongs;

}num[505];

 

int first[550];

int n,e;

double map[505][505];

double min,max;

bool instack[550];

int stack[550],b_cnt,idx,top;

 

double len(int i,int j)

{

    return sqrt(1.0*(q[i].x-q[j].x)*(q[i].x-q[j].x)+1.0*(q[i].y-q[j].y)*(q[i].y-q[j].y));

}

void init()

{

    for(int i=1;i<=2*n;i++)

    {

        e=0;

        first[i]=-1;

        num[i].DFN=num[i].LOW=0;

        num[i].belongs=0;

        instack[i]=false;

    }

}

void insertEdge(int u,int v)

{

    node[e].adj=v;

    node[e].next=first[u];

    first[u]=e++;;

}

void Tarjan(int u)

{

    int v;

    num[u].DFN=num[u].LOW=(++idx);

    instack[u]=true;

    stack[++top]=u;

    for(int p=first[u];p!=-1;p=node[p].next)

    {

        v=node[p].adj;

        if(!num[v].DFN)

        {

            Tarjan(v);

            if(num[v].LOW<num[u].LOW) num[u].LOW=num[v].LOW;

        }

        else

        if(instack[v]&&num[v].DFN<num[u].LOW)  num[u].LOW=num[v].DFN;

    }

    if(num[u].DFN==num[u].LOW)

    {

        b_cnt++;

        do

        {

           v=stack[top--];

           instack[v]=false;

           num[v].belongs=b_cnt;

        }while(u!=v);

    }

}

bool Tarjan_SCC()

{

    b_cnt=top=idx=0;

    for(int i=1;i<=2*n;i++)

      if(!num[i].DFN) Tarjan(i);

    for(int i=1;i<=n;i++)

      if(num[i].belongs==num[i+n].belongs) return false;

    return true;

}

bool check(double d)

{

    init();

    for(int i=1;i<=n;i++)

      for(int j=i+1;j<=n;j++)

      {

          if(map[i][j]<d) insertEdge(i,j+n),insertEdge(j,i+n);

          if(map[i][j+n]<d) insertEdge(i,j),insertEdge(j+n,i+n);

          if(map[i+n][j]<d) insertEdge(i+n,j+n),insertEdge(j,i);

          if(map[i+n][j+n]<d) insertEdge(i+n,j),insertEdge(j+n,i);

      }

    return Tarjan_SCC();

}

double solve()

{

    double ans=min;

    while(fabs(max-min)>=eps)

    {

        double mid=(min+max)/2;

        if(check(mid))

        {

            if(ans<mid) ans=mid;

            min=mid;

        }

        else max=mid;

    }

    return ans;

}

 

int main()

{

    while(scanf("%d",&n)!=EOF)

    {

        for(int i=1;i<=n;i++)  //处理重点?

        {

            scanf("%d%d",&q[i].x,&q[i].y);

            scanf("%d%d",&q[i+n].x,&q[i+n].y);

        }

        min=1000000.00,max=-1.0;

        for(int i=1;i<=2*n;i++)

          for(int j=1;j<=2*n;j++)

          {

              double l=len(i,j);

              if(l>max) max=l;

              if(l<min) min=l;

              map[i][j]=l;

          }

        printf("%0.2lf/n",solve()/2);

    }

    return 0;

}

你可能感兴趣的:(struct,Integer,input,each,float,output)