TOYS

http://poj.org/problem?id=2318

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 19301   Accepted: 9106

Description

Calculate the number of toys that land in each bin of a partitioned toy box. 
Mom and dad have a problem - their child John never puts his toys away when he is finished playing with them. They gave John a rectangular box to put his toys in, but John is rebellious and obeys his parents by simply throwing his toys into the box. All the toys get mixed up, and it is impossible for John to find his favorite toys.

John's parents came up with the following idea. They put cardboard partitions into the box. Even if John keeps throwing his toys into the box, at least toys that get thrown into different bins stay separated. The following diagram shows a top view of an example toy box. 
 
For this problem, you are asked to determine how many toys fall into each partition as John throws them into the toy box.

Input

The input file contains one or more problems. The first line of a problem consists of six integers, n m x1 y1 x2 y2. The number of cardboard partitions is n (0 < n <= 5000) and the number of toys is m (0 < m <= 5000). The coordinates of the upper-left corner and the lower-right corner of the box are (x1,y1) and (x2,y2), respectively. The following n lines contain two integers per line, Ui Li, indicating that the ends of the i-th cardboard partition is at the coordinates (Ui,y1) and (Li,y2). You may assume that the cardboard partitions do not intersect each other and that they are specified in sorted order from left to right. The next m lines contain two integers per line, Xj Yj specifying where the j-th toy has landed in the box. The order of the toy locations is random. You may assume that no toy will land exactly on a cardboard partition or outside the boundary of the box. The input is terminated by a line consisting of a single 0.

Output

The output for each problem will be one line for each separate bin in the toy box. For each bin, print its bin number, followed by a colon and one space, followed by the number of toys thrown into that bin. Bins are numbered from 0 (the leftmost bin) to n (the rightmost bin). Separate the output of different problems by a single blank line.

Sample Input

5 6 0 10 60 0
3 1
4 3
6 8
10 10
15 30
1 5
2 1
2 8
5 5
40 10
7 9
4 10 0 10 100 0
20 20
40 40
60 60
80 80
5 10
15 10
25 10
35 10
45 10
55 10
65 10
75 10
85 10
95 10
0

Sample Output

0: 2
1: 1
2: 1
3: 1
4: 0
5: 1 0: 2
1: 2
2: 2
3: 2
4: 2

Hint

As the example illustrates, toys that fall on the boundary of the box are "in" the box.
 
基础几何题,懒得写二分,直接暴力过了= =
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std; struct Point{
double x,y;
}; struct Line{
Point a,b;
}line[]; double Cross(Point A,Point B,Point C){
return (B.x-A.x)*(C.y-A.y)-(B.y-A.y)*(C.x-A.x);
} int ans[]; int main(){
int n,m;
double x1,y1,x2,y2,x,y;
int co=;
while(cin>>n){
if(!n) break;
memset(ans,,sizeof(ans));
cin>>m>>x1>>y1>>x2>>y2;
Point a,b;
if(co) cout<<endl;
for(int i=;i<n;i++){
cin>>x>>y;
a.x=x,a.y=y1;
b.x=y,b.y=y2;
line[i].a=a,line[i].b=b;
}
int j;
for(int i=;i<m;i++){
cin>>x>>y;
a.x=x,a.y=y;
for(j=;j<n;j++){
if(Cross(line[j].b,line[j].a,a)>){
break;
}
}
ans[j]++;
}
for(int i=;i<=n;i++){
cout<<i<<": "<<ans[i]<<endl;
}
co++;
}
}

