It is well known, that radio waves interfere, so if two closely located radio transmitters use the same frequency, the quality of the programs is poor.
The company NateRadio is planning to transmit its programs in Flatland. The Ministry of Health and Communications has issued the license to the company that allows it to use two different frequencies for the transmission.
The company has n slots for radio transmitters located at different points of the country. However, the transmitters themselves are not yet bought. The managers of the company want to know what power the transmitters should be. The power of the transmitter affects the range it transmits the radio program to.
All transmitters will have the same power. Transmitters will be installed into the slots and each will be tuned to one of the two allowed frequencies. The power of the transmitters must be selected in such a way that the programs from no two transmitters tuned to the same frequency are simultaneously received at any point. Each slot must be used.
Since the company wants the programs to be received by most people, it wants to install as powerful transmitters as possible --- the range of the transmission must be maximal.
The first line of the input file contains n --- the number of slots for the transmitters (3 ≤ n ≤ 1200). The following n lines contain two integer numbers each --- the coordinates of the corresponding slots. Coordinates do not exceed 104 by their absolute value. All slots are different.
There are multiple cases. Process to the end of file.
On the first line of the output file print the maximal possible range of the transmitters. On the second line print n integer numbers --- for each transmitter slot print 1 if the transmitter in this slot must use the first frequency, or 2 if it must use the second one.
You answer must be accurate up to 10-6. All inaccurances under this level will be resolved in your favor.
4 0 0 0 1 1 0 1 1
0.70710678118654752 1 2 2 1
Author: Andrew Stankevich
Source: Andrew Stankevich's Contest #11
#include<iostream> #include<math.h> #include<queue> #include<algorithm> #define M 1205 #define MIN 1e-8 using namespace std; int n; struct POINT { int x,y; int index; }p[M],now; queue<POINT>Q1,Q2; double len[M*M/2]; int mark[M]; int ans[M]; int cnt; inline double dis(POINT a,POINT b) { return sqrt(1.0*(a.x-b.x)*(a.x-b.x)+1.0*(a.y-b.y)*(a.y-b.y)); } void init() { int i,j; memset(mark,-1,sizeof(mark)); for(i=1;i<=n;i++) { scanf("%d%d",&p[i].x,&p[i].y); p[i].index=i; } cnt=0; for(i=1;i<n;i++) for(j=i+1;j<=n;j++) len[cnt++]=dis(p[i],p[j]); sort(len,len+cnt); } bool solve(double length) { memset(mark,-1,sizeof(mark)); while(!Q1.empty()) { Q1.pop(); } while(!Q2.empty()) { Q2.pop(); } POINT temp; int i,j; int num=1; now.x=p[1].x; now.y=p[1].y; now.index=1; mark[now.index]=1; Q1.push(now); while(!(Q1.empty()&&Q2.empty())) { while(!Q1.empty()) { now=Q1.front(); Q1.pop(); for(i=1;i<=n;i++) { if(dis(now,p[i])<length-MIN&&i!=now.index) { if(mark[p[i].index]==-1) { mark[p[i].index]=2; temp=p[i]; Q2.push(temp); num++; } else if(mark[p[i].index]==1) return false; } } } while(!Q2.empty()) { now=Q2.front(); Q2.pop(); for(i=1;i<=n;i++) { if(dis(now,p[i])<length-MIN&&i!=now.index) { if(mark[p[i].index]==-1) { mark[p[i].index]=1; temp=p[i]; Q1.push(temp); num++; } else if(mark[i]==2) return false; } } } if(num<n&&Q1.empty()&&Q2.empty()) { i=1; while(i<=n) { if(mark[i]==-1) { Q1.push(p[i]); mark[p[i].index]=1; num++; break; } i++; } } } return true; } int main() { double res; while(scanf("%d",&n)!=EOF) { init(); int low=0; int high=cnt-1; while(low<high-1) { int mid=(low+high)/2; if(solve(len[mid])) { low=mid; res=len[mid]; memcpy(ans,mark,sizeof(mark)); } else high=mid-1; } if(solve(len[high])) { res=len[high]; memcpy(ans,mark,sizeof(mark)); } printf("%.17lf/n",res/2); for(int i=1;i<n;i++) cout<<ans[i]<<" "; cout<<ans[n]<<endl; } }