POJ2398(KB13-B 计算几何)
Toy Storage
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5968 | Accepted: 3573 |
Description
Reza's parents came up with the following idea. They put cardboard partitions into the box. Even if Reza keeps throwing his toys into the box, at least toys that get thrown into different partitions stay separate. The box looks like this from the top:

We want for each positive integer t, such that there exists a partition with t toys, determine how many partitions have t, toys.
Input
A line consisting of a single 0 terminates the input.
Output
Sample Input
4 10 0 10 100 0
20 20
80 80
60 60
40 40
5 10
15 10
95 10
25 10
65 10
75 10
35 10
45 10
55 10
85 10
5 6 0 10 60 0
4 3
15 30
3 1
6 8
10 10
2 1
2 8
1 5
5 5
40 10
7 9
0
Sample Output
Box
2: 5
Box
1: 4
2: 1
Source
//2017-08-30
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ; struct Point{
int x, y;
Point(){}
Point(int _x, int _y):x(_x), y(_y){}
//a-b 表示向量 ba
Point operator- (const Point &b) const {
return Point(x-b.x, y-b.y);
}
//向量叉积
int operator* (const Point &b) const {
return x*b.y - y*b.x;
}
}A, B; int ans[N], U[N], L[N], t[N];
int n, m; bool check(int id, int x, int y){
if(y == A.y)return x > U[id];
if(y == B.y)return x > L[id];
Point a(L[id], B.y);
Point b(U[id], A.y);
Point c(x, y);
//令I = 向量ab 叉乘 向量 bc,若I为正,点c在向量ab的左侧(沿向量方向看);为负则在右侧
return ((c-a)*(b-a)) > ;
} int get_position(int x, int y){
int l = , r = n+, mid, ans;
while(l <= r){
mid = (l+r)>>;
if(check(mid, x, y)){
ans = mid;
l = mid+;
}else r = mid-;
}
return ans;
} int main()
{
std::ios::sync_with_stdio(false);
freopen("inputB.txt", "r", stdin);
while(cin>>n && n){
cin>>m>>A.x>>A.y>>B.x>>B.y;
U[] = L[] = A.x;
U[n+] = L[n+] = B.x;
for(int i = ; i <= n; i++)
cin>>U[i]>>L[i];
memset(ans, , sizeof(ans));
sort(U, U+n+);
sort(L, L+n+);
int x, y;
for(int i = ; i < m; i++){
cin>>x>>y;
ans[get_position(x, y)]++;
}
memset(t, , sizeof(t));
for(int i = ; i <= n; i++)
t[ans[i]]++;
cout<<"Box"<<endl;
for(int i = ; i <= m; i++)
if(t[i])
cout<<i<<": "<<t[i]<<endl;
} return ;
}
POJ2398(KB13-B 计算几何)的更多相关文章
- poj2398 Toy Storage 计算几何,叉积,二分
poj2398 Toy Storage 链接 poj 题目大意 这道题的大概意思是先输入6个数字:n,m,x1,y1,x2,y2.n代表卡片的数量,卡片竖直(或倾斜)放置在盒内,可把盒子分为n+1块区 ...
- [POJ2398]Toy Storage(计算几何,二分,判断点在线段的哪一侧)
题目链接:http://poj.org/problem?id=2398 思路RT,和POJ2318一样,就是需要排序,输出也不一样.手工画一下就明白了.注意叉乘的时候a×b是判断a在b的顺时针还是逆时 ...
- poj2398计算几何叉积
Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing ...
- ACM/ICPC 之 计算几何入门-叉积-to left test(POJ2318-POJ2398)
POJ2318 本题需要运用to left test不断判断点处于哪个分区,并统计分区的点个数(保证点不在边界和界外),用来做叉积入门题很合适 //计算几何-叉积入门题 //Time:157Ms Me ...
- HDU 2202 计算几何
最大三角形 Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- ACM 计算几何中的精度问题(转)
http://www.cnblogs.com/acsmile/archive/2011/05/09/2040918.html 计算几何头疼的地方一般在于代码量大和精度问题,代码量问题只要平时注意积累模 ...
- hdu 2393:Higher Math(计算几何,水题)
Higher Math Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)
Rescue The Princess Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Several days ago, a b ...
- [知识点]计算几何I——基础知识与多边形面积
// 此博文为迁移而来,写于2015年4月9日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102vxaq.html 1.前言 ...
随机推荐
- 文件上传下载、socketserver(并发)、解读socketserver源码
1.文件上传/下载 学习了socket套接字,我们现在可以写一个文件上传/下载的程序,如下示例: 分析上边代码,我们发现,client发送上传文件相关信息的字典序列化之后,server又给client ...
- Codeforces 1058 D. Vasya and Triangle(分解因子)
题目:http://codeforces.com/contest/1058/problem/D 题意:有一个大小为N*M的矩阵内,构造一个三角形,使面积为(n*m)/k.若存在输出三个顶点(整数). ...
- mysql多列索引和最左前缀
数据库的索引可以加快查询速度,原因是索引使用特定的数据结构(B-Tree)对特定的列额外组织存放,加快存储引擎(索引是存储引擎实现)查找记录的速度.索引优化是数据库优化的最重要手段. 如果查询语句使用 ...
- eclipse maven打war包
在eclipse中找到pom.xml文件右键 选择debug as 再选择Maven install运行后 按路径找到生成的war包 推荐https://www.cnblogs.com/qlqwjy/ ...
- js转换数据格式为货币格式
有时候输资金数据的时候如果位数较多就不好读了,如果输完能转换一下格式,转成用“,”隔开的通用格式就比较好看了.自己写了一个备用,以后用到的话就不用再写了. //将数字转换为货币格式,用,隔开 func ...
- ORA-01113 & ORA-01110同时出现
\NOARCHIVED LOG , 没备份 , Redo Log 被覆盖 , 某个datafile不能online 设计知识点:BBED> set block 1BBED> p kcvfh ...
- 如何使用gradle打jar包
1.进入工程目录,输入./gradlew,如显示"... build success" 则表示当前目录下gradle可用:如当前目录下无gradle,则在线下载 .. 2.输入./ ...
- React 安装
1.安装 node 8.0以上 node -v npm -v 2.安装淘宝镜像 cnpm npm install -g cnpm --registry=https://registry.npm.ta ...
- Activity四大启动模式
ctivity的四种启动模式: standard.singleTop.singleTask.singleInstance 为了打印方便,定义一个基础Activity,在其onCreate方法和onNe ...
- 【转】多线程:C#线程同步lock,Monitor,Mutex,同步事件和等待句柄(上)
本篇从Monitor,Mutex,ManualResetEvent,AutoResetEvent,WaitHandler的类关系图开始,希望通过 本篇的介绍能对常见的线程同步方法有一个整体的认识,而对 ...