Codeforces Round #431 (Div. 2)B Tell Your World
2017-09-05 16:29
225 查看
传送门
B. Tell Your World
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Connect the countless points with lines, till we reach the faraway yonder.
There are n points on a coordinate plane, the i-th
of which being (i, yi).
Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at
least one point in the set.
Input
The first line of input contains a positive integer n (3 ≤ n ≤ 1 000)
— the number of points.
The second line contains n space-separated integers y1, y2, ..., yn ( - 109 ≤ yi ≤ 109)
— the vertical coordinates of each point.
Output
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No"
otherwise.
You can print each letter in any case (upper or lower).
Examples
input
output
input
output
input
output
input
output
Note
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9).
It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and
is parallel to the first one.
In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel.
In the third example, it's impossible to satisfy both requirements at the same time.
题意:
给出坐标为(i,y[i])的一系列点,问能否找到两条平行且不重合的直线,使得所有点都落在两条直线上,且每条直线上至少有一个点。
思路:
1 2 3个点。3个斜率必定有一个平行线斜率。
B. Tell Your World
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Connect the countless points with lines, till we reach the faraway yonder.
There are n points on a coordinate plane, the i-th
of which being (i, yi).
Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at
least one point in the set.
Input
The first line of input contains a positive integer n (3 ≤ n ≤ 1 000)
— the number of points.
The second line contains n space-separated integers y1, y2, ..., yn ( - 109 ≤ yi ≤ 109)
— the vertical coordinates of each point.
Output
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No"
otherwise.
You can print each letter in any case (upper or lower).
Examples
input
5 7 5 8 6 9
output
Yes
input
5 -1 -2 0 0 -5
output
No
input
5 5 4 3 2 1
output
No
input
5 1000000000 0 0 0 0
output
Yes
Note
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9).
It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and
is parallel to the first one.
In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel.
In the third example, it's impossible to satisfy both requirements at the same time.
题意:
给出坐标为(i,y[i])的一系列点,问能否找到两条平行且不重合的直线,使得所有点都落在两条直线上,且每条直线上至少有一个点。
思路:
1 2 3个点。3个斜率必定有一个平行线斜率。
//china no.1 #pragma comment(linker, "/STACK:1024000000,1024000000") #include <vector> #include <iostream> #include <string> #include <map> #include <stack> #include <cstring> #include <queue> #include <list> #include <stdio.h> #include <set> #include <algorithm> #include <cstdlib> #include <cmath> #include <iomanip> #include <cctype> #include <sstream> #include <functional> #include <stdlib.h> #include <time.h> #include <bitset> using namespace std; #define pi acos(-1) #define s_1(x) scanf("%d",&x) #define s_2(x,y) scanf("%d%d",&x,&y) #define s_3(x,y,z) scanf("%d%d%d",&x,&y,&z) #define PI acos(-1) #define endl '\n' #define srand() srand(time(0)); #define me(x,y) memset(x,y,sizeof(x)); #define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++) #define close() ios::sync_with_stdio(0); cin.tie(0); #define FOR(x,n,i) for(int i=x;i<=n;i++) #define FOr(x,n,i) for(int i=x;i<n;i++) #define fOR(n,x,i) for(int i=n;i>=x;i--) #define fOr(n,x,i) for(int i=n;i>x;i--) #define W while #define sgn(x) ((x) < 0 ? -1 : (x) > 0) #define bug printf("***********\n"); #define db double #define ll long long #define mp make_pair #define pb push_back typedef long long LL; const int INF=0x3f3f3f3f; const LL LINF=0x3f3f3f3f3f3f3f3fLL; const int dx[]={-1,0,1,0,1,-1,-1,1}; const int dy[]={0,1,0,-1,-1,1,-1,1}; const int maxn=1e3+10; const int maxx=1e6+100; const double EPS=1e-8; const double eps=1e-8; const int mod=1e9+7; template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);} template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);} template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));} template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));} template <class T> inline bool scan_d(T &ret){char c;int sgn;if (c = getchar(), c == EOF){return 0;} while (c != '-' && (c < '0' || c > '9')){c = getchar();}sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0'); while (c = getchar(), c >= '0' && c <= '9'){ret = ret * 10 + (c - '0');}ret *= sgn;return 1;} inline bool scan_lf(double &num){char in;double Dec=0.1;bool IsN=false,IsD=false;in=getchar();if(in==EOF) return false; while(in!='-'&&in!='.'&&(in<'0'||in>'9'))in=getchar();if(in=='-'){IsN=true;num=0;}else if(in=='.'){IsD=true;num=0;} else num=in-'0';if(!IsD){while(in=getchar(),in>='0'&&in<='9'){num*=10;num+=in-'0';}} if(in!='.'){if(IsN) num=-num;return true;}else{while(in=getchar(),in>='0'&&in<='9'){num+=Dec*(in-'0');Dec*=0.1;}} if(IsN) num=-num;return true;} void Out(LL a){if(a < 0) { putchar('-'); a = -a; }if(a >= 10) Out(a / 10);putchar(a % 10 + '0');} void print(LL a){ Out(a),puts("");} //freopen( "in.txt" , "r" , stdin ); //freopen( "data.txt" , "w" , stdout ); //cerr << "run time is " << clock() << endl; //cf-535C Tavas and Pashmaks int n; int Q[maxn]; bool check(double k) { int p=-1; for(int i=2;i<=n;i++) { if((i-1)*k==Q[i]-Q[1])continue; if(p==-1)p=i;//不想等分在另一组 else if(k*(p-i)!=Q[p]-Q[i])return 0;//和两个的斜率都不相等,不满足条件 } return p!=-1;//判断是否在一条直线上 } int main() { scan_d(n); FOR(1,n,i) { scan_d(Q[i]); } if(n==2) { puts("Yes"); return 0; } if(check((Q[3]-Q[1])*1.0/2)||check(Q[2]-Q[1])||check (Q[3]-Q[2])) { puts("Yes"); return 0; } puts("No"); }
相关文章推荐
- Codeforces Round #431 (Div. 2)B 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)B 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)B 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 Round #431 (Div. 2)B Tell Your World
- Codeforces Round #431 (Div. 2)B Tell Your World
- Codeforces Round #431 (Div. 2)B Tell Your World
- Codeforces Round #287 (Div. 2) C. Guess Your Way Out! ACM解题报告(二叉树)
- Codeforces Round #431 (Div. 2) 849A Odds and Ends(思维)
- A. Odds and Ends Codeforces Round #431 (Div. 2)(水题)
- Codeforces Round #431 (Div. 2) A B C
- Codeforces Round #287 (Div. 2) C. Guess Your Way Out! 二叉树遍历
- 【Codeforces Round 431 (Div. 2) A B C D E五个题】
- Educational Codeforces Round 38 (Rated for Div. 2) B. Run For Your Prize