标签:顺序 sort sizeof jpg sorted header amp close 区域
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6534 | Accepted: 3905 |
Description
Input
Output
Sample Input
4 10 0 10 100 0 20 20 80 80 60 60 40 40 5 10 15 10 95 10 25 10 65 10 75 10 35 10 45 10 55 10 85 10 5 6 0 10 60 0 4 3 15 30 3 1 6 8 10 10 2 1 2 8 1 5 5 5 40 10 7 9 0
Sample Output
Box 2: 5 Box 1: 4 2: 1
Source
1 #include<iostream> 2 #include<cstring> 3 #include<string> 4 #include<algorithm> 5 #include<cstdio> 6 #include<cstdlib> 7 #include<cmath> 8 using namespace std; 9 const int MAX = 5005; 10 typedef struct point { 11 int x; 12 int y; 13 }point; 14 typedef struct value { 15 point start; 16 point end; 17 }v; 18 v edge[MAX]; 19 int sum[MAX], ans[MAX]; 20 int n, m, x1, y11, x2, y2, flag = 1,Ui, Li; 21 point tp; 22 int Xj, Yj; 23 bool com(const v t1, const v t2) { 24 return t1.start.x < t2.start.x; 25 } 26 bool com2(const int a, const int b) { 27 return a < b; 28 } 29 int multi(point p1, point p2, point p0) { //判断p1p0和p2p0的关系,<0,p1p0在p2p0的逆时针方向 30 return (p1.x - p0.x)*(p2.y - p0.y) - (p2.x - p0.x)*(p1.y - p0.y); 31 } 32 void inset(point p) { 33 int low = 0, high = n; 34 while (low <= high) { 35 int mid = (high + low) / 2; 36 if (multi(p, edge[mid].start, edge[mid].end) < 0) /*点p1在边的左侧*/ 37 high = mid - 1; 38 else //点p在边的右侧 39 low = mid + 1; 40 } 41 if (multi(p, edge[low-1].start, edge[low-1].end) < 0 ) 42 sum[low-1]++; 43 else 44 sum[low]++; 45 } 46 int main() { 47 while (cin>>n && n) { 48 memset(sum, 0, sizeof(sum)); 49 memset(ans, 0, sizeof(ans)); 50 cin >> m >> x1 >> y11 >> x2 >> y2; 51 for (int i = 0; i < n; i++) { 52 cin >> Ui >> Li; 53 edge[i].start.x = Ui; 54 edge[i].start.y = y11; 55 edge[i].end.x = Li; 56 edge[i].end.y = y2; 57 } 58 edge[n].start.x = x2; 59 edge[n].start.y = y11; 60 edge[n].end.x = x2; 61 edge[n].end.y = y2; 62 sort(edge, edge + n + 1, com); 63 for (int j = 0; j < m; j++) { 64 cin >> Xj >> Yj; 65 tp.x = Xj; 66 tp.y = Yj; 67 inset(tp); 68 } 69 for (int i = 0; i <= n; i++) 70 { 71 if (sum[i] != 0) 72 ans[sum[i]]++; 73 } 74 cout << "Box" << endl; 75 for (int i = 0; i <= n; i++) 76 { 77 if (ans[i] != 0) 78 cout << i << ": " << ans[i] << endl; 79 } 80 } 81 return 0; 82 }
1 再熟悉一下叉积函数 2 int multi(point p1, point p2, point p0) { 3 return (p1.x - p0.x)*(p2.y - p0.y) - (p2.x - p0.x)*(p1.y - p0.y); 4 } 5 //判断p1p0和p2p0的关系 6 //结果<0, p1p0在p2p0的逆时针方向,即点p1在p2p0的左侧 7 //结果>0, p1p0在p2p0的顺时针方向,即点p1在p2p0的右侧
POJ 2398--Toy Storage(叉积判断,二分找点,点排序)
标签:顺序 sort sizeof jpg sorted header amp close 区域
原文地址:https://www.cnblogs.com/FlyerBird/p/9270719.html