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的更多相关文章

  1. POJ 2398 - Toy Storage 点与直线位置关系

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5439   Accepted: 3234 Descr ...

  2. POJ 2398 Toy Storage(计算几何,叉积判断点和线段的关系)

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3146   Accepted: 1798 Descr ...

  3. POJ 2318 TOYS && POJ 2398 Toy Storage(几何)

    2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而231 ...

  4. 2018.07.04 POJ 2398 Toy Storage(二分+简单计算几何)

    Toy Storage Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad have a problem: their ch ...

  5. POJ 2398 Toy Storage (叉积判断点和线段的关系)

    题目链接 Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4104   Accepted: 2433 ...

  6. poj 2398 Toy Storage(计算几何)

    题目传送门:poj 2398 Toy Storage 题目大意:一个长方形的箱子,里面有一些隔板,每一个隔板都可以纵切这个箱子.隔板将这个箱子分成了一些隔间.向其中扔一些玩具,每个玩具有一个坐标,求有 ...

  7. poj2398 Toy Storage 计算几何,叉积,二分

    poj2398 Toy Storage 链接 poj 题目大意 这道题的大概意思是先输入6个数字:n,m,x1,y1,x2,y2.n代表卡片的数量,卡片竖直(或倾斜)放置在盒内,可把盒子分为n+1块区 ...

  8. poj 2398 Toy Storage(计算几何 点线关系)

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4588   Accepted: 2718 Descr ...

  9. POJ 2398 Toy Storage(计算几何)

    题意:给定一个如上的长方形箱子,中间有n条线段,将其分为n+1个区域,给定m个玩具的坐标,统计每个区域中的玩具个数. 题解:通过斜率判断一个点是否在两条线段之间. /** 通过斜率比较点是否在两线段之 ...

随机推荐

  1. ThinkPHP函数详解:M方法

    M方法用于实例化一个基础模型类,和D方法的区别在于:1.不需要自定义模型类,减少IO加载,性能较好:2.实例化后只能调用基础模型类(默认是Model类)中的方法:3.可以在实例化的时候指定表前缀.数据 ...

  2. sql语法:inner join on, left join on, right join on具体用法

    inner join(等值连接) 仅仅返回两个表中联结字段相等的行 left join(左联接) 返回包含左表中的全部记录和右表中联结字段相等的记录 right join(右联接) 返回包含右表中的全 ...

  3. mongo数据管理java简易版

    mongo是搭建在局域网服务器上的,处理起来比较麻烦,于是自己写了个简单的处理工具. 如果有对java操作mongo不太了解的也可以在这里看下简单的示例. 只有增删改查的功能,而且只支持json格式的 ...

  4. Android(java)学习笔记143:android提供打开各种文件的API接口:setDataAndType

    android 打开各种文件(setDataAndType) private void openFile(File file){ Intent intent = new Intent(); inten ...

  5. 无法从“object”转换为“string”

    就我在项目中遇到的问题,和大家分享一下“无法从“object”转换为“string” 在把我出错的代码复制上来,  Guid userid = new Guid(Membership.GetUser( ...

  6. 一种协程的 C/C++ 实现

    一种协程的 C/C++ 实现 介绍 在前几天接触到了协程的概念,觉得很有趣.因为我可以使用一个线程来实现一个类似多线程的程序,如果使用协程来替代线程,就可以省去很多原子操作和内存栅栏的麻烦,大大减少与 ...

  7. 获取tcl开发工具

    本篇文章对tcl脚本的解释工具获取和编辑工具进行一个简单的介绍,工欲善其事,必先利其器,掌握好解释工具的用法,能够使后续的脚本开发工作更加顺利.从源代码的获取到编译,详细解释在linux和window ...

  8. ElastciSearch常用APi

    列出所有的索引: GET /_cat/indices?v 删除索引 DELETE /customer?pretty

  9. 无法打开登录所请求的数据库 "XXX"。登录失败。 用户 'NT AUTHORITY\SYSTEM' 登录失败。

    1.打开数据库安全性-登录名 2.选择NT AUTHORITY\SYSTEM右键属性 3.选择服务器角色勾选sysadmin选项保存

  10. 用友U8按BOM计算销售订单物料需求SQL代码 第一稿

    drop table #tmp1999 drop table #tmp2999 drop table #tmp3999 drop table #tmp4999 drop table #tmp5999 ...