博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Ural 2036. Intersect Until You're Sick of It 计算几何
阅读量:6493 次
发布时间:2019-06-24

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

2036. Intersect Until You're Sick of It

题目连接:

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 
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
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
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
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;}

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

你可能感兴趣的文章
java web中对json的使用
查看>>
TYVJ P1051 选课 Label:多叉转二叉&&树形dp(虐心♥)
查看>>
将数据库中提取出来的数据在后台进行分页处理
查看>>
bzoj1034
查看>>
百度地图 鼠标绘制,获取矩形,多边形的顶点经纬度
查看>>
回文树模板
查看>>
struts2之防止表单重复提交
查看>>
【转】Netty系列之Netty并发编程分析
查看>>
cf591d
查看>>
图片存储系统TFS
查看>>
MYSQL备份与恢复
查看>>
贪心/数学 Codeforces Round #212 (Div. 2) A. Two Semiknights Meet
查看>>
Python类__call__()方法
查看>>
「小程序JAVA实战」 小程序wxss样式文件的使用(七)
查看>>
容斥定理,皮克公式
查看>>
[LeetCode] Rotate List
查看>>
git+idea
查看>>
集合异常测试
查看>>
cocos2d游戏开发,常用工具集合
查看>>
FatTree胖树拓扑结构
查看>>