TOYS(叉积)的更多相关文章

  1. POJ2318 TOYS[叉积 二分]

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14433   Accepted: 6998 Description ...

  2. POJ 2318 TOYS (叉积+二分)

    题目: Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and ...

  3. 【POJ 2318】TOYS 叉积

    用叉积判断左右 快速读入写错了卡了3小时hhh #include<cmath> #include<cstdio> #include<cstring> #includ ...

  4. POJ 2318 TOYS 叉积

    题目大意:给出一个长方形盒子的左上点,右下点坐标.给出n个隔板的坐标,和m个玩具的坐标,求每个区间内有多少个玩具. 题目思路:利用叉积判断玩具在隔板的左方或右方,并用二分优化查找过程. #includ ...

  5. POJ2318 TOYS(叉积判断点与直线的关系+二分)

    Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a prob ...

  6. POJ 2318 TOYS (计算几何,叉积判断)

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8661   Accepted: 4114 Description ...

  7. POJ2318:TOYS(叉积判断点和线段的关系+二分)&&POJ2398Toy Storage

    题目:http://poj.org/problem?id=2318 题意: 给定一个如上的长方形箱子,中间有n条线段,将其分为n+1个区域,给定m个玩具的坐标,统计每个区域中的玩具个数.(其中这些线段 ...

  8. POJ-2318 TOYS,暴力+叉积判断!

                                                                 TOYS 2页的提交记录终于搞明白了. 题意:一个盒子由n块挡板分成n+1块区 ...

  9. POJ 2318 TOYS(叉积+二分)

    题目传送门:POJ 2318 TOYS Description Calculate the number of toys that land in each bin of a partitioned ...

  10. POJ 2318 TOYS【叉积+二分】

    今天开始学习计算几何,百度了两篇文章,与君共勉! 计算几何入门题推荐 计算几何基础知识 题意:有一个盒子,被n块木板分成n+1个区域,每个木板从左到右出现,并且不交叉. 有m个玩具(可以看成点)放在这 ...

随机推荐

  1. ASP.NET Web Pages:C# 和 VB 实例

    ylbtech-.Net-ASP.NET Web Pages:C# 和 VB 实例 1.返回顶部 1. ASP.NET Web Pages - C# 和 VB 实例 通过 C# 和 Visual Ba ...

  2. ASP.NET Web Pages:帮助器

    ylbtech-.Net-ASP.NET Web Pages:帮助器 1.返回顶部 1. ASP.NET Web Pages - 帮助器 Web 帮助器大大简化了 Web 开发和常见的编程任务. AS ...

  3. VMware仅主机模式访问外网

    原文转载至:https://blog.csdn.net/eussi/article/details/79054622 保证VMware Network Adapter VMnet1是启用状态  将可以 ...

  4. unity3d的碰撞检测及trigger

    A.基本概念 要产生碰撞必须为游戏对象添加刚体(Rigidbody)和碰撞器,刚体可以让物体在物理影响下运动.碰撞体是物理组件的一类,它要与刚体一起添加到游戏对象上才能触发碰撞.如果两个刚体相互撞在一 ...

  5. PHP流程控制 - if 语句

    PHP - if 语句 if 语句用于仅当指定条件成立时执行代码. 语法 if (条件) { 条件成立时要执行的代码; } 如果当前时间小于 20,下面的实例将输出 "Have a good ...

  6. 开发组件:REST API

    REST API 最佳入门指南 https://blog.csdn.net/px01ih8/article/details/78674685

  7. MyBatis 中#与$的区别

    今天在工作中有个点击排序的功能调试了许久,终寻因,总结之.  需求是这样的,页面有个table,有一列的上下箭头可点击并排序.对于这种需求,我的mybatis.xml的sql配置写成了如下: < ...

  8. 并发工具类(三)控制并发线程的数量 Semphore

    前言   JDK中为了处理线程之间的同步问题,除了提供锁机制之外,还提供了几个非常有用的并发工具类:CountDownLatch.CyclicBarrier.Semphore.Exchanger.Ph ...

  9. 常用数据库2 mysql

    知识内容: 1.MySQL介绍及安装使用 2.MySQL管理 3.MySQL数据类型 4.MySQL常用命令 5.事务 6.索引 参考: http://www.cnblogs.com/alex3714 ...

  10. [Flutter] Android沉侵式标题栏顶部叠加层去除

    可能你的app是这样: 框起来部分和标题栏颜色并不一致. 调用下面的代码可以变成一样. import 'package:flutter/services.dart'; static SystemUiO ...