日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU 1086 You can Solve a Geometry Problem too

發(fā)布時間:2025/7/14 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 1086 You can Solve a Geometry Problem too 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

You can Solve a Geometry Problem too

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2734 Accepted Submission(s): 1284


Problem Description

Many geometry(幾何)problems were designed in the ACM/ICPC. And now, I also prepare a geometry problem for this final exam. According to the experience of many ACMers, geometry problems are always much trouble, but this problem is very easy, after all we are now attending an exam, not a contest :)
Give you N (1<=N<=100) segments(線段), please output the number of all intersections(交點). You should count repeatedly if M (M>2) segments intersect at the same point.

Note:
You can assume that two segments would not intersect at more than one point.

Input

Input contains multiple test cases. Each test case contains a integer N (1=N<=100) in a line first, and then N lines follow. Each line describes one segment with four float values x1, y1, x2, y2 which are coordinates of the segment’s ending.
A test case starting with 0 terminates the input and this test case is not to be processed.

Output

For each case, print the number of intersections, and one line one case.


?

Sample Input

2 0.00 0.00 1.00 1.00 0.00 1.00 1.00 0.00 3 0.00 0.00 1.00 1.00 0.00 1.00 1.00 0.000 0.00 0.00 1.00 0.00 0

Sample Output

1 3

Author

lcy 詳細看 《計算幾何—基礎(chǔ)》 1 #include<iostream>
2 using namespace std;
3 double p[100][2],q[100][2];
4 double direction( double p[] , double q[] , double r[])
5 {
6 return ( (r[0] - p[0]) * (q[1] - p[1]) - (r[1] - p[1]) * (q[0] - p[0]));
7 }
8 bool onsegment(double p[],double q[], double r[])
9 {
10 if(((r[0] - p[0])*(r[0] - q[0]) <= 0) && ((r[1] - p[1]) * (r[1] - q[1]) <= 0))
11 return true;
12 else return false;
13 }
14 bool judge(int i, int j)
15 {
16 double d1 , d2 , d3 , d4 ;
17 d1 = direction(p[i],q[i],p[j]);
18 d2 = direction(p[i],q[i],q[j]);
19 d3 = direction(p[j],q[j],p[i]);
20 d4 = direction(p[j],q[j],q[i]);
21 if( (d1 * d2 < 0) && (d3 * d4 < 0))
22 return true;
23 else if( d1 == 0 && onsegment(p[i],q[i],p[j]) == 1)
24 return true;
25 else if( d2 == 0 && onsegment(p[i],q[i],q[j]) == 1)
26 return true;
27 else if( d3 == 0 && onsegment(p[j],q[j],p[i]) == 1)
28 return true;
29 else if( d4 == 0 && onsegment(p[j],q[j],q[i]) == 1)
30 return true;
31 else return false;
32 }
33 int main(){
34 int n, i , j , count;
35 while( scanf( "%d" , &n ) , n)
36 {
37 for( i = 0 ; i < n ; ++ i )
38 {
39 scanf( "%lf %lf %lf %lf", &p[i][0] , &p[i][1] , &q[i][0] , &q[i][1] ) ;
40 }
41 for( i = 0 , count = 0 ; i < n ; i ++ )
42 for( j = i + 1 ; j < n ; j ++ )
43 if( judge( i , j ) == 1 )
44 ++count;
45 printf("%d\n",count);
46 }
47 return 0;
48 }

  

總結(jié)

以上是生活随笔為你收集整理的HDU 1086 You can Solve a Geometry Problem too的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。