Codeforces 849 B. Tell Your World(计算几何)
来源:互联网 发布:丑老太婆网络照片 编辑:程序博客网 时间:2024/05/29 14:39
题目大概意思是:给出n个坐标(i,y[i]),问是否存在两条不重合的平行线,经过所有点,且每条平行线上至少有一个点。
思路为:把所有的点分成两个平行线的集合,则第一个点与第二个点连接的斜率和第一个点和第三个点连接的斜率或第三个点和第二个点连接的斜率必定有一个存在其中一个平行线的集合当中,则不存在两条平行线,经过所有的点。
直接上代码:
#include<stdio.h>#include<string.h>#include<iostream>#include<cmath>#include<algorithm>#include<cctype>using namespace std;int mj(double k,int n,int *m){ int flag=0; int p=-1;//已第一个点和第P个点为基准枚举进行查找 for(int i=2;i<=n;i++) { if(m[i]-m[1]==k*(i-1))continue; flag=1; if(p<0) p=i; else if(m[i]-m[p]!=k*(i-p))//第p个点和i相连结的斜率与第一条平行线不平行跳出 { flag=0; break; } } if(flag) return 1; else return 0;}int main(){ int n; int a[10005]; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); } double k1=(a[2]-a[1])/1.0; double k2=(a[3]-a[1])/2.0; double k3=(a[3]-a[2])/1.0; if(mj(k1,n,a)||mj(k2,n,a)||mj(k3,n,a)) //其中一个斜率存在一个平行线集合中,切其他点在另外一个平行线集合当中 printf("Yes\n"); else printf("No\n");}
阅读全文
0 0
- codeforces 849B Tell Your World(计算几何)
- Codeforces 849 B. Tell Your World(计算几何)
- Codeforces 849B. Tell Your World 计算几何
- Codeforces 849 B Tell Your World
- CodeForces 849B Tell Your World 点线
- codeforces 849B. Tell Your World
- codeforces 849B Tell Your World
- Codeforces-849B Tell Your World
- CodeForces #431Div. 2 849B Tell your world 几何 暴力 枚举
- Codeforces 894B. Tell Your World
- Codeforces Tell Your World
- Codeforces Round #431 (Div. 2) B. Tell Your World
- Codeforces Round #431 (Div. 2)B Tell Your World
- Codeforces Round #431 (Div. 2) 849B Tell Your World(暴力+枚举)
- CodeFroces 849B. Tell Your World (鸽巢原理)
- Codeforces Round #431 (Div. 2) B. Tell Your World(向量积)
- Codeforces Round #431 (Div. 2) B. Tell Your World(技巧性模拟+精度坑死人系列)
- B. Tell Your World Codeforces Round #431 (Div. 2)(简单模拟)
- 6-7 简单计算器
- 22.c语言各种输入输出与错误处理
- 数据结构之线性表(建表-插入-删除-合并)
- Importing the multiarray numpy extension module failed
- CSS 选择器权重计算规则
- Codeforces 849 B. Tell Your World(计算几何)
- C语言(在linex系统操作)通讯录
- C#笔记(2)md5加密
- 【python爬虫03】使用Scrapy框架模拟登录知乎
- 6-8 统计一行文本的单词个数
- 机器学习笔记--K-近邻算法(三)
- matlab2c使用c++实现matlab函数系列教程-kron函数
- linux 基础
- 01背包问题*3