NC54778. Kuangyeye's Game
描述
输入描述
The first line contains an integer n which indicates the number of balloons. The next n following lines contain two integers xi and yi each, which represent the X coordinate and the Y coordinate of i-th balloon respectively.
输出描述
If you can explosive all balloons with one shoot, output "Yes". Output "No" otherwise(without quotes).
示例1
输入:
2 1 1 -1 -1
输出:
Yes
说明:
These two ballons are all on the line x-y=0.示例2
输入:
3 1 2 2 1 3 3
输出:
No
说明:
We can't find a line which all these ballons on it.C++(g++ 7.5.0) 解法, 执行用时: 3ms, 内存消耗: 480K, 提交时间: 2023-05-04 19:01:04
#include<iostream> #include<cmath> using namespace std; int main() { int n; cin>>n; int a,b,c,d; cin>>a>>b>>c>>d; for(int i = 3; i <= n ; i ++) { int x,y; cin>>x>>y; if((y-b)*(c-a)!=(d-b)*(x-a)) { printf("No"); return 0; } } printf("Yes"); return 0; }
C(clang 3.9) 解法, 执行用时: 3ms, 内存消耗: 376K, 提交时间: 2020-01-11 18:46:56
#include<stdio.h> #include<math.h> int main() { int m,n,i,j,t,x,y,a,b,c,d,f=0; scanf("%d %d %d",&n,&a,&b); scanf("%d %d",&c,&d); for(i=3;i<=n;i++){ scanf("%d %d",&x,&y); if((y-b)*(c-a)!=(d-b)*(x-a)){ printf("No"); return 0; } } printf("Yes"); return 0; }
C++14(g++5.4) 解法, 执行用时: 4ms, 内存消耗: 584K, 提交时间: 2020-01-11 17:21:35
#include<bits/stdc++.h> using namespace std; int n,a,b,c,d; int main() { scanf("%d%d%d%d%d",&n,&a,&b,&c,&d); for(int i=3; i<=n; i++) { int x,y; cin>>x>>y; if((d-b)*(x-a)!=(y-b)*(c-a)) { return !printf("No\n"); } } return !printf("Yes\n"); }
C++(clang++ 11.0.1) 解法, 执行用时: 3ms, 内存消耗: 464K, 提交时间: 2023-03-16 11:15:42
#include<bits/stdc++.h> using namespace std; int main(){int n;cin>>n;int x0,y0,x1,y1;cin>>x0>>y0>>x1>>y1;for(int i=3;i<=n;i++){int x,y;cin>>x>>y;if((y-y0)*(x1-x0)!=(y1-y0)*(x-x0)){cout<<"No"<<endl;return 0;}}cout<<"Yes"<<endl;return 0;}