A - Intersect Until You're Sick of It

Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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:
  1. Draw a line through every pair of different points.
  2. Find all intersections of all pairs of different non-parallel lines.
  3. 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 10 8.

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

input output
4
0 0
0 1
1 0
1 1

题意:给你n个不同的点,第一步,将任意两个点之间连成一条直线,第二步,直线相交可以形成新的点,然后再重复第一步,

问最后可以形成多少个点,如果无穷多个输出oo;

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull; #define MM(a,b) memset(a,b,sizeof(a));
#define inf 0x7f7f7f7f
#define FOR(i,n) for(int i=1;i<=n;i++)
#define CT continue;
#define PF printf
#define SC scanf const int mod=1000000007;
const int N=1e5+10; struct Point{
ll x,y;
void read(){
scanf("%lld%lld",&x,&y);}
bool operator<(const Point &a) const{
if(this->x!=a.x) return this->x<a.x;
else return this->y<a.y;
}
}p[N]; Point operator-(Point a,Point b)
{
return (Point){a.x-b.x,a.y-b.y};
} ll det(Point a,Point b)
{
return a.x*b.y-b.x*a.y;
} int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++) p[i].read();
if(n<=3) {printf("%d\n",n);return 0;}
sort(p+1,p+n+1);
if(n==4)
{
do
{
if(det(p[2]-p[1],p[4]-p[3])==0&&det(p[1]-p[4],p[2]-p[3])==0
&&det(p[3]-p[1],p[2]-p[1])!=0)
{printf("5\n");return 0;};
}while(next_permutation(p+1,p+n+1));
}
if(n==5)
{
do
{
if(det(p[2]-p[1],p[4]-p[3])==0&&det(p[1]-p[4],p[2]-p[3])==0&&
det(p[3]-p[1],p[2]-p[1])!=0&&det(p[4]-p[5],p[2]-p[5])==0&&
det(p[3]-p[5],p[1]-p[5])==0)
{printf("5\n");return 0;};
}while(next_permutation(p+1,p+n+1));
} for(int i=1;i<=2;i++)
for(int j=i+1;j<=4;j++)
{
int cnt=2;
for(int k=1;k<=n;k++) if(k!=i&&k!=j)
if(det(p[k]-p[i],p[k]-p[j])==0) cnt++;
if(cnt>=n-1) {printf("%d\n",n);return 0;}
}
printf("oo\n");
return 0;
}

 比赛分析:比赛时看到计算几何的题都不敢想,,,,比赛完了后稍微看了下题解,自己再想了想,发现水的一笔;

分析:看到题目时被吓到了,觉得情况好多,,心态很重要!

假设<=3个点,那么自己无论怎么排列,都不会形成新的点,所以就输出n;

如果是4个点,如果是平行四边形,,那么只能形成5个点;

如果是五个点,如果在是平行四边形的基础上,第五个点位于平行四边形的对角线上,那么最后也是五个点。

最后一个是比较特殊的情况,有n个点,假如n-1个点共线,一个点在直线外,那么答案就是n,但是

如果在直线外的点的个数>=2的话,那么就是oo了。

最后,因为要求点的全排列,需要用到next_permutation()函数:

1.因为point是自定义结构体,所以要定义点的优先级

2.next_permutation()函数使用前需要先对待排列数组排下序,利用sort从小到大排序

