Ural 2036. Intersect Until You're Sick of It 计算几何
2036. Intersect Until You're Sick of It
题目连接:
http://acm.timus.ru/problem.aspx?space=1&num=2036
Description
Ural contests usually contain a lot of geometry problems. Many participants do not conceal their discontent with such disbalance. Still, we have decided not to break the tradition and give you an unbalanced contest. Let’s start!
Consider an iterative process for a set of points on a plane. Every iteration consists of three steps:
Draw a line through every pair of different points.
Find all intersections of all pairs of different non-parallel lines.
Merge the initial set of points with the set of intersection points and go to step one.
After each iteration, the number of points either increases or stays the same.
You are given a set of points. Iterations repeat while the number of points increases. How many points will be in the set after the end of this iterative process?
Input
The first line contains an integer n (1 ≤ n ≤ 100000). Further input describes n different points. For every point, you are given a pair of integer coordinates whose absolute value does not exceed 108.
Output
If the process is infinite, print “oo” (two lowercase Latin letters ‘o’), otherwise print the number of points in the set after the end of the process.
Sample Input
4
0 0
0 1
1 0
1 1
Sample Output
5
Hint
题意
给你n个点,然后进行下列操作:
1.两两点连线
2.找到所有不平行直线所构成的交点
3.把所有找到的点和原来的点合并,如果点数增加,再进行1操作;否则break
输出最后点的数量。
可能是无限多。
题解:
无限多的情况很多,我们来考虑特殊情况,即有解的:
显然所有点都是在一条直线上,这个答案是n
显然如果只有一个点不在直线上,这个答案也是n
有两个点不在直线上,那么答案可能是n,也有可能是n+1.
基本上情况就这些了,讨论一下,然后求解即可。
数据:
Anti-WA #51:
4
0 0
2 0
1 1
1 2
Answer: oo
Anti-WA #52:
4
0 0
1 2
2 2
3 0
Answer: oo
代码
#include <bits/stdc++.h>
using namespace std;
const int N=100010;
const int inf=1e9;
struct POINT
{
long long x;
long long y;
POINT(long long a=0, long long b=0) { x=a; y=b;} //constructor
bool operator<(const POINT &A)const{
if(A.x==x)return A.y<y;
return A.x<x;
}
};
long long multiply(POINT sp,POINT ep,POINT op)
{
return((sp.x-op.x)*(ep.y-op.y)-(ep.x-op.x)*(sp.y-op.y));
}
long long multiply(POINT A,POINT B,POINT C,POINT D)
{
long long x1 = A.x-B.x;
long long y1 = A.y-B.y;
long long x2 = C.x-D.x;
long long y2 = C.y-D.y;
return x1*y2-x2*y1;
}
POINT P[N];
int n;
int solve(POINT st)
{
vector<POINT> ans,ret;
if(st.x==0&&st.y==0)
{
return inf;
}
for(int i=1;i<=n;i++)
{
if(multiply(P[i],st,P[1])!=0) ans.push_back(P[i]);else ret.push_back(P[i]);
}
if(ans.size()<=1)
{
return n;
}
else
{
for(int i=2;i<ans.size();i++)
if(multiply(ans[0],ans[1],ans[i])!=0) return inf;
for(int i=0;i<ret.size();i++)
if(multiply(ret[i],ans[1],ans[0])==0)
return n;
if(ans.size()>2)
{
return inf;
}
else
{
long long t1=multiply(ans[0],st,P[1]),t2=multiply(ans[1],st,P[1]);
if(t1>0&&t2>0||t1<0&&t2<0)
{
return inf;
}
else
{
POINT pp;
int flag=1,f1=1,f2=1;
for(int i=0;i<ret.size();i++)
{
if(multiply(ret[i],ans[1],ans[0])<0) f1=0;
if(multiply(ret[i],ans[1],ans[0])>0) f2=0;
}
if(f1||f2) flag=0;
return n+flag;
}
}
}
}
long long X(POINT A,POINT B){
return A.x*B.y-A.y*B.x;
}
long long sq(long long A){
return A*A;
}
long long dis(POINT A,POINT B){
return sq(A.x-B.x)+sq(A.y-B.y);
}
bool ok4(){
long long tmp = multiply(P[1],P[2],P[3],P[4]);
if(tmp!=0)return 0;
tmp = multiply(P[1],P[2],P[3]);
if(tmp==0)return 0;
long long dis1 = dis(P[1],P[2]);
long long dis2 = dis(P[3],P[4]);
if(dis1!=dis2)return 0;
return 1;
}
bool ok14(){
long long tmp = multiply(P[1],P[2],P[3]);
if(tmp==0)return 1;
long long dis1 = dis(P[1],P[2]);
long long dis2 = dis(P[3],P[4]);
if(dis1==dis2)return 1;
return 0;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%I64d%I64d",&P[i].x,&P[i].y);
}
for(int i=2;i<=n;i++)
P[i].x-=P[1].x,P[i].y-=P[1].y;
P[1].x=P[1].y=0;
int tmp=inf;
if(n<=3)
{
printf("%d\n",n);
return 0;
}
if(n==4){
sort(P+1,P+1+n);
do{
if(ok4()){
printf("5\n");
return 0;
}
}while(next_permutation(P+1,P+1+n));
sort(P+1,P+1+n);
do{
if(ok14()){
printf("4\n");
return 0;
}
}while(next_permutation(P+1,P+1+n));
printf("oo\n");
return 0;
}
if(n<=5)
{
for(int o=2;o<=n;o++)
{
tmp=min(tmp,solve(P[o]));
}
}
else
{
int flag=0;
POINT stt;
stt.x=stt.y=0;
for(int i=2;i<=6;i++)
{
for(int j=i+1;j<=6;j++)
{
for(int k=j+1;k<=6;k++)
if(multiply(P[i],P[j],P[1])==0&&multiply(P[i],P[k],P[1])==0)
{
stt=P[i];
flag=1;
break;
}
if(flag) break;
}
if(flag) break;
}
tmp=solve(stt);
}
if(tmp==inf) printf("oo\n");else printf("%d\n",tmp);
return 0;
}
Ural 2036. Intersect Until You're Sick of It 计算几何的更多相关文章
- URAL 2036 Intersect Until You're Sick of It 形成点的个数 next_permutation()函数
A - Intersect Until You're Sick of It Time Limit:500MS Memory Limit:65536KB 64bit IO Format: ...
- URAL 2025. Line Fighting (math)
2025. Line Fighting Time limit: 1.0 second Memory limit: 64 MB Boxing, karate, sambo- The audience i ...
- LINQ to SQL语句(8)之Concat/Union/Intersect/Except
适用场景:对两个集合的处理,例如追加.合并.取相同项.相交项等等. Concat(连接) 说明:连接不同的集合,不会自动过滤相同项:延迟. 1.简单形式: var q = ( from c in db ...
- 【oracle】union、union all、intersect、minus 的用法及区别
一.union与union all 首先建两个view create or replace view test_view_1 as as c from dual union as c from dua ...
- oracle之集合操作函数---minus、union、intersect
集合操作符专门用于合并多条select语句的结果,包括:UNION,UNION ALL,INTERSECT,MINUS.当使用集合操作函数时,需保证数据集的字段数据类型和数目一致. 使用集合操作符需要 ...
- LINQ的Intersect方法
找到两个集合中交集部分: source code: IEnumerable<int> a = new List<int>{ { }, { }, { } }; IEnumerab ...
- Linq连接查询之左连接、右连接、内连接、全连接、交叉连接、Union合并、Concat连接、Intersect相交、Except与非查询
内连接查询 内连接与SqL中inner join一样,即找出两个序列的交集 Model1Container model = new Model1Container(); //内连接 var query ...
- List之Union(),Intersect(),Except()
http://www.cnblogs.com/qinpengming/archive/2012/12/03/2800202.html List之Union(),Intersect(),Except() ...
- Sql中的并(UNION)、交(INTERSECT)、差(minus)、除去(EXCEPT)详解
UNION 查询选修了180101号或180102号课程或二者都选修了的学生学号.课程号和成绩. (SELECT 学号, 课程号, 成绩 FROM 学习 WHERE 课程号='180101' ...
随机推荐
- bzoj千题计划250:bzoj3670: [Noi2014]动物园
http://www.lydsy.com/JudgeOnline/problem.php?id=3670 法一:KMP+st表 抽离nxt数组,构成一棵树 若nxt[i]=j,则i作为j的子节点 那么 ...
- 小记 HTML5 file对象
<input type="file" id="myfile" multiple> 这是个很普通的 file 上传组件,multiple 是支持多选, ...
- [转载]嵌入式C语言中的Doxygen注释模板
http://blog.csdn.net/willerency/article/details/7083953 嵌入式C语言开发中通常使用Doxygen进行文档的生成.Doxygen支持多种格式,非常 ...
- CSS-3 圆角Border-radius 的使用
那么早些年 圆角其实是有的,后来的草案中将它去掉了,现在从CSS3开始,又加入了回来.可以看出圆角的使用还是非常广泛的. 那么在圆角还没有被加入进来之前,我们要实现圆角的效果,可能就是需要IMG图片来 ...
- 关于Spring mvc注解中的定时任务的配置
关于spring mvc注解定时任务配置 简单的记载:避免自己忘记,不是很确定我理解的是否正确.有错误地方望请大家指出. 1,定时方法执行配置: (1)在applicationContext.xml中 ...
- 【GDOI2018】所有题目和解题报告
使用说明:题意和数据范围都只是回忆内容,仅供参考.题解陆续补上. Day 1 第一题 题意:给定n个数字,要求划分成k的连续段使得每个连续段内的数字之和相同,求最大的k.n,Σai<=10^6. ...
- 第9月第3天 uilabel contentscale
1. http://blog.csdn.net/u012703795/article/details/43706449
- Python人工智能之路 - 第一篇 : 你得会点儿Python基础
Python 号称是最接近人工智能的语言,因为它的动态便捷性和灵活的三方扩展,成就了它在人工智能领域的丰碑 走进Python,靠近人工智能 一.编程语言Python的基础 之 "浅入浅出&q ...
- 使用 scm-manager 搭建 git/svn 代码管理仓库(一)
1.在官网上下载scm-manager 下载地址 https://www.scm-manager.org/download/ 选择下载文件 2. 配置java 环境 参照文章:https://jin ...
- 善用backtrace解决大问题【转】
转自:https://www.2cto.com/kf/201107/97270.html 一.用途: 主要用于程序异常退出时寻找错误原因 二.功能: 回溯堆栈,简单的说就是可以列出当前函数调用关系 三 ...