Codeforces 849 B Tell Your World
来源:互联网 发布:城市轨道交通系统知乎 编辑:程序博客网 时间:2024/05/15 13:54
题目地址
题意:告诉你一个长度为n的序列,每位的值代表的就是(i,num[i])这个点,问这些点能不能连成两条平行的直线。
思路:通过暴力枚举num[1]-num[0], num[2] - num[1],num[2] - num[0])/2
这3种情况,如果能有两个平行的直线那这里面一定是至少有一个是斜率的,然后通过得的斜率求枚举每一个值,看是不是有两个起点,为什么至少有一个是斜率呢,因为如果是真的,那只会有2种情况:
- 3个点在一条直线
- 3个点在两条直线上,但是一定有两个点在一条直线上
那就说明3点中肯定会有2个点在一条直线上,可以求出斜率,那直接枚举一下就好了。
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <stack>#include <cmath>#include <cstdio>#include <algorithm>#include <iomanip>#define N 1010#define M 1000010#define LL __int64#define inf 0x3f3f3f3f#define lson l,mid,ans<<1#define rson mid+1,r,ans<<1|1#define getMid (l+r)>>1#define movel ans<<1#define mover ans<<1|1using namespace std;const LL mod = 1000000007;double num[N];int n;set<double>s;bool check(double k) { s.clear(); for (int i = 0; i < n; i++) { s.insert(num[i] - k*(i + 1)); } return s.size() == 2;}int main() { cin.sync_with_stdio(false); while (cin >> n) { for (int i = 0; i < n; i++) { cin >> num[i]; } if (check(num[1]-num[0])|| check(num[2] - num[1])|| check((num[2] - num[0])/2)) {//一定有一个是斜率 cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0;}
阅读全文
0 0
- 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 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)(简单模拟)
- 无人车准备0902
- [DP 决策单调性] Codeforces Gym 101002H .Jewel Thief
- java中命名规则
- kali安装网易云音乐
- 如何获得CSDN积分
- Codeforces 849 B Tell Your World
- 文章标题
- 04 Spring框架 依赖注入(一)
- Word 公式编辑器 上下标
- PAI的示例项目MNIST详解
- CodeForces 22b_Bargaining Table_dp(暴力)
- UVa 232 Crossword Answers
- 笔试复习_TCP/IP(二)
- 朴素贝叶斯分类器