标签:style blog class code java c
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 res[5005]; 18 int cross(point p1,point p2,point p0){ 19 return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x); 20 } 21 22 bool cmp(line c,line d){ 23 return c.b.x < d.b.x ; 24 } 25 26 int main() 27 { 28 int n,m,x1,x2,y1,y2; 29 int t1,t2; 30 point c; 31 while(cin>>n&&n){ 32 cin>>m>>x1>>y1>>x2>>y2; 33 lline[0].a.x=x1,lline[0].a.y=y1; 34 lline[0].b.x=x1,lline[0].b.y=y2; 35 lline[n+1].a.x = x2,lline[n+1].a.y=y1; 36 lline[n+1].b.x = x2,lline[n+1].b.y=y2; 37 for(int i=1;i<=n;i++){ 38 scanf("%d%d",&t1,&t2); 39 lline[i].a.x=t1; 40 lline[i].a.y=y1; 41 lline[i].b.x=t2; 42 lline[i].b.y=y2; 43 } 44 45 sort(lline,lline+n+2,cmp); 46 // for(int i=0;i<n+2;i++) 47 // cout<<lline[i].b.x<<" "<<lline[i].b.y<<" "<<lline[i].a.x<<" "<<lline[i].a.y<<endl; 48 memset(cnt,0,sizeof(cnt)); 49 for(int i=0;i<m;i++){ 50 cin>>c.x>>c.y; 51 for(int j=0;j<n+2;j++){ 52 //cout<<j<<" "<<cross(c,lline[j].a,lline[j].b)<<endl; 53 if(cross(c,lline[j].a,lline[j].b)>0){ 54 continue; 55 }else{ 56 cnt[j-1]++; 57 break; 58 } 59 } 60 } 61 // for(int i=0;i<=n;i++) 62 // cout<<cnt[i]<<endl; 63 memset(res,0,sizeof(res)); 64 for(int i=0;i<=n;i++){ 65 res[cnt[i]]++; 66 } 67 cout<<"Box"<<endl; 68 for(int i=1;i<=n;i++)if(res[i]) 69 cout<<i<<": "<<res[i]<<endl; 70 } 71 return 0; 72 }
标签:style blog class code java c
原文地址:http://www.cnblogs.com/Bang-cansee/p/3724235.html