就是给出非常多点,要求分成两个集合,在同一个集合里的点要求随意两个之间的距离都大于5。

求一个集合。它的点数目是全部可能答案中最少的。

直接从随意一个点爆搜,把它范围内的点都丢到跟它不一样的集合里。不断这样搞即可了。

由于可能有非常多相离的远,把每次搜索得到的那个最小的数目加起来就可以。

因为全部点都格点上,所以仅仅须要枚举一个点可以包括的点是否在数据中存在就可以。

当然也能够用一棵树直接去找。这我并不会。。

时间复杂度是81nlogn

湖大的OJ机器太老。。

。还要开栈。

。UVA LIVE随便交就过了。

#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
struct Point
{
int x,y;
Point(){}
Point(int x,int y)
{
this->x=x;
this->y=y;
}
bool operator <(Point one)const
{
if(x!=one.x)
return x<one.x;
return y<one.y;
}
};
vector<Point>bx;
int dis2(Point one,Point two)
{
return (one.x-two.x)*(one.x-two.x)+(one.y-two.y)*(one.y-two.y);
}
void create()
{
for(int i=-5;i<=5;i++)
for(int j=-5;j<=5;j++)
if(dis2(Point(i,j),Point(0,0))<=25)
bx.push_back(Point(i,j));
}
map<Point,int>mp;
Point cnt;
void dfs(Point v)
{
int n=bx.size(),no=mp[v];
map<Point,int>::iterator it;
for(int i=0;i<n;i++)
{
Point t=Point(v.x+bx[i].x,v.y+bx[i].y);
it=mp.find(t);
if(it!=mp.end()&&it->second==0)
{
if(no==1)
{
it->second=2;
cnt.y++;
}
else
{
it->second=1;
cnt.x++;
}
dfs(t);
}
}
}
int main()
{
//int size = 256 << 20; // 256MB
// char *p = (char*) malloc (size) + size;
// __asm__ ("movl %0, %%esp\n" :: "r" (p) );
create();
int n;
while(scanf("%d",&n)!=EOF)
{
while(n--)
{
Point t;
scanf("%d%d",&t.x,&t.y);
mp[t]=0;
}
map<Point,int>::iterator it;
int ans=0;
for(it=mp.begin();it!=mp.end();it++)
{
if(it->second==0)
{
it->second=1;
cnt.x=1;
cnt.y=0;
dfs(it->first);
if(cnt.x>cnt.y)
swap(cnt.x,cnt.y);
ans+=cnt.x;
}
}
cout<<ans<<endl;
}
return 0;
}

Time Limit: 15000ms, Special Time Limit:37500ms, Memory Limit:65536KB
Total submit users: 9, Accepted users: 6
Problem 13307 : No special judgement
Problem description

The Andromeda galaxy is expected to collide with our Milky Way in about 3.8 billion years. The collision will probably be a merging of the two galaxies, with no two stars actually colliding. That is because the distance between stars in both galaxies is
so huge. Professor Andrew is building a computational model to predict the possible outcomes of the collision and needs your help! A set of points in the two dimensional plane is given, representing stars in a certain region of the already merged galaxies.
He does not know which stars came originally from which galaxy; but he knows that, for this region, if two stars came from the same galaxy, then the distance between them is greater than 5 light years. Since every star in this region comes either from Andromeda
or from the Milky Way, the professor also knows that the given set of points can be separated into two disjoint subsets, one comprising stars from Andromeda and the other one stars from the Milky Way, both subsets with the property that the minimum distance
between two points in the subset is greater than 5 light years. He calls this a good separation, but the bad news is that there may be many different good separations. However, among all possible good separations there is a minimum number of stars a subset
must contain, and this is the number your program has to compute.



Input

The first line contains an integer N (1 ≤ N ≤ 5×10^4) representing the number of points in the set. Each of the next N lines describes a different point with two integers X and Y (1 ≤ X,Y ≤ 5 × 10^5), indicating its coordinates, in light years. There are
no coincident points, and the set admits at least one good separation.

