本文主要是介绍POJ 2398(同POJ2318),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:题目链接
题目意思同2318,只不过加了线段排序。再者输出每一种数量有几个格子就OK:
代码:
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <map>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
using namespace std;const int M=1030;
const double eps=1e-8;
struct point
{__int64 x,y;
} p[M],q;
struct rec
{point p[4];
} r[M];
__int64 cnt[M],cnt1[M];
int n,m;void init()
{for(int i=0; i<=n+1; i++)cnt[i]=cnt1[i]=0;
}double cross(double x1,double y1,double x2,double y2)
{return x1*y2-x2*y1;
}void search()
{int low=0,high=n;bool flag=false;while(low<=high){int mid=(low+high)>>1;double temp1=cross(r[mid].p[0].x-q.x,r[mid].p[0].y-q.y,r[mid].p[1].x-q.x,r[mid].p[1].y-q.y);double temp2=cross(r[mid].p[3].x-q.x,r[mid].p[3].y-q.y,r[mid].p[2].x-q.x,r[mid].p[2].y-q.y);if(temp1>=eps && temp2<=-eps){cnt[mid]++;return ;}if(temp2>eps)low=mid+1;elsehigh=mid-1;}
}bool cmp(point p,point q)
{return p.x<q.x;
}int main()
{while(scanf("%d",&n)==1){if(!n) break;init();scanf("%d",&m);scanf("%I64d%I64d%I64d%I64d",&r[0].p[0].x,&r[0].p[0].y,&r[n].p[2].x,&r[n].p[2].y);r[0].p[1].x=r[0].p[0].x;r[0].p[1].y=r[n].p[2].y;r[n].p[3].x=r[n].p[2].x;r[n].p[3].y=r[0].p[0].y;for(int i=1; i<=n; i++){scanf("%I64d%I64d",&p[i].x,&p[i].y);}sort(p+1,p+n+1,cmp);for(int i=1; i<=n; i++){r[i-1].p[3].x=p[i].x;r[i-1].p[3].y=r[i-1].p[0].y;r[i-1].p[2].x=p[i].y;r[i-1].p[2].y=r[i-1].p[1].y;r[i].p[0].x=p[i].x;r[i].p[0].y=r[i-1].p[3].y;r[i].p[1].x=p[i].y;r[i].p[1].y=r[i-1].p[2].y;}for(int i=0; i<m; i++){scanf("%I64d%I64d",&q.x,&q.y);search();}printf("Box\n");for(int i=0; i<=n; i++){if(cnt[i])cnt1[cnt[i]]++;}for(int i=1; i<=m; i++){if(cnt1[i])printf("%d: %I64d\n",i,cnt1[i]);}}return 0;
}
努力努力...
这篇关于POJ 2398(同POJ2318)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!