uva live 6827 Galaxy collision
就是给出非常多点,要求分成两个集合,在同一个集合里的点要求随意两个之间的距离都大于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 |
| 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 |
| 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 |
| Sample Output |
Sample output 1 |
| Problem Source |
| ICPC Latin American Regional ?
2014 |
uva live 6827 Galaxy collision的更多相关文章
- DFS --- HNU 13307 Galaxy collision
Galaxy collision Problem's Link Mean: 给定二维坐标平面内的n个整数点,让你把这n个点划分为两个集合,同一集合内的所有点必须两两距离大于5,求这两个集合的元素个数之 ...
- uva 1382 - Distant Galaxy
题目连接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=91208#problem/G 题意: 给出平面上的n个点,找出一个矩形,使得边 ...
- UVa LA 3695 - Distant Galaxy 前缀和,状态拆分,动态规划 难度: 2
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- 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 ...
随机推荐
- POJ 1111(数字很吉利嘛) 简单BFS
Image Perimeters Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8594 Accepted: 5145 Desc ...
- Vue页面间传值,以及客户端数据存储
初学Vue,遇到了页面传值的问题,大概网上学习了解了一下,在此跟大家分享一下学习心得,欢迎批评指正. 一.参数传值 如果是简单的页面传值,比如传一个id到详情页等等,推荐使用参数传值. 这里页面是通过 ...
- Laravel5.1 学习笔记1, 目录结构和命名空间(待修)
自从用 Laravel4做了个小网站,使用了数据库ORM Eloquent, 就放下了一段时间,想不到这个与Asp.net MVC 有着异曲同工之妙的框架已经出了下个版本,而且还有不小的改动,因此不得 ...
- buf.readInt32LE函数详解
offset {Number} 0 noAssert {Boolean} 默认:false 返回:{Number} 从该 Buffer 指定的带有特定尾数格式(readInt32BE() 返回一个较大 ...
- Android嵌入式(初稿)--路漫漫其修远兮,吾将上下而求索
- Android上UDP组播无法接收数据的问题
最近,想做一个跨平台的局域网的文件传输软件,思路是组播设备信息,TCP连接传输文件.于是进行了一次简单的UDP组播测试,发现Android对于UDP组播接收数据的支持即极为有限. 部分代码如下 pac ...
- SLAM: 单目视觉SLAM的方案分类《机器人手册》
摘抄知乎上一段有趣的话: 如果你出门问别人『学习SLAM需要哪些基础?』之类的问题,一定会有很热心的大哥大姐过来摸摸你的头,肩或者腰(不重要),一脸神秘地从怀里拿出一本比馒头还厚的<Mu ...
- js 中this到底指向哪里?
其实js的this指向很简单.我们记住下面3种情况. this 指向的是浏览器中的window.代码如下: function fn(){ this.name='yangkun'; this.age=2 ...
- 日记——OI历程
学OI也一年多了(2015.12-),一直没学出个像样的东西.相比dalao们,我还是弱爆了. ljj,qyf,yyf三位三区dalao. xxy,myj两位三区学长dalao. 稍微总结一下前一段时 ...
- [tyvj1935 Poetize3]导弹防御塔 (二分图多重匹配)
传送门 Description Freda控制着N座可以发射导弹的防御塔.每座塔都有足够数量的导弹,但是每座塔每次只能发射一枚.在发射导弹时,导弹需要T1秒才能从防御塔中射出,而在发射导弹后,发射这枚 ...
