http://codeforces.com/contest/849/problem/B

题目是给出n个点,要求把这n个点分成两组,每组都是一条直线。而且这两组不能为空,还要是平行的。

思路:

对于前3个点来说,他们不可能各自一组,因为只能分成2组。

他们有可能同时一组,或者两个点在一组。

这一共就4种情况,然后O(n)判断即可

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
const int maxn = 1e3 + ;
struct coor {
LL x, y;
} a[maxn], b[maxn];
int vis[maxn], DFN = ;
int n;
bool same(int i, int j, int k) {
return (a[j].y - a[i].y) * (a[k].x - a[i].x) == (a[k].y - a[i].y) * (a[j].x - a[i].x);
}
bool init(int one, int two) {
++DFN;
vis[one] = vis[two] = DFN;
for (int i = ; i <= n; ++i) {
if (vis[i] == DFN) continue;
if (same(one, two, i)) {
vis[i] = DFN;
}
}
int lenb = ;
for (int i = ; i <= n; ++i) {
if (vis[i] == DFN) continue;
if (lenb == ) b[++lenb] = a[i];
else {
b[++lenb] = a[i];
if ((a[two].y - a[one].y) * (b[lenb].x - b[].x) != (b[lenb].y - b[].y) * (a[two].x - a[one].x)) {
return false;
}
}
}
return lenb != ;
}
void work() {
scanf("%d", &n);
for (int i = ; i <= n; ++i) {
scanf("%I64d", &a[i].y);
a[i].x = i;
}
for (int i = ; i <= ; ++i) {
for (int j = i + ; j <= ; ++j) {
if (init(i, j)) {
printf("Yes\n");
return;
}
}
}
printf("No\n");
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

随机推荐

  1. js数组中常用的几个API

    1.push:从末尾添加数据项. 2.pop:从末尾去除数据项. 3.shift:从开始去除数据项 4.splice: splice(m,n) m:指开始删除的索引位置  n:值删除几项 splice ...

  2. pythoon_interview_redit

    easy/intermediate What are Python decorators and how would you use them?How would you setup many pro ...

  3. SpringMVC 学习笔记(请求方法的返回值和参数)

    在用注解对配置 处理器时,一般是一个方法处理一个请求,不同方法的返回类型有着不同的意义. 返回值为 ModelAndView 类型 ModelAndView 是Model 和 View 的一个集合类型 ...

  4. /* font-awesome-4.7.0的应用*/

    <!DOCTYPE html> /* font-awesome-4.7.0的应用*/ <html lang="en"> <head> <m ...

  5. 牛叉之nc命令

    nc是一款很不错的网络检测工具,以下是详细使用. 'nc.exe -h'即可看到各参数的使用方法. 基本格式:nc [-options] hostname port [ports] - nc -l - ...

  6. 向PCD文件写入点云数据

    博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=83 本小节我们学习如何向PCD文件写入点云数据. 代码 章例2文件夹中,打开 ...

  7. 《精通Spring4.X企业应用开发实战》读后感第五章(基于注解的配置)

  8. Linux 静态库(.a)转换为动态库(.so)

    Linux 静态库转换为动态库 参考 http://blog.csdn.net/moxuansheng/article/details/5812410 首先将.a文件转为.so文件是可以实现的 原因是 ...

  9. C#中小数转化为string的问题

    在C#中,把小数转化为string, 比如 45.12, 转换为string时,应该就是"45.12" 但是在项目开发中,开发法国的branch时,由于culture使用的是FR- ...

  10. C++哪些函数不能是虚函数

    1. inline是编译时展开,必须有实体:(不考虑不展开的假inline)   2. static属于class自己的,也必须有实体:   3. 构造函数.复制构造函数.virtual函数基于vta ...