列表

详情


NC54778. Kuangyeye's Game

描述

Christmas Day is coming! To celebrate this great festival, Kuangyeye, a creative boy, wants to play a game with everyone. The rule is described as following: there are several balloons in the classroom, and you have a prop gun. To achieve a higher goal, you need to shoot as many balloons as you can with one bullet. Now you have to judge whether you can explosive all balloons with one shoot. In a rigorous word, there are n points on the plane, you need to judge if they are on the same line. In addition, the balloons may extremely tiny, so some of them may share the same coordinate.


输入描述

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;}

上一题