Output

Output a line with an integer representing the minimum number of points a subset may have in a good separation.

Sample Input
Sample input 1
6
1 3
9 1
11 7
5 7
13 5
4 4 Sample input 2
2
10 10
50 30
Sample Output
Sample output 1
2 Sample output 2
0
Problem Source
ICPC Latin American Regional ?

2014

uva live 6827 Galaxy collision的更多相关文章

  1. DFS --- HNU 13307 Galaxy collision

    Galaxy collision Problem's Link Mean: 给定二维坐标平面内的n个整数点,让你把这n个点划分为两个集合,同一集合内的所有点必须两两距离大于5,求这两个集合的元素个数之 ...

  2. uva 1382 - Distant Galaxy

    题目连接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=91208#problem/G 题意:  给出平面上的n个点,找出一个矩形,使得边 ...

  3. UVa LA 3695 - Distant Galaxy 前缀和,状态拆分,动态规划 难度: 2

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  4. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  5. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  6. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  7. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  8. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

  9. UVA数学入门训练Round1[6]

    UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...

随机推荐

  1. HDU3085 Nightmare Ⅱ

    题目: Last night, little erriyue had a horrible nightmare. He dreamed that he and his girl friend were ...

  2. Swagger UI改造 增加 Token验证、显示控制器注释、自定义泛型缓存应用、

    /// <summary> /// Swagger 增加 Token 选项和控制器描述 /// </summary> public class CustomOperationF ...

  3. Zeppelin0.6.2+sparkR2.0.2环境搭建

    0.序 先吐槽一下网上旧版本的Zeppelin和R的安装,让我折腾了几个小时. 不过最终还是调通了也不容易,其实我现在一点R都没有学呢,只是刚看了一节课,但是这个工具既然出现在了Spark中,我想它还 ...

  4. mybatis parameterType报错:There is no getter for property named 'xxx' in 'class java.lang.String'

    方法1: 当parameterType = "java.lang.String" 的时候,参数读取的时候必须为 _parameter 方法2: 在dao层的时候,设置一下参数,此方 ...

  5. Oracle 生成数据字典

    SELECT ROWNUM 序号,A.COLUMN_NAME AS "字段名称",B.comments AS "字段描述", A.DATA_TYPE as 字段 ...

  6. Windows phone开发数据绑定系列(1)--了解数据绑定

    (部分内容参考MSDN文档) 数据绑定是在应用程序UI与业务逻辑之间建立连接的过程.通过数据绑定的方式实现了后台数据和前台UI元素的关联, 为用户提供了更好地交互体验. 数据绑定一般有以下几种体现方式 ...

  7. OPPO R11 R11plus系列 解锁BootLoader ROOT Xposed 你的手机你做主

    首先准备好所有要使用到的文件 下载链接:https://share.weiyun.com/5WgQHtx 步骤1. 首先安装驱动 解压后执行 Install.bat 部分电脑需要禁用驱动程序签名才可以 ...

  8. angular2之组件通讯

    定义父组件,在父组件中以路由插座形式引入子组件,定义相关输入输出属性 可以在同一模块内部定义多个组件,将一个组件引入另一个组件中去:也可以该模块整体导出,将该模块导入到其他模块,这样此模块中的组件就能 ...

  9. STL之map篇

    度熊所居住的 D 国,是一个完全尊重人权的国度.以至于这个国家的所有人命名自己的名字都非常奇怪.一个人的名字由若干个字符组成,同样的,这些字符的全排列的结果中的每一个字符串,也都是这个人的名字.例如, ...

  10. Unicode转换为UTF-8过程Demo

    碎碎念:这几天在学习Python对Unicode的支持 上学的时候,计算机基础课上总能听到老师讲什么字节,字符,Unicode,UTF-8吧啦吧啦一堆,反正我是只记住了名字,至于具体这些名字所表达的含 ...