TOYS(叉积)
TOYS
http://poj.org/problem?id=2318
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 19301 | Accepted: 9106 |
Description
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
Output
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
#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(叉积)的更多相关文章
- POJ2318 TOYS[叉积 二分]
TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14433 Accepted: 6998 Description ...
- POJ 2318 TOYS (叉积+二分)
题目: Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and ...
- 【POJ 2318】TOYS 叉积
用叉积判断左右 快速读入写错了卡了3小时hhh #include<cmath> #include<cstdio> #include<cstring> #includ ...
- POJ 2318 TOYS 叉积
题目大意:给出一个长方形盒子的左上点,右下点坐标.给出n个隔板的坐标,和m个玩具的坐标,求每个区间内有多少个玩具. 题目思路:利用叉积判断玩具在隔板的左方或右方,并用二分优化查找过程. #includ ...
- POJ2318 TOYS(叉积判断点与直线的关系+二分)
Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a prob ...
- POJ 2318 TOYS (计算几何,叉积判断)
TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8661 Accepted: 4114 Description ...
- POJ2318:TOYS(叉积判断点和线段的关系+二分)&&POJ2398Toy Storage
题目:http://poj.org/problem?id=2318 题意: 给定一个如上的长方形箱子,中间有n条线段,将其分为n+1个区域,给定m个玩具的坐标,统计每个区域中的玩具个数.(其中这些线段 ...
- POJ-2318 TOYS,暴力+叉积判断!
TOYS 2页的提交记录终于搞明白了. 题意:一个盒子由n块挡板分成n+1块区 ...
- POJ 2318 TOYS(叉积+二分)
题目传送门:POJ 2318 TOYS Description Calculate the number of toys that land in each bin of a partitioned ...
- POJ 2318 TOYS【叉积+二分】
今天开始学习计算几何,百度了两篇文章,与君共勉! 计算几何入门题推荐 计算几何基础知识 题意:有一个盒子,被n块木板分成n+1个区域,每个木板从左到右出现,并且不交叉. 有m个玩具(可以看成点)放在这 ...
随机推荐
- Dell PowerEdge R630服务器VMware ESXI6.0服务器安装
一.Raid 磁阵划分 官方说明:http://www.dell.com/support/article/cn/zh/cndhs1/SLN292050/%E6%88%B4%E5%B0%94%E6%9C ...
- Jade简单教程
Express框架里内嵌了Jade模板引擎.正好项目里也要用到,本篇整理了下Jade的相关用法. 安装与执行 标签和属性 多行文本 变量 语句 Mixin 模板 注释 过滤器 安装与执行 安装很简单: ...
- Hibernate JavaBean.hbm.xml配置
主键生成策略: hibernate中必须设置主键 <generator> 由数据库维护: identity:用于自动生成主键方式(没有自增主键的数据库不使用eg:oracle) seque ...
- Spring MVC springMVC-servlet.xml
DispatcherServlet的配置: DispatcherServlet是SpringMVC的前端控制器,所有的请求都经过前端控制器,也是项目中出现的唯一一个servlet,在 web.xml中 ...
- Spark分析之启动流程
- spring boot 静态变量注入配置文件
spring 静态变量注入 spring 中不支持直接进行静态变量值的注入,我们看一下代码: @Component(value = "KafkaConfig") @Configur ...
- Mysql-事务,原子性操作
事物分为 自动(默认的)和手动(需开启事务)两种 -- 事务 start transaction; -- commite; 提交事务 -- rollback; 回滚事务 create table if ...
- 最近学习下,nohup和&的区别
nohup是永久执行 &是指在后台运行 运行 nohup --helpRun COMMAND, ignoring hangup signals. 可以看到是“运行命令,忽略挂起信号” 就是指, ...
- 19.XPath选择器
1.extract():提取数据 2./text() :获取节点内容文本 3./@href :获取节点href属性 4. @ :获取属性名称 需要注意问题: 用定义的规则那 ...
- Python正则总结
re总结 限定符(就是控制重复次数) ? 匹配前面的子表达式零次或一次.例如,"do(es)?" 可以匹配 "do" . "does" 中的 ...