zoj 3717 - Balloon(2-SAT)
裸的2-SAT,详见刘汝佳训练指南P-323
不过此题有个特别需要注意的地方:You should promise that there is still no overlap for any two balloons after rounded.
模版题,
代码如下:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map> #define LL long long
#define eps 1e-5
#define M 205
#define mod 1000000007 using namespace std; struct Point
{
int x, y, z;
Point() { }
Point(int x, int y, int z) : x(x), y(y), z(z) { }
void readPoint()
{
scanf("%d %d %d", &x, &y, &z);
}
};
struct TwoSAT
{
int n;
vector<int>G[M*2];
bool mark[M*2];
int S[M*2], 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 < (int)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 y)
{
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;
}
};
Point poi[2*M];
int dcmp(double a)
{
if(fabs(a)<eps) return 0;
return a<0?-1:1;
}
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)+1.0*(a.z-b.z)*(a.z-b.z));
}
int ok(int n, double R)
{
TwoSAT temp;
temp.init(n);
for(int i = 0; i < 2*n; ++i)
for(int j = i+1; j < 2*n; ++j)
if(dcmp(dis(poi[i], poi[j])-2*R)<0)
{
temp.add_clause(i^1, j^1);
}
return temp.solve();
}
int main ()
{
int n;
while(~scanf("%d", &n))
{
for(int i = 0; i < 2*n; ++i)
poi[i].readPoint();
double l = 0.0, r = dis(Point(0,0,0), Point(10000,10000,10000)), mid;
while(r-l>eps)
{
mid = (r+l)/2;
if(ok(n, mid))
l = mid;
else
r = mid;
}
double ans = (int)(mid*1000+0.5)/1000.0;//注意!!!
if(!ok(n, ans)) ans-=0.001;
printf("%.3lf\n", ans);
}
return 0;
}
zoj 3717 - Balloon(2-SAT)的更多相关文章
- ZOJ 3717 Balloon ( TLE )
正解2-SAT. 我用DLX想搜一搜的,结果TLE了…… 没什么遗憾,最起码我尝试过了. 扔个代码留作纪念. #include <cstdio> #include <cstring& ...
- ZOJ 3717
这题是二分+2SAT. 总结一下SAT题的特征.首先,可能会存在二选一的情况,然后会给出一些矛盾.据这些矛盾加边,再用SAT判定. 这一道题好像不能直接用printf("%0.3lf&quo ...
- zoj 3981 Balloon Robot
https://vjudge.net/problem/ZOJ-3981 题意: 有m个座位,其中n个队伍坐在这些位置上,一个队伍一个座位.当一个队A了题之后,他们们会得到气球,假设他们在a时刻A题,但 ...
- ZOJ 3717 二分+2-sat判定。
好久没有2-sat了,此题当复习之用,二分求最大值+2-sat判断可行,此题主要跪于题意:The results should be rounded to three decimal places. ...
- ZOJ - 3981 - Balloon Robot (思维)
参考自:https://blog.csdn.net/qq_36553623/article/details/78445558 题意: 第一行三个数字n, m, q表示有m个座位围成一个环,n个队伍,q ...
- ZOJ 3981 && 2017CCPC秦皇岛 A:Balloon Robot(思维题)
A - Balloon Robot Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Sub ...
- zoj 2104 Let the Balloon Rise(map映照容器的应用)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2104 题目描述: Contest time again! Ho ...
- zoj 2104 Let the Balloon Rise
Let the Balloon Rise Time Limit: 2 Seconds Memory Limit: 65536 KB Contest time again! How excit ...
- [ZOJ 1003] Crashing Balloon (dfs搜索)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3 题目大意:给你a,b两个数,问当b由约数1到100组成时,a能否由其 ...
随机推荐
- SQL Server创建复合索引时,复合索引列顺序对查询的性能影响
说说复合索引 写索引的博客太多了,一直不想动手写,有一下两个原因:一是觉得有炒剩饭的嫌疑,有兄弟曾说:索引吗,只要在查询条件上建索引就行了,真的可以这么暴力吗?二来觉得,索引是个非常大的话题,很难概括 ...
- 在子线程中new Handler报错--Can't create handler inside thread that has not called Looper.prepare()
在子线程中new一个Handler为什么会报以下错误? java.lang.RuntimeException: Can't create handler inside thread that has ...
- java中的数据类型
通常情况下,为了方便物品的存储,我们会规定每个盒子可以存放的物品种类,就好比在"放臭袜子的盒子"里我们是不会放"面包"的!同理,变量的存储也讲究"分门 ...
- Android开发学习---template requires a minimum SDK version of at least 7,build target API version of 14
adt 22.6.3的bug 当adt更新到22.6.3,其编辑器中最低支持api7,即android 2.1,这里可能是google故意这么做的,也可能是其bug.其target sdk 和comp ...
- 清除oracle中的缓存(具体细节未知, 慎用)
oracle中的缓存主要是指SGA中的:1.share pool2.database buffer cache清空命令如下:首先要登录到sqlplus命令下,输入如下命令即可:SQL> alte ...
- js中判断true和false的情况
- yarn container启动失败
在yarn资源管理的集群上运行spark程序,无法读取的数据多与少,都会报这个错误,但是其他程序在集群上能够正常运行. 16/11/14 00:13:44 WARN cluster.YarnSched ...
- 获得URL含有中文出现乱码解决
如: http://www.htmlx.culub/?searchWord=工商代理 当获取链接中所对应searchWord的值时,出现 '%E5%B7%A5%E5%95%86%E4%BB%A3%E7 ...
- artTemplate里一个比不上jQuery tmpl模板的地方就是放一个数组进去它不会自动循环.
artTemplate里一个比不上jQuery tmpl模板的地方就是放一个数组进去它不会自动循环.
- softmax分类器+cross entropy损失函数的求导
softmax是logisitic regression在多酚类问题上的推广,\(W=[w_1,w_2,...,w_c]\)为各个类的权重因子,\(b\)为各类的门槛值.不要想象成超平面,否则很难理解 ...