题目大意:和 TOY题意一样,但是需要对隔板从左到右进行排序,要求输出的是升序排列的含有i个玩具的方格数,以及i值。

题目思路:判断叉积,二分遍历

#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<math.h>
#include<map>
#define INF 0x3f3f3f3f
#define MAX 100005
#define Temp 1000000000
#define MOD 1000000007 using namespace std; struct node1
{
int ans;//ans记录方格内玩具数
}a[MAX]; struct node2
{
int up,down;//up为上方x坐标,down为下方x坐标
}b[MAX]; int x[MAX],y[MAX],n,m,X1,Y1,X2,Y2,num[MAX];//num记录内有i个玩具的方格数 int cmp(struct node2 A,struct node2 B)
{
if(A.up!=B.up)
return A.up < B.up;
return A.down < B.down;
} void Init()
{
for(int i=;i<=n;i++)
{
a[i].ans=;
}
memset(num,,sizeof(num));
} int check(int pos,int x1,int y1)//叉积
{
int x3=b[pos].up,x2=b[pos].down,y2=Y1,y3=Y2;
return (x1-x3)*(y3-y2)-(x3-x2)*(y1-y3);
} void Find(int pos)//二分查找隔板
{
int x1=x[pos],y1=y[pos],L=,R=n-;
while(L < R)
{
int Mid=(L+R)/;
if(check(Mid,x1,y1) < )
L=Mid+;
else
R=Mid;
}
if(check(L,x1,y1)>)
a[L].ans++;
else
a[L+].ans++;
} int main()
{
int maxn;
while(scanf("%d",&n),n)
{
Init();
maxn=;
scanf("%d%d%d%d%d",&m,&X1,&Y1,&X2,&Y2);
for(int i=;i<n;i++)
scanf("%d%d",&b[i].down,&b[i].up);
sort(b,b+n,cmp);
for(int i=;i<m;i++)
scanf("%d%d",&x[i],&y[i]);
for(int i=;i<m;i++)//二分查找
{
Find(i);
}
printf("Box\n");
for(int i=;i<=n;i++)
{
num[a[i].ans]++;
maxn=max(maxn,num[a[i].ans]);
}
for(int i=;i<=maxn;i++)
if(num[i]!=)
printf("%d: %d\n",i,num[i]);
}
return ;
}

Toy Storage POJ 2398的更多相关文章

  1. (叉积)B - Toy Storage POJ - 2398

    题目链接:https://cn.vjudge.net/contest/276358#problem/B 题目大意:和上一次写叉积的题目一样,就只是线不是按照顺序给的,是乱序的,然后输出的时候是按照有三 ...

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

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

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

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

  4. 简单几何(点与线段的位置) POJ 2318 TOYS && POJ 2398 Toy Storage

    题目传送门 题意:POJ 2318 有一个长方形,用线段划分若干区域,给若干个点,问每个区域点的分布情况 分析:点和线段的位置判断可以用叉积判断.给的线段是排好序的,但是点是无序的,所以可以用二分优化 ...

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

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

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

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

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

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

  8. 向量的叉积 POJ 2318 TOYS & POJ 2398 Toy Storage

    POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由ab ...

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

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

随机推荐

  1. java 导出excel(简单案例)

    public class Student { private int id; private String name; private int age; private Date birth; pub ...

  2. hdu_5354_Bipartite Graph(cdq分治+并查集判二分图)

    题目链接:hdu_5354_Bipartite Graph 题意: 给你一个由无向边连接的图,问对于每一个点来说,如果删除这个点,剩下的点能不能构成一个二分图. 题解: 如果每次排除一个点然后去DFS ...

  3. 浙江大学 pat 1006题解

    1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

  4. putty命令行提交本地修改文件到git

    使用putty 连接 linux服务器 ,服务器账户和密码在putty 上使用git提交.使用git账户和密码 (需要升级管理员) 01 pwd 查看当前目录print work directory0 ...

  5. 二、ASP.NET MVC Controller 控制器(一:深入解析控制器运行原理)

    阅读目录: 1.开篇介绍 2.ASP.NETMVC Controller 控制器的入口(Controller的执行流程) 3.ASP.NETMVC Controller 控制器的入口(Controll ...

  6. strrchr

    strrchr() 函数查找字符在指定字符串中从正面开始的最后一次出现的位置,如果成功,则返回从该位置到字符串结尾的所有字符,如果失败,则返回 false.与之相对应的是strchr()函数,它查找字 ...

  7. CDOJ 1270 Playfair(模拟)

    题目链接 Playfair is a kind of substitution cipher.And the encryption role is simple.In general,there ar ...

  8. yum安装memcache,mongo扩展以及python的mysql模块安装

    //启动memcached/usr/local/memcached/bin/memcached -d -c 10240 -m 1024 -p 11211 -u root/usr/local/memca ...

  9. LeetCode OJ 88. Merge Sorted Array

    Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:Yo ...

  10. [ An Ac a Day ^_^ ] CodeForces 680A Bear and Five Cards

    这两天回家了 家里电脑太卡 调试不方便 就只能写写水题了…… #include<stdio.h> #include<iostream> #include<algorith ...