OpenJudge exercises (C ++) -- question 4072: judge whether multiple points are in the same straight line

Source: Internet
Author: User

OpenJudge exercises (C ++) -- question 4072: judge whether multiple points are in the same straight line
Question:

Total time limit:
1000 ms
Memory limit:
65536kB
Description

There are N (1 <= n <= 100) <span = ""> points that do not overlap with each other, and their coordinates (xi, yi) are given ), ask if these points are in the same straight line.

Input
The first row is the number of T (1 <= T <= 100), followed by T group data. The first row of each group is the number of N data points of the group, followed by N rows, each line represents the coordinate of a point, which consists of two numbers separated by spaces.
Output
There are T rows. Each row corresponds to a set of input data. If the data points in the group are in the same line, the row outputs True; otherwise, the output is False.
Sample Input
130 02 21 1
Sample output
True
Solution:
#include<iostream>#include<stdio.h>using namespace std;int main(){int T;cin>>T;int True[T];double a[T][1000];double b[T][1000];int c[T];for(int i=0;i<t;i&#43;&#43;) cin="">>c[i];for(int j=0;j<c[i];j&#43;&#43;) cin="">>a[i][j]>>b[i][j];}}for(int i=0;i<t;i&#43;&#43;) int="" h="1;h<c[i];h++)">2&&(b[i][1]-b[i][0])*(a[i][h]-a[i][0])!=(b[i][h]-b[i][0])*(a[i][1]-a[i][0])){True[i]=0;//cout<<a[i][0]*b[i][h]<<"and"<<a[i][h]*b[i][0]<<endl; else="" return="" pre=""><p></p>   </a[i][0]*b[i][h]<<"and"<<a[i][h]*b[i][0]<<endl;></t;i&#43;&#43;)></c[i];j&#43;&#43;)></t;i&#43;&#43;)></stdio.h></iostream>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.