poj2398
题解:
计算几何入门题
对每个二分最近的在它右边的杆子
如何判断一个杆子在它右边呢
计算机判断这些要更善于利用点积和叉积
如果叉积为正代表在顺时针方向叉积为负在逆时针
发现要在struct里面重载运算符和struct调用struct
就必须要
Point() {}
Point(int x1,int y1)
{
x=x1; y=y1;
}
代码:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
#define rint register int
#define IL inline
#define rep(i,h,t) for (int i=h;i<=t;i++)
#define dep(i,t,h) for (int i=t;i>=h;i--)
#define me(x) memset(x,0,sizeof(x))
#define mid ((h+t)>>1)
#define ll long long
const int N=1e4;
int n,m,x1,y1,x2,y2,x,y,ans[N],num[N];
struct Point{
int x,y;
Point() {}
Point(int x1,int y1)
{
x=x1; y=y1;
}
Point operator +(const Point &b) const
{
return Point(x+b.x,y+b.y);
}
Point operator -(const Point &b) const
{
return Point(x-b.x,y-b.y);
}
int operator *(const Point &b) const
{
return x*b.x+y*b.y;
}
int operator ^(const Point &b) const
{
return x*b.y-y*b.x;
}
};
struct Line{
Line(){}
Point s,e;
Line(Point s1,Point e1)
{
s=s1,e=e1;
}
}l[N];
bool cmp(Line x,Line y)
{
return x.s.x<y.s.x;
}
IL bool check(Line x,Point y)
{
return ((y-x.s)^(x.e-x.s))<?:;
}
int main()
{
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
ios::sync_with_stdio(false);
while (cin>>n&&n)
{
cin>>m>>x1>>y1>>x2>>y2;
rep(i,,n)
{
cin>>x>>y;
l[i]=Line(Point(x,y1),Point(y,y2));
}
n++;
l[n]=Line(Point(x2,y1),Point(x2,y2));
sort(l+,l+n+,cmp);
me(ans); me(num);
while (m--)
{
cin>>x>>y;
Point p=Point(x,y);
int h=,t=n;
while (h<t)
{
if (check(l[mid],p)) t=mid; else h=mid+;
}
ans[h]++;
}
rep(i,,n) if (ans[i]>) num[ans[i]]++;
cout<<"Box"<<endl;
rep(i,,n)
if (num[i]>) cout<<i<<": "<<num[i]<<endl;
}
return ;
}
poj2398的更多相关文章
- poj2398 Toy Storage 计算几何,叉积,二分
poj2398 Toy Storage 链接 poj 题目大意 这道题的大概意思是先输入6个数字:n,m,x1,y1,x2,y2.n代表卡片的数量,卡片竖直(或倾斜)放置在盒内,可把盒子分为n+1块区 ...
- [POJ2398]Toy Storage(计算几何,二分,判断点在线段的哪一侧)
题目链接:http://poj.org/problem?id=2398 思路RT,和POJ2318一样,就是需要排序,输出也不一样.手工画一下就明白了.注意叉乘的时候a×b是判断a在b的顺时针还是逆时 ...
- poj2398计算几何叉积
Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing ...
- POJ2398【判断点在直线哪一侧+二分查找区间】
题意:同POJ2318 #include<algorithm> #include<cstdio> #include<cstdlib> #include<cst ...
- POJ2398(KB13-B 计算几何)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5968 Accepted: 3573 Descr ...
- POJ-2398
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4243 Accepted: 2517 Descr ...
- [poj2398]Toy Storage
接替关键:和上题类似,输出不同,注意输入这道题需要排序. #include<cstdio> #include<cstring> #include<algorithm> ...
- ACM/ICPC 之 计算几何入门-叉积-to left test(POJ2318-POJ2398)
POJ2318 本题需要运用to left test不断判断点处于哪个分区,并统计分区的点个数(保证点不在边界和界外),用来做叉积入门题很合适 //计算几何-叉积入门题 //Time:157Ms Me ...
- ACM训练计划建议(写给本校acmer,欢迎围观和指正)
ACM训练计划建议 From:freecode# Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...
随机推荐
- python3+selenium入门01-环境搭建
作为一个测试,在最近两年应该有明显的感觉.那就是工作变的难找,要求变的高了,自动化测试,性能测试等.没有自动化测试能力,只会点点点工作难找不说,工资也不高.所以还是要学习一些技术.首先要学习一门编程语 ...
- MySQL--详细查询操作(单表记录查询、多表记录查询(连表查询)、子查询)
一.单表查询 1.完整的语法顺序(可以不写完整,其次顺序要对) (不分组,且当前表使用聚合函数: 当前表为一组,显示统计结果 ) select distinct [*,查询字段1,查询字段2,表达式, ...
- SSL For Free 申请免费https SSL 凭证
打开 SSL For Free网站(https://www.sslforfree.com) ,在输入框中填入你要申请 Let’s Encrypt 凭证的网域名称,可以用空白来分隔不同的网址,例如[su ...
- LabVIEW---vi图标和符号的制作
前言: 使用图形化设计语言进行开发时候,为VI添加说明的一个重要的方法是为其建立一个形象的图标,每个VI都在前面板后程序框图的右上角有一个图标,它是VI的图形化表示.如果VI当作子VI调用,该图标就会 ...
- Shiro配置URL过滤
常用过滤器: anon 不需要认证 authc 需要认证 user 验证通过或RememberMe登录的都可以 URL说明: /admin?=authc 表示 ...
- Goland could not launch process: decoding dwarf section info at offset 0x0: too short 解决方案
1 前言 Goland版本:2018.1.5 Go:1.11.2 此版本调试不了bug,而且有时会显示could not launch process: decoding dwarf section ...
- MYSQL修改字段
当字段为空则插入0,不为空则原来的值 UPDATE t_pm_scheduleSET lesson_room_id1 = IFNULL(lesson_room_id1, 0), lesson_roo ...
- 给Linux增加swap内存
有时内存不足时, 编译xxx报错cc: 编译器内部错误:已杀死(程序 cc1) Please submit a full bug report, with preprocessed source if ...
- Confluence 6 找到你的支持识别代码(SEN)
你可以在下面 3 个地方找到你的 SEN 代码: 在 Confluence 中,进入 > 基本配置(General Configuration) > 许可证详细(License Deta ...
- 华为手机浏览器 onclick失灵的问题
开发h5 遇到的问题是华为浏览器onclick 点击失灵. 下面这个网站是检查 浏览器是否支持es6语法的网站 http://ruanyf.github.io/es-checker/index.cn. ...