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 = ...
随机推荐
- Autobiography
Autobiography My name is Donggongdechen. I am ** years old. I was born in XuChang, HeNan province, t ...
- Java压缩技术(二) ZIP压缩——Java原生实现
原文:http://snowolf.iteye.com/blog/642298 去年整理了一篇ZLib算法Java实现(Java压缩技术(一) ZLib),一直惦记却没时间补充.今天得空,整理一下ZI ...
- go之for循环
一.基于计数器的迭代 格式 for 初始化语句; 条件语句; 修饰语句{} 实例 package main import "fmt" func main(){ for i:=0;i ...
- CentOS7 搭建Kafka(三)工具篇
CentOS7 搭建Kafka(三)工具篇 做为一名懒人,自然不喜欢敲那些命令,一个是容易出错,另外一个是懒得记,能有个工具就最好了,一查还挺多,我们用个最主流的Kafka Manager Kafka ...
- CORS 和 JSONP
跨域资源共享(CORS) 它允许浏览器向跨源服务器,发出XMLHttpRequest请求,从而克服了AJAX只能同源使用的限制. CORS(Cross-Origin Resource Sharing) ...
- Android6.0以上版本获取本机蓝牙地址
Android6.0以上版本使用BluetoothAdapter.getDefaultAdapter().getAddress()是获取不到正确的蓝牙地址的,返回的值都是02:00:00:00:00: ...
- Leetcode0037--Sudoku Solver 数独游戏
[转载请注明]http://www.cnblogs.com/igoslly/p/8719622.html 来看一下题目: Write a program to solve a Sudoku puzzl ...
- Sql语句优化-查询两表不同行NOT IN、NOT EXISTS、连接查询Left Join
在实际开发中,我们往往需要比较两个或多个表数据的差别,比较那些数据相同那些数据不相同,这时我们有一下三种方法可以使用:1. IN或NOT IN,2. EXIST或NOTEXIST,3.使用连接查询(i ...
- 基于 CC2530 的温度采集系统(未定稿)
前言 最近在自学 Zigbee,每天的主要是任务是:看博客,看 CC2530 的 datasheet 和实践,熟悉片上的 SFR 以及控制板子. 学和做内容包括:IO.外部中断.Timer1/3/4. ...
- CXF-JAX-RS开发(二)spring整合CXF-JAX-RS
一.创建maven工程[Packaging:war] 1.目录结构 2.坐标书写 二.导入依赖和tomcat服务器插件 <dependencies> <!-- CXF --> ...