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 ...
随机推荐
- spring cloud 学习(6) - zuul 微服务网关
微服务架构体系中,通常一个业务系统会有很多的微服务,比如:OrderService.ProductService.UserService...,为了让调用更简单,一般会在这些服务前端再封装一层,类似下 ...
- Shell - 简明Shell入门07 - 数组(Array)
示例脚本及注释 #!/bin/bash test0=() # 定义数组 test1=(a b c d e f) # 定义数组 test2=( # 定义数组 'A?' "BB!" C ...
- Testing - 软件测试知识梳理 - 软件可靠性测试
软件可靠性的基本概念 错误,缺陷,故障和失效 错误:指的是软件在生命周期中各个阶段的状态和行为与人们的期待不一致的偏差,不单单是软件系统本身,中间产品的偏差也算是软件错误 缺陷:指的是软件中一切不好的 ...
- 让PETSc跑得再快一些
最近做了一个使用PETSc来求解线性方程组(Ax=b)的项目,把其中遇到的一些坑和解决方法记录下来.本文不介绍PETSc如何入门,而是给出一些能让PETSc运行得更快的编程细节.开始我只是简单地修改P ...
- [umbraco] 数据结构
我想此图就能说明一切了,不需要再废话了
- JDK8 - Function介绍
注:写这个文档只是为了方便加深记忆,加强理解,重点关注两个default方法中泛型[V]. JDK8作为一个还在维护阶段的长期版本,势必会在企业应用中占据相当大的市场份额,所以还是以JDK8作为例子的 ...
- arm pip源
https://www.piwheels.org/simple
- python for dblp.xml
由于最近处理数据时涉及到dblp.xml,刚开始下载时dblp.xml只有300多M,但解压之后就有1.9G,没有什么东西能够打开,所以必须要用工具来处理,在python中sax包能够一边解析一边处理 ...
- JavaScript -- Style
-----055-Style.html----- <!DOCTYPE html> <html> <head> <meta http-equiv="c ...
- Silverlight中使用MVVM(1)--基础
Silverlight中使用MVVM(1)--基础 Silverlight中使用MVVM(2)—提高 Silverlight中使用MVVM(3)—进阶 Silverlight中使用MVVM(4)—演练 ...