URAL 2036 Intersect Until You're Sick of It 形成点的个数 next_permutation()函数的更多相关文章

  1. 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 ...

  2. [转]数位dp小记

    转载自:http://blog.csdn.net/guognib/article/details/25472879 参考: http://www.cnblogs.com/jffifa/archive/ ...

  3. Array 数组的排序 sort

    JavaScript实现多维数组.对象数组排序,其实用的就是原生的sort()方法,用于对数组的元素进行排序.sort() 方法用于对数组的元素进行排序.语法如下:arrayObject.sort(s ...

  4. T-SQL基础(四)之集合运算

    三个运算符 T-SQL支持三个集合运算符:UNION.INTERSECT.EXCEPT. 集合运算符查询的一般形式如下: Query1 <set_operator> Query2 -- 这 ...

  5. R语言函数总结(转)

    R语言特征 对大小写敏感 通常,数字,字母,. 和 _都是允许的(在一些国家还包括重音字母).不过,一个命名必须以 . 或者字母开头,并且如果以 . 开头,第二个字符不允许是数字. 基本命令要么是表达 ...

  6. Ts基础

    //typeof 用来判断变量类型 var s: string = 'egret'; var isString: boolean = typeof s === 'string'; console.lo ...

  7. 【Ray Tracing in One Weekend 超详解】 光线追踪1-4

    我们上一篇写了Chapter5 的第一个部分表面法线,那么我们来学剩下的部分,以及Chapter6. Chapter5:Surface normals and multiple objects. 我们 ...

  8. [JS深入学习]——数组对象排序

    (转) JavaScript实现多维数组.对象数组排序,其实用的就是原生的sort()方法,用于对数组的元素进行排序. sort() 方法用于对数组的元素进行排序.语法如下: arrayObject. ...

  9. 【R笔记】R语言函数总结

    R语言与数据挖掘:公式:数据:方法 R语言特征 对大小写敏感 通常,数字,字母,. 和 _都是允许的(在一些国家还包括重音字母).不过,一个命名必须以 . 或者字母开头,并且如果以 . 开头,第二个字 ...

随机推荐

  1. Python 3.8.0 正式版发布,新特性初体验 全面介绍

    Python 3.8.0 正式版发布,新特性初体验 北京时间 10 月 15 日,Python 官方发布了 3.8.0 正式版,该版本较 3.7 版本再次带来了多个非常实用的新特性. 赋值表达式 PE ...

  2. 使用EF Core 连接远程oracle 不需要安装oracle客户端方法

    连接字符串: Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=IP地址(PORT=1521))(CONNECT_DATA=(SERVICE_ ...

  3. C++ STL用法总结(持续更新)

    Vector 动态数组 https://www.cnblogs.com/zhonghuasong/p/5975979.html lower_bound&&upper_bound htt ...

  4. C++:函数先声明后实现

    贼神奇的是,直到昨天在写flex规则的时候我才知道C++中的函数要么在使用之前先定义,要么将实现放在调用之前,不允许先调用后实现.之前一年多竟然不知道这件事,汗````,当然也是可能这件事本身和我思考 ...

  5. O043、计算节点宕机了怎么办

    参考https://www.cnblogs.com/CloudMan6/p/5562131.html   Rebuild 可以恢复损坏的instance .那如果是宿主机坏了怎么办呢?比如硬件故障或者 ...

  6. HTML5之客户端存储(Storage)

    关于客户端存储技术 storage 一.关于客户端(浏览器)存储技术 浏览器的存储技术第一个能想到的应该就是cookie,关于cookie本身出现的初衷是为了解决客户端识别,可存储信息量小(4k左右) ...

  7. JavaScript笔记(2)

    函数 1.使用关键字function声明一个函数,如果需要传参数就传参,多个参数用逗号隔开,如果不需要传参数就不传 //函数声明 function name(num1,num2){ //方法体 } 2 ...

  8. 销售订单(SO)-API-登记销售订单

    登记销售订单可以在新增订单的时候就登记:并不是去修改 flow_status 为booked,而是赋值action request:就下面两句 l_action_request_tbl(l_actio ...

  9. 《Redis高阶应用》讲座总结

    数据结构延展 常用数据结构:String,Hash,List,Set,Sorted Set(不聊这些) 高级数据结构:Bitmaps,hyperloglog,GEO 单机拓展到分布式 为什么要分区:性 ...

  10. Python制作的射击游戏

    如果其他朋友也有不错的原创或译文,可以尝试推荐给伯乐在线.] 你有没有想过电脑游戏是怎样制作出来的?其实它没有你想象的那样复杂! 在这个教程里,你要学做一个叫<兔子和獾>的塔防游戏,兔子作 ...