CodeForces 849B Tell Your World 点线
来源:互联网 发布:淘宝联盟链接转换 编辑:程序博客网 时间:2024/05/29 15:34
题意 : 依次给出 y1 y2 y3 ... yn,表示点得纵坐标,每个点的横坐标就是对应的下标
(1,y1) (2,y2)...(n,yn) 问你这些点能不能被两条平行的直线贯穿,即所有点都在这两条直线上,且这两条直线不能平行
思路:对于大问题,先缩小为小问题
首先,只有两个点的时候,随意都可以把它画成两条平行的线,然后是三个点,那么其中一条线要穿过两个点,然后第三个点所在的直线也必须与前一条直线平行,那么我们就可以找出三种方案,就是两两点组合确定好一条直线。
在画了三个点的情况之后,增加一个点,但是我们只能判断这个点是否在前面的两条直线上,也就是说,前面的三个点就已经确定了线的斜率。
也就是说,利用前面三个点得到的三个斜率,必定有一个是正确的,那么我们就只需要枚举那三个斜率,然后判断是否所有点分布在两条为该斜率且不平行的线上就可以了
我枚举斜率之后,对于每个点,计算出过改点且为该斜率情况下的直线经过Y轴的点的纵坐标是多少,然后记录一下又多少个不同的过Y轴纵坐标,只有当数目为2的时候才正确。
#include<iostream>#include<cstdio>#include<algorithm>#include<map>using namespace std;map<double,int>m;int op[1005];double ang[5];int main(){int n,y,flag;double a1,a2,a3;while(scanf("%d",&n) != EOF){for(int i = 1;i <= n;i++){scanf("%d",&op[i]);}ang[1] = (op[2] - op[1]) * 1.0 / (2 - 1);ang[2] = (op[3] - op[2]) * 1.0 / (3 - 2);ang[3] = (op[3] - op[1]) * 1.0 / (3 - 1);flag = 0;for(int a = 1;a <= 3;a++){int cnt = 0;m.clear();for(int i = 1;i <= n;i++){double b = op[i] - ang[a] * i;if(!m.count(b)){m[b] = 1;cnt++;}else{m[b]++;}}if(cnt == 2){flag = 1;break;}}if(flag)puts("Yes");elseputs("No");}return 0;}
阅读全文
1 2
- 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 849 B. Tell Your World(计算几何)
- Codeforces 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(暴力+枚举)
- CodeForces #431Div. 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)(简单模拟)
- jsday09(table综合练习 通过指针操作数组 部分正则验证)
- leetcode 275. H-Index II
- HttpSession与Hibernate中Session的区别
- CVE-2014-6332浅析-Internet Explorer整数溢出漏洞
- sysctl.conf文件详解
- CodeForces 849B Tell Your World 点线
- HTML5中的data-属性
- 学习shell的知识结构图
- 十进制转换成二进制示例代码位运算
- Android 常用控件
- 关于Cesium粒子系统中的emitterModelMatrix和modelMatrix参数的理解
- maven(19)-生命周期和内置插件
- 天堂图片网爬虫
- Leetcode#83: Remove Duplicates from Sorted List