URAL 2036 Intersect Until You're Sick of It 形成点的个数 next_permutation()函数
Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
- 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.
Input
Output
Sample Input
| input | output |
|---|---|
4 |
题意:给你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()函数的更多相关文章
- 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 ...
- [转]数位dp小记
转载自:http://blog.csdn.net/guognib/article/details/25472879 参考: http://www.cnblogs.com/jffifa/archive/ ...
- Array 数组的排序 sort
JavaScript实现多维数组.对象数组排序,其实用的就是原生的sort()方法,用于对数组的元素进行排序.sort() 方法用于对数组的元素进行排序.语法如下:arrayObject.sort(s ...
- T-SQL基础(四)之集合运算
三个运算符 T-SQL支持三个集合运算符:UNION.INTERSECT.EXCEPT. 集合运算符查询的一般形式如下: Query1 <set_operator> Query2 -- 这 ...
- R语言函数总结(转)
R语言特征 对大小写敏感 通常,数字,字母,. 和 _都是允许的(在一些国家还包括重音字母).不过,一个命名必须以 . 或者字母开头,并且如果以 . 开头,第二个字符不允许是数字. 基本命令要么是表达 ...
- Ts基础
//typeof 用来判断变量类型 var s: string = 'egret'; var isString: boolean = typeof s === 'string'; console.lo ...
- 【Ray Tracing in One Weekend 超详解】 光线追踪1-4
我们上一篇写了Chapter5 的第一个部分表面法线,那么我们来学剩下的部分,以及Chapter6. Chapter5:Surface normals and multiple objects. 我们 ...
- [JS深入学习]——数组对象排序
(转) JavaScript实现多维数组.对象数组排序,其实用的就是原生的sort()方法,用于对数组的元素进行排序. sort() 方法用于对数组的元素进行排序.语法如下: arrayObject. ...
- 【R笔记】R语言函数总结
R语言与数据挖掘:公式:数据:方法 R语言特征 对大小写敏感 通常,数字,字母,. 和 _都是允许的(在一些国家还包括重音字母).不过,一个命名必须以 . 或者字母开头,并且如果以 . 开头,第二个字 ...
随机推荐
- jvm自带的监控机制
Jdk为我们提供了查看java服务运行时的监控情况 1.如下图所示,打开指定目录下的jconsole.exe应用程序文件. 2.双击后跳出如下界面,可以看到,我们可以监视本地的,也可以监视远程服务.本 ...
- maven 父子工程打包 并且上传linux服务器
先对父工程进行 mvn clean 再对子工程执行 install wagon:upload-single wagon:sshexec 使用wagon前提: 本地maven 的settings.xml ...
- Java学习笔记【六、正则表达式】
参考:http://www.runoob.com/java/java-regular-expressions.html 概述 java.util.regex包,主要包含三个类: Pattern:正则表 ...
- 单点登录系统SSO实现
前些天被问到单点登录了,而据我当时做的这个模块两年了,现在重新温习并记录下,方便以后快速回忆起来 一.什么是单点登录系统 SSO全称Single Sign On.SSO是用户只需要登录一次就可以访问所 ...
- jquery 取指定class下的input checkbox选中的值
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 8、nginx基础
1Nginx基本简述 Nginx是一个开源且高性能.可靠的Http Web服务.代理服务. 开源: 直接获取源代码 高性能: 支持海量并发 可靠: 服务稳定 我们为什么选择 Nginx服务 Nginx ...
- Kivy 简单尝试
Kivy 简明教程 首先,有两个网址你不得不看: Kivy: Cross-platform Python Framework for NUI在官网逛逛,顺便看看最下面的代码,try to run it ...
- arm交叉编译sudo-1.8.6p7
1.交叉编译 # tar -xvf sudo-1.8.6p7.tar.gz # cd sudo-1.8.6p7/ # mkdir build # ./configure --prefix=/home/ ...
- 【网络协议】ARP地址解析协议
地址解析协议ARP 在以太网协议中规定,同一局域网中的一台主机要和另一台主机进行直接通信,必须要知道目标主机的MAC地址.而在TCP/IP协议中,网络层和传输层只关心目标主机的IP地址.这就导致在以太 ...
- qunee 流动的关系
<!DOCTYPE html> <html> <head> <title>Hello Qunee for HTML5</title> < ...