CodeForces #431Div. 2 849B Tell your world 几何 暴力 枚举
来源:互联网 发布:淘宝答题在哪里 编辑:程序博客网 时间:2024/06/10 15:36
做这题之前首先大喊:
骑士团参见公主殿下!!
然后这题目的题意是说给出n个点,判断这n个点是不是恰好在两条平行的直线上
题目会给出n个点的纵坐标,其中第i个点的横坐标是i
实际上我我觉得就算横坐标是给出的,也应该复杂度是一样的。O(n)
做法是枚举前三个点的状态,P1和P2在同一直线上,P1和P3在同一直线上,P2和P3在同一直线上。
对于任何一种情况来说,我们都可以把一条直线的斜率k和偏移量b求出来。然后对所有的点扫一遍,不在该直线上的点判断一下和另一个不在该直线上的点所连直线的斜率是不是等于已知直线。
最后注意特判一下所有点都在同一直线上的情况即可
此外一个小trick就是我把所有点都向左平移了一个单位,这样在枚举三种情况的时候偏移量b都会是整数
#include <iostream>#include <cstring>#include <cmath>using namespace std;const double eps = 1E-7;const int maxm=1010;int n,arr[maxm];bool check(double k,int b);int main(){ ios_base::sync_with_stdio(0); cin>>n; for(int i=0;i<n;++i)cin>>arr[i]; cout<<(check(arr[1]-arr[0],arr[0])||check(arr[2]-arr[1],(arr[1]<<1)-arr[2])||check(0.5*(arr[2]-arr[0]),arr[0])?"Yes\n":"No\n"); return 0;}bool check(double k, int b){ int cnt=0,pos1=-1; for(int i=0;i<n;++i) if(arr[i]==1LL*k*i+b) ++cnt; else if(pos1==-1) pos1=i; else if(abs(k-(arr[i]-arr[pos1])*1.0/(i-pos1))>eps) return false; return cnt!=n;}
阅读全文
0 0
- CodeForces #431Div. 2 849B Tell your world 几何 暴力 枚举
- Codeforces Round #431 (Div. 2) 849B Tell Your World(暴力+枚举)
- Codeforces Round #431 (Div. 2) B. Tell Your World
- Codeforces Round #431 (Div. 2)B Tell Your World
- codeforces 849B Tell Your World(计算几何)
- Codeforces 849 B. Tell Your World(计算几何)
- Codeforces 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)(简单模拟)
- 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 Round #431 (Div. 2) Tell Your World
- Codeforces Round #431 (Div. 2) A、Odds and Ends B、Tell Your World C、From Y to Y
- Codeforces 894B. Tell Your World
- HttpClient中post请求http、https示例
- codevs 3336 电话网络 SPFA 解题报告
- Mac 本地安装 wordpress
- 基于深度残差学习的图像识别 Deep Residual Learning for Image Recognition
- 基于二级指针实现动态二维数组的不定长输入及遍历
- CodeForces #431Div. 2 849B Tell your world 几何 暴力 枚举
- 线段树基本操作(单点更新,区间极值,区间求和)
- linux学习---brk(), sbrk() 用法
- https工作原理
- 《机器学习》第二章 模型评估与选择 笔记3 查准率、查全率
- Andriod常用权限和依赖
- 利用POI框架创建excel表格
- 漏洞及渗透练习平台:
- 安利一个icon的网站