博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2296 Map Labeler(二分+2SAT可行性判断)
阅读量:6721 次
发布时间:2019-06-25

本文共 3477 字,大约阅读时间需要 11 分钟。

Map Labeler
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1023   Accepted: 337

Description

Map generation is a difficult task in cartography. A vital part of such task is automatic labeling of the cities in a map; where for each city there is text label to be attached to its location, so that no two labels overlap. In this problem, we are concerned with a simple case of automatic map labeling.
Assume that each city is a point on the plane, and its label is a text bounded in a square with edges parallel to x and y axis. The label of each city should be located such that the city point appears exactly in the middle of the top or bottom edges of the label. In a good labeling, the square labels are all of the same size, and no two labels overlap, although they may share one edge. Figure 1 depicts an example of a good labeling (the texts of the labels are not shown.)
Given the coordinates of all city points on the map as integer values, you are to find the maximum label size (an integer value) such that a good labeling exists for the map.

Input

The first line contains a single integer t (1 <= t <= 10), the number of test cases. Each test case starts with a line containing an integer m (3 ≤ m ≤ 100), the number of cities followed by m lines of data each containing a pair of integers; the first integer (X) is the x and the second one (Y) is the y coordinates of one city on the map (-10000 ≤X, Y≤ 10000). Note that no two cities have the same (x, y) coordinates.

Output

The output will be one line per each test case containing the maximum possible label size (an integer value) for a good labeling.

Sample Input

161 12 33 24 410 42 5

Sample Output

2

Source

 
 
题目链接:
题型:二分+可行性判断。

二分+2-SAT可行性判断

题意:给你n个点,要你在这n个点上放一个正方形,点
只能在正方形的上边或下边的中点上,所有正方形大小一样,
不能重叠,求最大的正方形。。。

如果abs(s[i].x-s[j].x)>=r则可以随便放

如果 abs[s[i].x-s[j].y)<r;
   如果abs(s[i].y-s[j].y)<r,如果s[i].y==s[i].y则要求一个放上面一个放下面。
                            否则只能是上面的点放上面,下面的点放下面。
   如果r<=abs(s[i].y-s[j].y)<2*r,则除了上面的点放下方、下面的点放上方的情况都是可以的。

 

/*POJ  2296二分+2-SAT可行性判断题意:给你n个点,要你在这n个点上放一个正方形,点只能在正方形的上边或下边的中点上,所有正方形大小一样,不能重叠,求最大的正方形。。。如果abs(s[i].x-s[j].x)>=r则可以随便放如果 abs[s[i].x-s[j].y)
#include
#include
#include
#include
#include
#include
using namespace std;const int MAXN=220;bool visit[MAXN];queue
q1,q2;//vector建图方法很妙vector
>adj; //原图 //中间一定要加空格把两个'>'隔开vector
>radj;//逆图vector
>dag;//缩点后的逆向DAG图int n,cnt;int id[MAXN],order[MAXN],ind[MAXN];//强连通分量,访问顺序,入度void dfs(int u){ visit[u]=true; int i,len=adj[u].size(); for(i=0;i
=0;i--) if(!visit[order[i]]) { cnt++;//这个一定要放前面来 rdfs(order[i]); }}bool solvable(){ for(int i=0;i
=0) { mid=(left+right)>>1; adj.assign(2*n,vector
()); radj.assign(2*n,vector
()); //2*i表示放上面的,2*i+1表示放下面 for(int i=0;i
=mid)continue;//没有限制 if(abs(s[i].y-s[j].y)
s[j].y)//i放上面,j放下面 { adj[2*i+1].push_back(2*i); adj[2*j].push_back(2*j+1); radj[2*i].push_back(2*i+1); radj[2*j+1].push_back(2*j); } else { adj[2*i].push_back(2*i+1); adj[2*j+1].push_back(2*j); radj[2*i+1].push_back(2*i); radj[2*j].push_back(2*j+1); } } else if(abs(s[i].y-s[j].y)<2*mid)//上面的放下面和下面的放上面是不允许的 { if(s[i].y>s[j].y) { adj[2*i+1].push_back(2*j+1); adj[2*j].push_back(2*i); radj[2*j+1].push_back(2*i+1); radj[2*i].push_back(2*j); } else { adj[2*j+1].push_back(2*i+1); adj[2*i].push_back(2*j); radj[2*i+1].push_back(2*j+1); radj[2*j].push_back(2*i); } } } korasaju(); if(solvable()){ans=mid;left=mid+1;} else right=mid-1; } printf("%d\n",ans); } return 0;}

 

转载地址:http://akcmo.baihongyu.com/

你可能感兴趣的文章
借助mysql和DNS view实现智能DNS(centos6.3 x64环境)
查看>>
维纳-辛钦 (Wiener–Khinchin) 定理
查看>>
修改mysql的数据库密码
查看>>
Nginx安装图文
查看>>
解决DataNode启动不起来原因
查看>>
tomcat处理jsp页面的流程
查看>>
fedora的一些使用记录(二)
查看>>
为什么电子人的世界阴盛阳衰?
查看>>
解析InputStream流工具
查看>>
我的友情链接
查看>>
varchar2转clob
查看>>
ansible--循环
查看>>
Jenkins安装部署篇
查看>>
(原创)BFS广度优先算法,看完这篇就够了
查看>>
如何让Ubuntu服务器远离鬼影漏洞(GHOST)影响
查看>>
java反射之动态代理学习笔记
查看>>
ElasticSearch 安装 elasticsearch-analysis-ik分词器
查看>>
清空RMON统计的数据
查看>>
linux 自动化运维之Cobbler
查看>>
tomcat的安装过程
查看>>