poj 2653 计算几何


 1 #include <iostream>
2 #include <cstring>
3 #include <algorithm>
4 #include <cmath>
5 #include <cstdio>
6 using namespace std;
7 struct point {
8 double x,y;
9 };
10 point be[100005],en[100005];
11 int ans[100005];
12 int res[100005];
13
14 double max(double a,double b){
15 return a>b?a:b;
16 }
17 double min(double a,double b){
18 return a<b?a:b;
19 }
20
21 int inter(point a,point b,point c,point d){
22 if(min(a.x,b.x)>max(c.x,d.x)||min(a.y,b.y)>max(c.y,d.y)||min(c.x,d.x)>max(a.x,b.x)||min(c.y,d.y)>max(a.y,b.y))
23 return 0;
24 double h,i,j,k;
25 h = (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
26 i = (d.x-a.x)*(b.y-a.y)-(d.y-a.y)*(b.x-a.x);
27 j = (a.x-c.x)*(d.y-c.y)-(a.y-c.y)*(d.x-c.x);
28 k = (b.x-c.x)*(d.y-c.y)-(b.y-c.y)*(d.x-c.x);
29 return h*i<0&&j*k<0;
30 }
31 int main()
32 {
33 int n;
34 while(scanf("%d",&n)==1&&n){
35 for(int i=0;i<n;i++)
36 cin>>be[i].x>>be[i].y>>en[i].x>>en[i].y;
37 memset(ans,0,sizeof(ans));
38 memset(res,0,sizeof(res));
39 for(int i=0;i<n;i++){
40 for(int j=i+1;j<n;j++){
41 if(inter(be[i],en[i],be[j],en[j])){
42 ans[i] =1;
43 break;
44 }
45 }
46 }
47 int cnt =0;
48 for(int i=0;i<n;i++){
49 if(!ans[i])
50 res[cnt++] = i+1;
51 }
52 printf("Top sticks: ");
53 for(int i=0;i<cnt-1;i++)
54 printf("%d, ",res[i]);
55 printf("%d.\n",res[cnt-1]);
56
57 }
58 return 0;
59 }

poj 2653 计算几何

时间: 2024-08-28 18:48:04

poj 2653 计算几何的相关文章

poj 2653 线段与线段相交

Pick-up sticks Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 11884   Accepted: 4499 Description Stan has n sticks of various length. He throws them one at a time on the floor in a random way. After finishing throwing, Stan tries to fin

poj 2653 (线段相交判断)

http://poj.org/problem?id=2653 Pick-up sticks Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 9531   Accepted: 3517 Description Stan has n sticks of various length. He throws them one at a time on the floor in a random way. After finishi

POJ 2398 计算几何+二分+排序

Toy Storage Time Limit: 1000MS  Memory Limit: 65536K Total Submissions: 3953  Accepted: 2334 Description Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing with them. They gave Reza a rectangular box t

POJ 3304 计算几何

Segments Time Limit: 1000MS  Memory Limit: 65536K Total Submissions: 9564  Accepted: 2943 Description Given n segments in the two dimensional space, write a program, which determines if there exists a line such that after projecting these segments on

POJ 2653

开一个数组做成队列来搜索就好了. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <queue> 5 #include <algorithm> 6 using namespace std; 7 8 const int MAXN=100010; 9 10 typedef struct po{ 11 double x,y; 12 }Point; 13

poj 1410 计算几何

1 /** 2 注意: 千万得小心..就因为一个分号,调了一个晚上... 3 **/ 4 #include <iostream> 5 #include <algorithm> 6 using namespace std; 7 struct point { 8 int x,y; 9 }; 10 11 struct line{ 12 point a; 13 point b; 14 }; 15 line l,lt;//l 直线 lt 矩形的边 16 int x1,x2,y1,y2; 17

poj 2398 计算几何

1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <algorithm> 5 using namespace std; 6 7 struct point{ 8 int x,y; 9 }; 10 11 struct line{ 12 point a,b; 13 }; 14 line lline[5005]; 15 16 int cnt[5005]; 17 int re

poj 1269 计算几何

1 /** 2 判断直线位置关系 3 **/ 4 #include <iostream> 5 #include <cmath> 6 #include <cstdio> 7 using namespace std; 8 struct point { 9 double x,y; 10 point(double x=0,double y=0):x(x),y(y){} 11 }; 12 13 typedef point Vector; 14 15 Vector operator

POJ 2318 计算几何+二分

TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10425 Accepted: 5002 Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a problem - their child John never puts his toys away when