【POJ】2318 TOYS ——计算几何+二分
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 10281 | Accepted: 4924 |
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 <cstdio>
#include <cstring> const int LEN = ; struct Point //点的结构体
{
int x;
int y;
}; struct Line //线段的结构体
{
Point a;
Point b;
}line[LEN]; int ans[LEN]; int judge(Line tline, Point p3) //运用叉积的性质判断点在线段的左边还是右边
{
Point t1, t2;
t1.x = p3.x - tline.b.x;
t1.y = p3.y - tline.b.y;
t2.x = tline.a.x - tline.b.x;
t2.y = tline.a.y - tline.b.y;
return t1.x * t2.y - t1.y * t2.x;
} int divide(int l, int r, Point toy) //二分查找
{
int mid = (l + r) / ;
if (mid == l)
return l;
if (judge(line[mid], toy) < )
return divide(l, mid, toy);
else
return divide(mid, r, toy);
} int main()
{
int n, m, x1, y1, x2, y2;
//freopen("in.txt", "r", stdin);
while(scanf("%d", &n) != EOF && n){
scanf("%d %d %d %d %d", &m, &x1, &y1, &x2, &y2);
memset(ans, , sizeof(ans));
for(int i = ; i <= n; i++){
int up, low;
scanf("%d %d", &up, &low);
line[i].a.x = up;
line[i].a.y = y1;
line[i].b.x = low;
line[i].b.y = y2;
}
n++;
line[].a.x = line[].b.x = x1;
line[].b.y = line[n].b.y = y2;
line[].a.y = line[n].a.y = y1;
line[n].a.x = line[n].b.x = x2;
for(int i = ; i < m; i++){
Point toy;
scanf("%d %d", &toy.x, &toy.y);
ans[divide(, n, toy)]++;
}
for(int i = ; i < n; i++){
printf("%d: %d\n", i, ans[i]);
}
printf("\n");
}
return ;
}
【POJ】2318 TOYS ——计算几何+二分的更多相关文章
- 2018.07.03 POJ 2318 TOYS(二分+简单计算几何)
TOYS Time Limit: 2000MS Memory Limit: 65536K Description Calculate the number of toys that land in e ...
- POJ 2318 TOYS (叉积+二分)
题目: Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and ...
- poj 2318 TOYS(计算几何 点与线段的关系)
TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12015 Accepted: 5792 Description ...
- POJ 2318 TOYS(计算几何)
跨产品的利用率推断点线段向左或向右,然后你可以2分钟 代码: #include <cstdio> #include <cstring> #include <algorit ...
- POJ 2318 TOYS(叉积+二分)
题目传送门:POJ 2318 TOYS Description Calculate the number of toys that land in each bin of a partitioned ...
- poj 2318 TOYS (二分+叉积)
http://poj.org/problem?id=2318 TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 101 ...
- 简单几何(点与线段的位置) POJ 2318 TOYS && POJ 2398 Toy Storage
题目传送门 题意:POJ 2318 有一个长方形,用线段划分若干区域,给若干个点,问每个区域点的分布情况 分析:点和线段的位置判断可以用叉积判断.给的线段是排好序的,但是点是无序的,所以可以用二分优化 ...
- POJ 2318 TOYS && POJ 2398 Toy Storage(几何)
2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而231 ...
- 向量的叉积 POJ 2318 TOYS & POJ 2398 Toy Storage
POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由ab ...
随机推荐
- javascript 事件设计模式
http://plkong.iteye.com/blog/213543 1. 事件设计概述 事件机制可以是程序逻辑更加清晰可见,在JavaScript中很多对象都有自己的事件,如:button有onc ...
- COB(Chip On Board)的製程簡單介紹
前面提及 COB 的生產與 IC 的封裝製程幾乎是一致的,除了把 leadframe 改成了 PCB,把封膠由 molding 改成 dispensing,少了 triming & marki ...
- 一道C语言面试题:写一个宏,将16位的整数转为Big Endian
题目:输入16位整数x,如0x1234,将其转为Big Endian格式再输出,此例为输出 0x3412 来源:某500强企业面试题目 思路:将x左移8位得到a,将x右移8位得到b,a+b即为所得 / ...
- 调用Windows属性窗口(居然是通过注册表来调用的)
简述 在Windows系统下.可以通过:右键 -> 属性,来查看文件/文件夹对应的属性信息,包括:常规.安全.详细信息等. 简述 共有类型 共有类型 首先,需要包含头文件: #include & ...
- 将文件放到Android模拟器的SD卡中的两种解决方法
两种方式:一.窗口界面操作1.打开DDMS页面2.打开File Explorer页,如果没有,在Window --> Show View -->File Explorer3.一般就在mnt ...
- Android SDK目录结构和工具介绍
Android SDK目录结构和工具介绍是本文要介绍的内容,主要是来了解并学习Android SDK的内容,具体关于Android SDK内容的详解来看本文. AD: Android SDK目录结构和 ...
- Longge的问题(欧拉,思维)
Longge的问题 Submit Status Practice HYSBZ 2705 Description Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一 ...
- mysql 初始化
一.centos7下mysql 安装配置 yum -y install mariadb* systemctl start mariadb.service systemctl enable mariad ...
- js的事件属性方法一览表
event对象常用属性和方法 event 对象用来表示当前事件,事件有很多状态,例如,鼠标单击时的位置,按下键盘时的按键,发生事件的HTML元素,是否执行默认动作,是否冒泡等,这些都是作为event对 ...
- 《think in python》学习-7
think in python 7 迭代 对一个变量可以进行多次赋值 是合法的. 例如以下: bruce = 5 print bruce bruce = 7 print bruce 因为有了多重赋值 ...