Toy Storage
题型与2318 TOYS一样,注意要对线段排序,现在模板又更新了~~
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<time.h>
using namespace std;
#define MS0(a) memset(a,0,sizeof(a))
const int MAXN = ;
struct point{
int x,y;
point(){}
point(int _x,int _y){
x = _x; y = _y;
}
long long operator *(const point &b)const{// 点向量叉乘
return (1LL*x*b.y - 1LL*y*b.x);
}
point operator -(const point &b)const{
return point(x - b.x,y - b.y);
}
long long dot(const point &b){ //点乘
return 1LL*x*b.x + 1LL*y*b.y;
}
double dist(const point &b){
return sqrt(1LL*(x-b.x)*(x-b.x)+1LL*(y-b.y)*(y-b.y));
}
long long dist2(const point &b){
return 1LL*(x-b.x)*(x-b.x)+1LL*(y-b.y)*(y-b.y);
}
double len(){
return sqrt(1LL*x*x+1LL*y*y);
}
double point_to_segment(point b,point c)//点a到“线段” bc的距离
{
point v[];
v[] = {c.x - b.x,c.y - b.y};
v[] = {x - b.x,y - b.y};
v[] = {x - c.x,y - c.y};
if(v[].dot(v[]) < ) return v[].len();
if(v[].dot(v[]) > ) return v[].len();
return fabs(.*(v[]*v[])/v[].len());
}
long long Xmult(point b,point c){ // 当a->b与a->c顺时针转时,返回正;
return (b-*this)*(c-*this);
}
bool operator <(const point &b)const{
return y < b.y||(y == b.y && x < b.x);
}
void input(){
scanf("%d%d",&x,&y);
}
}p[MAXN]; struct Line{
point s,t;
Line(){}
Line(point _s,point _t){
s = _s,t =_t;
}
bool operator <(const Line &b)const{
return s < b.s;
}
}line[MAXN]; int ans[MAXN],ret[MAXN];
int main()
{
int n,m,i,j,x1,y1,x2,y2,kase = ,U,L;
while(scanf("%d",&n),n){
MS0(ans);
MS0(ret);
scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2);
for(i = ;i <= n;i++){
scanf("%d%d",&U,&L);
line[i] = Line(point(U,y1),point(L,y2));
}
sort(line+,line+n+);
line[] = Line(point(x1,y1),point(x1,y2));
int x,y;
for(i = ;i < m;i++){
scanf("%d%d",&x,&y);
int l = , r = n,tmp;
while(l <= r){
int mid = l + r >> ;
if( point(x,y).Xmult(line[mid].s,line[mid].t) <= ) r = mid-; //在线的上边
else tmp = mid,l = mid+; //线下的点所在的区域才是改line的标号;
}
ret[tmp]++;
}
for(i = ;i <= n;i++){
ans[ret[i]]++;
}
puts("Box");
for(i = ;i <= m;i++)if(ans[i])
printf("%d: %d\n",i,ans[i]);
}
return ;
}
Toy Storage的更多相关文章
- POJ 2398 - Toy Storage 点与直线位置关系
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5439 Accepted: 3234 Descr ...
- POJ 2398 Toy Storage(计算几何,叉积判断点和线段的关系)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3146 Accepted: 1798 Descr ...
- POJ 2318 TOYS && POJ 2398 Toy Storage(几何)
2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而231 ...
- 2018.07.04 POJ 2398 Toy Storage(二分+简单计算几何)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad have a problem: their ch ...
- POJ 2398 Toy Storage (叉积判断点和线段的关系)
题目链接 Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4104 Accepted: 2433 ...
- poj 2398 Toy Storage(计算几何)
题目传送门:poj 2398 Toy Storage 题目大意:一个长方形的箱子,里面有一些隔板,每一个隔板都可以纵切这个箱子.隔板将这个箱子分成了一些隔间.向其中扔一些玩具,每个玩具有一个坐标,求有 ...
- poj2398 Toy Storage 计算几何,叉积,二分
poj2398 Toy Storage 链接 poj 题目大意 这道题的大概意思是先输入6个数字:n,m,x1,y1,x2,y2.n代表卡片的数量,卡片竖直(或倾斜)放置在盒内,可把盒子分为n+1块区 ...
- poj 2398 Toy Storage(计算几何 点线关系)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4588 Accepted: 2718 Descr ...
- POJ 2398 Toy Storage(计算几何)
题意:给定一个如上的长方形箱子,中间有n条线段,将其分为n+1个区域,给定m个玩具的坐标,统计每个区域中的玩具个数. 题解:通过斜率判断一个点是否在两条线段之间. /** 通过斜率比较点是否在两线段之 ...
随机推荐
- new的例子
12.6 编写函数,返回一个动态分配的int的vector.将此vector传递给另一个函数,这个函数读取标准输入,将读入的值保存在vector元素中.再将vector传递给另一个函数,打印读入的值. ...
- BeagleBone Black Linux驱动程序开发入门(0): 开发环境
搭建arm-linux交叉编译环境的教程有很多,这里只作简要说明.Host宿主机是Ubuntu10.04,我把它装在Windows XP的VirtualBox虚拟机中,这样相当于一台主机有两个操作系统 ...
- merge into sql优化
今天网友说他的merge into sql跑了15分钟了还没有跑出数据,问我能不能优化一下,我让他把sql和sql的执行计划发过来 merge into F_Sal_P_Camp_Samp_Cust_ ...
- start mysqld on Mac server
#!/bin/sh # Source the common setup functions for startup scripts test -r /etc/rc.common || exit 1 . ...
- 深入理解计算机系统第二版习题解答CSAPP 2.1
A.将0x39A7F8转换为二进制. 0011 1001 1010 0111 1111 1000 B.将二进制1100 1001 0111 1011转换为十六进制. 0xC97B C.将0xD5E ...
- UPDATE---修改表中数据
UPDATE table_name SET column1=value1,column2=value2,... [WHERE conditions]; 例: UPDATE userinfo SET n ...
- 获取select下拉列表选中的值
html: <select id="resultList"> <option >1班</option> <option >2班< ...
- Oracle+FluentData+MVC4+EasyUI开发权限管理系统之开篇
在园子里有很多EF+MVC+EasyUI的框架实在是太多了,经过在一段时间的学习高手写的思路,但是都是针对Sql数据的,但是今年我当上研发组组长的第一个任务就是编写一个通用平台框架,一刚开始想把学习过 ...
- MVC 避免黄页
可以使用HandleErrorAttribute 有两种方式可以使用它,在类或者方法的头上加 [HandleError] 这种直接在类或者方法上加[HandlerError]手动添加 另外一种方式是使 ...
- Visual C++ 打印编程技术-编程基础
背景: windows产生前,操作系统(如DOS等)都不提供支持图像处理的打印机驱动程序,使得程序员为打印出图像,不得不针对使用的打印机 自己编写设备驱动程序,导致了大量的.不必要的重复开发. 随着w ...