HDU3622(二分+2-SAT)
Bomb Game
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5647 Accepted Submission(s): 2036
Problem Description
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
Output
Sample Input
1 1 1 -1
-1 -1 -1 1
2
1 1 -1 -1
1 -1 -1 1
Sample Output
1.00
Source
- //2017-08-27
- #include <cstdio>
- #include <cstring>
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- const int N = ;
- const int M = N*N;
- const double EPS = 1e-;
- int head[N], rhead[N], tot, rtot;
- struct Edge{
- int to, next;
- }edge[M], redge[M];
- void init(){
- tot = ;
- rtot = ;
- memset(head, -, sizeof(head));
- memset(rhead, -, sizeof(rhead));
- }
- void add_edge(int u, int v){
- edge[tot].to = v;
- edge[tot].next = head[u];
- head[u] = tot++;
- redge[rtot].to = u;
- redge[rtot].next = rhead[v];
- rhead[v] = rtot++;
- }
- vector<int> vs;//后序遍历顺序的顶点列表
- bool vis[N];
- int cmp[N];//所属强连通分量的拓扑序
- //input: u 顶点
- //output: vs 后序遍历顺序的顶点列表
- void dfs(int u){
- vis[u] = true;
- for(int i = head[u]; i != -; i = edge[i].next){
- int v = edge[i].to;
- if(!vis[v])
- dfs(v);
- }
- vs.push_back(u);
- }
- //input: u 顶点编号; k 拓扑序号
- //output: cmp[] 强连通分量拓扑序
- void rdfs(int u, int k){
- vis[u] = true;
- cmp[u] = k;
- for(int i = rhead[u]; i != -; i = redge[i].next){
- int v = redge[i].to;
- if(!vis[v])
- rdfs(v, k);
- }
- }
- //Strongly Connected Component 强连通分量
- //input: n 顶点个数
- //output: k 强连通分量数;
- int scc(int n){
- memset(vis, , sizeof(vis));
- vs.clear();
- for(int u = ; u < n; u++)
- if(!vis[u])
- dfs(u);
- int k = ;
- memset(vis, , sizeof(vis));
- for(int i = vs.size()-; i >= ; i--)
- if(!vis[vs[i]])
- rdfs(vs[i], k++);
- return k;
- }
- int n;
- struct Point{
- int x, y;
- }point[N];
- //input: 两个点
- //output: 两点间距离
- double distance(Point a, Point b){
- return sqrt((double)(a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
- }
- //input:radius 半径
- //output:true 通过选取某些点可以得到radius的分数,false 无法得到radius的分数
- bool check(double radius){
- init();
- for(int i = ; i < *n; i++){
- for(int j = i+; j < *n; j++){
- if((i^) == j)continue;
- if(distance(point[i], point[j]) < *radius){//i与j存在矛盾
- add_edge(i^, j);// NOT i -> j
- add_edge(j^, i);// NOT j -> i
- }
- }
- }
- scc(*n);
- for(int i = ; i < *n; i += ){
- if(cmp[i] == cmp[i^])
- return false;
- }
- return true;
- }
- int main()
- {
- std::ios::sync_with_stdio(false);
- //freopen("inputC.txt", "r", stdin);
- while(cin>>n){
- for(int i = ; i < n; i++){
- cin>>point[*i].x>>point[*i].y>>point[*i+].x>>point[*i+].y;
- }
- double l = 0.0, r = 40000.0, mid, ans = ;
- while(r-l > EPS){
- mid = (l+r)/;
- if(check(mid)){
- ans = mid;
- l = mid;
- }else
- r = mid;
- }
- cout.setf(ios::fixed);
- cout<<setprecision()<<ans<<endl;
- }
- return ;
- }
HDU3622(二分+2-SAT)的更多相关文章
- hdu3622 二分+2sat
题意: 给你N组炸弹,每组2个,让你在这N组里面选取N个放置,要求(1)每组只能也必须选取一个(2)炸弹与炸弹之间的半径相等(3)不能相互炸到对方.求最大的可放置半径. 思路: 二 ...
- hdu3622(二分+two-sat)
传送门:Bomb Game 题意:给n对炸弹可以放置的位置(每个位置为一个二维平面上的点),每次放置炸弹是时只能选择这一对中的其中一个点,每个炸弹爆炸的范围半径都一样,控制爆炸的半径使得所有的爆炸范围 ...
- hdu3622 2-sat问题,二分+判断有无解即可。
/*2-sat问题初破!题意:每一对炸弹只能选一个(明显2-sat),每个炸弹半径自定,爆炸范围不可 相交,求那个最小半径的最大值(每种策略的最小半径不同).思:最优解:必然是选择的点最近 的俩个距离 ...
- HDU3622 Bomb Game(二分+2-SAT)
题意 给n对炸弹可以放置的位置(每个位置为一个二维平面上的点), 每次放置炸弹是时只能选择这一对中的其中一个点,每个炸弹爆炸 的范围半径都一样,控制爆炸的半径使得所有的爆炸范围都不相 交(可以相切), ...
- 2 - sat 模板(自用)
2-sat一个变量两种状态符合条件的状态建边找强连通,两两成立1 - n 为第一状态(n + 1) - (n + n) 为第二状态 例题模板 链接一 POJ 3207 Ikki's Story IV ...
- 证明与计算(3): 二分决策图(Binary Decision Diagram, BDD)
0x01 布尔代数(Boolean algebra) 大名鼎鼎鼎的stephen wolfram在2015年的时候写了一篇介绍George Boole的文章:George Boole: A 200-Y ...
- Map Labeler POJ - 2296(2 - sat 具体关系建边)
题意: 给出n个点 让求这n个点所能建成的正方形的最大边长,要求不覆盖,且这n个点在正方形上或下边的中点位置 解析: 当然是二分,但建图就有点还行..比较难想..行吧...我太垃圾... 2 - s ...
- LA 3211 飞机调度(2—SAT)
https://vjudge.net/problem/UVALive-3211 题意: 有n架飞机需要着陆,每架飞机都可以选择“早着陆”和“晚着陆”两种方式之一,且必须选择一种,第i架飞机的早着陆时间 ...
- UVALive - 3211 (2-SAT + 二分)
layout: post title: 训练指南 UVALive - 3211 (2-SAT + 二分) author: "luowentaoaa" catalog: true m ...
随机推荐
- Quartz是一个任务调度
这段时间做一个案子,用到每天定时处理事件,之前的解决思路是通过一个定时器轮询时间段,这样不能精准的在某个时间戳上执行动作.由于没有用过Quartz是一个任务调度,一直使用这个办法,今天通过同事提点,从 ...
- CF1082解题报告
CF1082A Vasya and Book 模拟一下即可 \(Code\ Below:\) #include <bits/stdc++.h> using namespace std; c ...
- 【翻译】 Windows 内核漏洞学习—空指针解引用
Windows Kernel Exploitation – NullPointer Dereference 原文地址:https://osandamalith.com/2017/06/22/windo ...
- pika配置文件说明
# Pika 端口 port : 9221 # pika进程数量,不建议超过核心数量,pika是多线程的 thread-num : 1 # Sync 线程数量 sync-thread-num : 6 ...
- SSH 学习笔记
零.背景 在看 pm2 的 deploy 功能的时候,对 ssh 的不熟悉导致错误频出,包括之前对 github 的配置也用到了 SSH,所以找个机会整理一下. 一.介绍 SSH 是每一台 Linux ...
- 一步步Cobol 400 上手自学入门教程03 - 数据部
数据部的作用 程序中涉及到的全部数据(输入.输出.中间)都要在此定义,对它们的属性进行说明.主要描述以下属性: 数据类型(数值/字符)和存储形式(长度) 数据项之间的关系(层次和层号) 文件与记录的关 ...
- django基础之二
一.什么是架构? 框架,即framework,特指为解决一个开放性问题而设计的具有一定约束性的支撑结构,使用框架可以帮你快速开发特定的系统,简单地说,就是你用别人搭建好的舞台来做表演. 对于所有的We ...
- 【xsy2913】 enos 动态dp
题目大意:给你一棵 $n$个点 以 $1$为根 的树,每个点有$ 0,1,2 $三种颜色之一,初始时整棵树的颜色均为 $0$. $m$ 次操作, 每次操作形如: 1 x y c : 将 $x$到$y$ ...
- Java动态代理总结
在之前的代码调用阶段,我们用action调用service的方法实现业务即可. 由于之前在service中实现的业务可能不能够满足当先客户的要求,需要我们重新修改service中的方法,但是servi ...
- ORACLE数据库表解锁record is locked by another user
出现此问题多由于操作Oracle执行完,没有COMMIT,直接把PL/SQL关闭掉,后来导致那张表被锁住,当编辑时就会出现这个信息,record is locked by another user! ...