poj 2398 Toy Storage
来源:互联网 发布:淘宝靠谱化妆品代购店 编辑:程序博客网 时间:2024/06/06 01:27
跟2318 差不多
#include <iostream>
#include <cstdio>#include <cstring>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
#define MAXN 1111
struct Point
{
int x, y;
Point(){};
Point(int a, int b)
{
x = a;
y = b;
}
Point operator- (const Point &b) const
{
return Point(x - b.x, y - b.y);
}
int operator* (const Point &b) const
{
return x*b.x + y*b.y;
}
int operator^ (const Point &b) const
{
return x*b.y - b.x * y;
}
};
struct Line
{
Point s,e;
Line(){};
Line(Point a, Point b)
{
s = a;
e = b;
}
};
int cmp( Line a, Line b)
{
if(a.s.x != b.s.x)
return a.s.x < b.s.x;
return a.e.x < b.e.x;
}
Line sta[MAXN];
int num[MAXN];
map<int, int > ans;
int xmul( Point a, Point b, Point c)
{
return (b - a) ^ (c - a);
}
int main()
{
int n, m, x1, y1, x2, y2;
while(scanf("%d",&n) != EOF && n)
{
memset(num, 0, sizeof(num));
scanf("%d %d %d %d %d",&m ,&x1, &y1, &x2, &y2);
int ui, li;
ans.clear();
for( int i = 0; i < n; i++)
{
scanf("%d %d",&ui, &li);
sta[i] = Line(Point(ui,y1), Point(li,y2));
}
sta[n] = Line(Point(x2,y1), Point(x2,y2));
sort(sta, sta + n + 1, cmp);
// for( int i = 0; i <= n; i++)
// printf("%d %d ---> %d %d\n",sta[i].s.x, sta[i].s.y ,sta[i].e.x, sta[i].e.y);
int x, y;
int temp;
Point toy;
for( int i = 0; i < m; i++)
{
scanf("%d %d",&toy.x, &toy.y);
if(toy.x > x2 || toy.x < x1 || toy.y < y2 || toy.y > y1)
continue;
int l = 0, r = n;
while( l <= r)
{
int mid = (l + r) >> 1;
if(xmul(sta[mid].s, sta[mid].e,toy) < 0)
{
temp = mid;
r = mid - 1;
}
else
l = mid + 1;
}
//cout<<"temp-------->"<<temp<<endl;
num[temp] ++;
}
for( int i = 0; i <= n; i++)
if(num[i])
ans[num[i]]++;
map<int, int> :: iterator it = ans.begin();
printf("Box\n");
while(it != ans.end())
{
printf("%d: %d\n",it->first, it->second);
it++;
}
}
}
0 0
- poj 2398 Toy Storage
- poj 2398 Toy Storage
- POJ 2398 Toy Storage
- POJ 2398 Toy Storage
- poj 2398 toy storage
- poj 2398 Toy Storage
- POJ 2398 Toy Storage
- poj 2398Toy Storage
- POJ 2398 Toy Storage
- poj 2398 Toy Storage
- poj 2398 Toy Storage
- poj 2398 Toy Storage
- Poj-2398-Toy Storage
- poj 2398 Toy Storage
- poj 2398 Toy Storage
- poj 2398 Toy Storage
- Toy Storage(poj 2398)
- POJ 2398 Toy Storage
- Linux 的开机启动流程详解
- 使用Titanium模块
- Linux环境下安装Nginx+Pcre+zlib+OpenSSL
- XSS信息刺探脚本
- 随机生成8位字符串
- poj 2398 Toy Storage
- 2-2-3 嵌套和级联的判断-分段函数-级联
- Python可视化编程
- 指针第一次练习
- C# Handler 下载文件
- 网站推广是系统工程 转载
- Struts2技术内幕 读书笔记二 web开发的基本模式
- GSM语音编码
- 使用纯 CSS3 动画实现地球转动