Codeforces 894B. Tell Your World
来源:互联网 发布:java中instanceof 编辑:程序博客网 时间:2024/05/16 16:16
题目链接
比赛的时候这题被Hack了真的无比伤心,赛后看了很多篇代码,大多O(
相邻的两个点,要么在同一条直线上,要么在不同的直线上,共有三种情况,如图所示
设直线的斜率为p(由于题目中相邻两个点的横坐标差值为1,所以如果在同一条直线上的话相邻两点的纵坐标差值即为斜率),设两条平行直线在同一横坐标下纵坐标差值的绝对值为q
下面分析三种情况下,相邻两个点的纵坐标差值
情况1:p
情况2:p+q
情况3:p-q
大致思路如上所述,代码实现过程中有许多细节,比如差分处理之后出现过的不同数值只能是两种或三种才有可能满足题目条件;情况2和情况3分别都不能连续出现,详见代码
#include<bits/stdc++.h>using namespace std;#define N 1005struct node{ int dis,cnt; bool operator < (const node& x) const { return dis<x.dis; }}a[N];int tot,n,x[N],y[N],i,j;bool chk(){ int tmp=0; map<int,int>M; for(i=1;i<n;i++){ for(j=0;j<tot;j++)if(y[i]==a[j].dis) break; if(!j) tmp--; else if(j==tot-1) tmp++; M[tmp]=1; } return M.size()==2;}int main(){ scanf("%d",&n); for(tot=i=0;i<n;i++){ scanf("%d",&x[i]); if(i){ y[i]=x[i]-x[i-1]; for(j=0;j<tot;j++)if(a[j].dis==y[i]) break; if(j>=tot) a[tot++].dis=y[i]; a[j].cnt++; } } if(tot==3){ sort(a,a+3); //排序后a[1]即情况1 puts(a[0].dis+a[2].dis==2*a[1].dis&&chk()?"Yes":"No"); } else if(tot==2) puts(a[0].cnt==1||a[1].cnt==1||chk()?"Yes":"No"); else puts("No");}
阅读全文
1 0
- Codeforces 894B. 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 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(向量积)
- Codeforces Round #431 (Div. 2) 849B Tell Your World(暴力+枚举)
- Codeforces Round #431 (Div. 2) B. Tell Your World(技巧性模拟+精度坑死人系列)
- B. Tell Your World Codeforces Round #431 (Div. 2)(简单模拟)
- codeforces 431B Tell Your World(两平行线穿过所有点)【模板】
- CodeForces #431Div. 2 849B Tell your world 几何 暴力 枚举
- 图片加载之Glide使用总结
- HDFS的安全模式
- Navicat无法连接Oracle 11g:Cannot load OCI DLL 87/193——解决办法
- 让Ubuntu 16.04可以压缩/解压缩RAR文件
- Qt Charts入门指南
- Codeforces 894B. Tell Your World
- 练习二(第二周)
- android datebinding学习
- 欢迎使用CSDN-markdown编辑器
- BOW
- 欢迎使用CSDN-markdown编辑器
- Canvas的实际使用
- PHP执行外部程序
- 基数排序