北邮OJ 85. Three Points On A Line
生活随笔
收集整理的這篇文章主要介紹了
北邮OJ 85. Three Points On A Line
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
85. Three Points On A Line
時間限制1000 ms????內存限制 65536 KB????題目描述
Given points on a 2D plane, judge whether there're three points that locate on the same line.
輸入格式
The number of test cases T(1≤T≤10)? appears in the first line of input.
Each test case begins with the number of points N(1≤N≤100)?. The following N? lines describe the coordinates (x?i?,y?i?)? of each point, in accuracy of at most 3 decimals. Coordinates are ranged in [?10?4?,10?4?]?.
輸出格式
For each test case, output Yes if there're three points located on the same line, otherwise outputNo.
輸入樣例
2 3 0.0 0.0 1.0 1.0 2.0 2.0 3 0.001 -2.000 3.333 4.444 1.010 2.528輸出樣例
Yes No?
三點共線,枚舉所有的3點,求斜率,一樣則存在,做好標記然后退出枚舉即可。還有一種做法是求出一組后,把計算結果存起來,減少計算量。
?
#include<stdio.h> int main(){int t,n,i,j,k;double x[105],y[105];for(scanf("%d",&t);t--;){scanf("%d",&n);for(i=0;i<n;i++)scanf("%lf%lf",x+i,y+i);int sig=0;for(i=0;i<n&&!sig;i++)for(j=i+1;j<n&&!sig;j++){for(k=j+1;k<n&&!sig;k++){if((y[k]-y[i])/(x[k]-x[i])==(y[j]-y[i])/(x[j]-x[i]))sig=1;}}if(sig)printf("Yes\n");else printf("No\n");}return 0; }
?
總結
以上是生活随笔為你收集整理的北邮OJ 85. Three Points On A Line的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 北邮OJ 84. Single Numb
- 下一篇: 新BOJ 87. 日期