POJ 2398(同POJ2318)
来源:互联网 发布:banner制作软件 编辑:程序博客网 时间:2024/05/17 23:30
题目:题目链接
题目意思同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; else high=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)
- POJ 2398 Toy Storage POJ2318提高版入门题
- POJ2318(计算几何)
- poj2318
- POJ2318
- poj2318
- poj2318
- poj2318
- poj2318
- poj2318
- poj2318
- Poj2318
- poj2318
- POJ 3844(同余)
- POJ2398(POJ2318的姊妹篇)
- poj2318 TOYS(计算几何)
- poj 2750题鸡兔同笼(java)
- poj 1061(线性同余方程。。。。)
- Android项目导入时,出现的Could not write file 。。。。。。.classpath错误解决办法
- 【diannaoxitong】ThinkPad无线不能用
- 如何在SAS中直接使用Oracle特有函数--sas Pass-Through Facility
- erlang 的快排递归
- histeq && imadjust
- POJ 2398(同POJ2318)
- spring 连接到数据库池以及数据库操作
- ListView常用用法2(分类总结)
- ORCAL WMSYS.WM_CONCAT 函数应用实例及Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]问题出现解决
- numpy中view详解
- 贪心——NYOJ 题目14 会场安排问题
- linux下查看所有硬盘分区+挂接NTFS磁盘/硬盘+自动挂接硬盘方法
- ios利用Reachability确认网络环境3G/WIFI
- 小众音乐电台推荐