ZOJ 3717
这题是二分+2SAT.
总结一下SAT题的特征。首先,可能会存在二选一的情况,然后会给出一些矛盾。据这些矛盾加边,再用SAT判定。
这一道题好像不能直接用printf("%0.3lf"),因为这个是四舍五入的,这道题好像不能四舍五入,只好选减去0.0005再按这个格式输出了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stdlib.h>
#define oo 1000000007
#define eps 1e-4
using namespace std;
const int MAXN=;
const int MAXM=;
struct b{
int x,y,z;
}ball[MAXN];
double dis[MAXN][MAXN];
int head[MAXN],dfn[MAXN],low[MAXN],tot,stop,indx,belong[MAXN],pat;
int st[MAXN];
bool stack[MAXN];
int n;
struct e{
int u,v;
int next;
}edge[MAXM]; void addedge(int u,int v){
edge[tot].u=u;
edge[tot].v=v;
edge[tot].next=head[u];
head[u]=tot++;
} void tarjan(int u){
int v;
dfn[u]=low[u]=++indx;
st[stop++]=u;
stack[u]=true;
for (int e=head[u];e!=-;e=edge[e].next){
v=edge[e].v;
if (dfn[v]==) {
tarjan(v) ;
low[u] = min(low[u], low[v]) ;
}
else if (stack[v]) {
low[u] = min(low[u], dfn[v]) ;
}
}
if (dfn[u] == low[u]) {
pat++;
do{
v = st[--stop];
belong[v]=pat;
stack[v]=false;
}while(u!= v);
}
} bool slove(double leng){
int a,b; tot=; indx=; stop=; pat=-;
memset(head,-,sizeof(head));
for(int i=;i<n;i++){
a=i;
for(int j=i+;j<n;j++){
b=j;
if(leng*>dis[a*][b*]){
addedge(*a+,b*);
addedge(b*+,a*);
}
if(leng*>dis[a*][b*+]){
addedge(a*+,b*+);
addedge(b*,a*);
}
if(leng*>dis[a*+][b*]){
addedge(a*,b*);
addedge(b*+,a*+);
}
if(leng*>dis[a*+][b*+]){
addedge(a*,b*+);
addedge(b*,a*+);
}
}
}
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
memset(stack,false,sizeof(stack));
memset(belong,-,sizeof(belong));
for(int i=;i<*n;i++){
if(dfn[i]==){
tarjan(i);
}
}
bool flag=true;
for(int i=;i<n;i++){
if(belong[i*]==belong[i*+]){
flag=false;
break;
}
}
return flag;
} int main(){
double xi,yi,zi;
while(scanf("%d",&n)!=EOF){
for(int i=;i<*n;i++){
scanf("%d%d%d",&ball[i].x,&ball[i].y,&ball[i].z);
i++;
scanf("%d%d%d",&ball[i].x,&ball[i].y,&ball[i].z);
}
double high=oo,lown=; double tmp;
for(int i=;i<*n;i++){
for(int j=i;j<*n;j++){
xi=ball[i].x-ball[j].x;
yi=ball[i].y-ball[j].y;
zi=ball[i].z-ball[j].z;
tmp=sqrt(xi*xi+yi*yi+zi*zi);
dis[i][j]=dis[j][i]=tmp;
}
}
double ans;
while(lown<high-eps){
double mid=(high+lown)/;
if(slove(mid)){
ans=mid;
lown=mid;
}
else high=mid;
}
printf("%0.3lf\n",ans-0.0005);
}
return ;
}
ZOJ 3717的更多相关文章
- zoj 3717 - Balloon(2-SAT)
裸的2-SAT,详见刘汝佳训练指南P-323 不过此题有个特别需要注意的地方:You should promise that there is still no overlap for any two ...
- ZOJ 3717 Balloon ( TLE )
正解2-SAT. 我用DLX想搜一搜的,结果TLE了…… 没什么遗憾,最起码我尝试过了. 扔个代码留作纪念. #include <cstdio> #include <cstring& ...
- ZOJ 3717 二分+2-sat判定。
好久没有2-sat了,此题当复习之用,二分求最大值+2-sat判断可行,此题主要跪于题意:The results should be rounded to three decimal places. ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
随机推荐
- bzoj 4481 [ Jsoi 2015 ] 非诚勿扰 —— 期望
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4481 太弱了这种题都要看半天TJ...:https://blog.csdn.net/chai ...
- E20170906-mk
portrait n. 肖像,肖像画; 模型,标本; 半身雕塑像; 人物描写; orientation n. 方向,定位,取向,排列方向; 任职培训; (外交等的) 方针[态度]的确定; 环境判 ...
- JS判断浏览器类型和详细区分IE各版本浏览器
今天用到JS判断浏览器类型,于是就系统整理了一下,便于后期使用. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 ...
- linux的shell函数参数
在Shell中,调用函数时可以向其传递参数.在函数体内部,通过 $n 的形式来获取参数的值,例如,$1表示第一个参数,$2表示第二个参数... 带参数的函数示例: #!/bin/bash funWit ...
- JNI学习积累之一 ---- 常用函数大全
主要资料来源: 百度文库的<JNI常用函数> . 同时对其加以了补充 . 要素 :1. 该函数大全是基于C语言方式的,对于C++方式可以直接转换 ,例如,对于生成一个jstring类型的 ...
- POJ 3322 Bloxorz I
首先呢 这个题目的名字好啊 ORZ啊 如果看不懂题意的话 请戳这里 玩儿几盘就懂了[微笑] http://www.albinoblacksheep.com/games/bloxorz 就是这个神奇的木 ...
- 脑洞大开加偏执人格——可持久化treap版的Link Cut Tree2
试了一下先上再下的Treap方式,很高兴,代码变短了,但是,跑的变慢了!!!其实慢得不多,5%左右.而且这个版本的写法不容易写错..只要会一般可持久化Treap的人写着都不难...就是相对于(压行的) ...
- view在使用shape属性加圆角的同时,用代码修改其他background属性(例如颜色)不生效
项目中一个TextView控件设置了shape属性,给其加了圆角,如下: houlder.mtxtGovernmentType.setBackgroundResource(R.drawable.tv_ ...
- vegas pro 15解决导入的视频和音频有噪声问题,亲测可行
中文步骤: 按住Shift->点击选项->首选项,松开Shift 点击右上角"内部"选项卡,在最下面的搜索栏输入SO4 找到第二项Enable So4 Compound ...
- ASP.NET刷新页面的六种方法
第一: private void Button1_Click( object sender, System.EventArgs e ) { Response.Redirect( Requ ...