ZOJ3370. Radio Waves(2-sat)

算是很裸的吧,二分半径,然后2-sat判定能不能满足条件。

#include <bits/stdc++.h>
using namespace std;
const int maxn=1222;
const double eps=1e-9;
struct node{
    double x,y;
}p[maxn];
struct twoset{
    int n;
    vector<int>g[maxn<<1];
    bool mark[maxn<<1];
    int s[maxn<<1],c;
    bool dfs(int x){
        if(mark[x^1])return false;
        if(mark[x])return true;
        mark[x]=true;
        s[c++]=x;
        for(int i=0;i<g[x].size();i++)if(!dfs(g[x][i]))return false;
        return true;
    }
    void init(int n){
        this->n=n;
        for(int i=0;i<n*2;i++)g[i].clear();
        memset(mark,0,sizeof mark);
    }
    void add_clause(int x,int xval,int y,int yval){
        x=x*2+xval;
        y=y*2+yval;
        g[x^1].push_back(y);
        g[y^1].push_back(x);
    }
    bool solve(){
        for(int i=0;i<n*2;i+=2){
            if(!mark[i]&&!mark[i+1]){
                c=0;
                if(!dfs(i)){
                    while(c>0)mark[s[--c]]=false;
                    if(!dfs(i+1))return false;
                }
            }
        }
        return true;
    }
}solver;

double getdis(node a,node b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void run(int n){
    for(int i=0;i<n;i++)scanf("%lf%lf",&p[i].x,&p[i].y);
    double l=0,r=30000,ans=0;
    while(l+eps<=r){
        double mid=(l+r)/2;
        solver.init(n);
        for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++){
            double dis=getdis(p[i],p[j]);
            if(dis<2*mid){
                solver.add_clause(i,0,j,0);
                solver.add_clause(i,1,j,1);
            }
        }
        if(solver.solve())ans=mid,l=mid+eps;
        else r=mid-eps;
    }
    solver.init(n);
    for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++){
        double dis=getdis(p[i],p[j]);
        if(dis<2*ans){
            solver.add_clause(i,0,j,0);
            solver.add_clause(i,1,j,1);
        }
    }
    solver.solve();
    printf("%.8lf\n",ans);
    for(int i=0;i<n;i++){
        if(solver.mark[i<<1])putchar(‘1‘);
        else putchar(‘2‘);
        printf("%c",i==n-1?‘\n‘:‘ ‘);
    }
}
int main()
{
//    freopen("in","r",stdin);
    int n;
    while(scanf("%d",&n)>0)run(n);
    return 0;
}

  

时间: 2024-12-16 10:10:04

ZOJ3370. Radio Waves(2-sat)的相关文章

Radio Basics for RFID

Radio Basics for RFID (2015/09/24 22:30:37) Radio Basics for RFID (2015/09/24 22:30:37) Radio Basics for RFID (2015/09/24 22:30:37) Radio Basics for RFID (2015/09/24 22:30:37) Radio Basics for RFID (2015/09/24 22:30:37) Radio Basics for RFID (2015/09

Half Wavelength Dipole Antenna

Reference : 1. wikipedia   The dipole antenna is the simplest and most widely used class of antenna.It consists of two identical conductive elements such as metal wires or rods, which are usually bilaterally symmetrical.Each side of the feedline to t

Basic Modulation Techniques: AM FM

The origin of all radio modulation techniques stem back to the AM and FM basic modulation. AM modulation changes the carrier frequency according to the data signal while the FM changes the carrier frequency according to the data signal. The informati

RFID 基础/分类/编码/调制/传输

不同频段的RFID产品会有不同的特性,本文详细介绍了无源的感应器在不同工作频率产品的特性以及主要的应用. 目前定义RFID产品的工作频率有低频.高频和甚高频的频率范围内的符合不同标准的不同的产品,而且不同频段的RFID产品会有不同的特性. 其中感应器有无源和有源两种方式,下面详细介绍无源的感应器在不同工作频率产品的特性以及主要的应用. 1. 低频(从125KHz到134KHz)   其实RFID技术首先在低频得到广泛的应用和推广.该频率主要是通过电感耦合的方式进行工作, 也就是在读写器线圈和感应

新概念4-43

Lesson 43   Are there strangers in space?  宇宙中有外星人吗?     We must conclude from the work of those who have studied the origin of life, that given a planet only approximately like our own, life is almost certain to start. Of all the planets in our sola

射频识别 (RFID) 技术

1. 什么是射频识别 (RFID) 技术? 射频识别 (RFID) 技术可使用无线广播通信对对象或人进行唯一识别,是当今发展速度最快的自动数据采集 (ADC) 技术之一. RFID 开创了一种可自动收集产品.位置.时间或事务处理等信息的新方法,既简单快捷,又不会出现人为错误. 它提供了一种无需视线触及的非接触式数据链路,例如硬纸板盒内的物品,或者有关更严苛或更恶劣环境中的信息,这些环境将严重制约其它自动 ID 技术(例如条形码等). 此外,RFID 不仅是一个 ID 代码,其还可用作数据载体,将

新概念英语第四册41-48课(转)

Lesson 41  Training elephants 训练大象 1.两个主要的技术方法 Two main techniques一直被使用于 have been used for训练大象,training elephants, 这两个方法which我们可以分别称之为we may call respectively 强硬法和温柔法.the tough and the gentle. 两个主要的技术方法一直被用于训练大象,Two main techniques have been used fo

solution

DAY1 A  UVAlive 3937 painting the sticks 给你一些木棒,按照给定的颜色序列染色,每次最多可以染连续的3块(每块的颜色可以不一样),每块可以由任意多个连续木棒组成,求最少步数. 题目里有说不允许覆盖染色吗?统计不同的颜色块的个数,除以3并向上取整就是答案了.. B UValive3938 "Ray, Pass me the dishes!" 给一个长度为n的序列,有m个询问,每次询问某个区间内的和最大的子区间 线段树问题,对于线段树上的每个节点维护

antenna

Antenna (radio) For other uses, see Antenna. Part of a series on Antennas Common types[show] Components[show] Systems[show] Safety and regulation[show] Radiation sources / regions[show] Characteristics[show] Techniques[show] v t e This article needs