poj 2318
来源:互联网 发布:js多个请求 编辑:程序博客网 时间:2024/05/16 06:53
由于期末考试好久没写题来 ( ps:都是借口, 没写题也没干别的,天天就看捧本小破书一看一上午,看一页睡半个小时, so 还是写题吧)
简单的计算机和入门
由于. 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.
所以我们可以确定所有的点都是在(x1,y1) ( x1,y1)(x2,y2)(x2,y1)四个点所构成的举行内部的, 而且没有点在直线上即所有的点都唯一的在一个容器内,所以这道题由点与四边形的关系变成点与直线的关系了,我们只需要判断点跟隔板的关系就好了,就是线段与点的位置关系,又因为所有的隔板都是按照顺序给的,所有可以用二分来找最合适的位置
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <cmath>
using namespace std;
#define MAXN 5555
struct Point
{
int x, y;
Point() {};
Point( int _x,int _y)
{
x = _x;
y = _y;
}
Point operator-(const Point &b) const
{
return Point(x - b.x, y - b.y);
}
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 - y*b.x;
}
};
struct Line
{
Point s, e;
Line() {};
Line(Point a, Point b)
{
s = a;
e = b;
}
} sta[MAXN];
int xmul( Point a, Point b, Point c)
{
return (b - a) ^ ( c - a);
}
int num[MAXN];
int main()
{
bool first = true;
int n, m, x1, y1, x2, y2;
while(scanf("%d",&n) != EOF && n)
{
scanf("%d %d %d %d %d", &m, &x1, &y1, &x2, &y2);
memset(num, 0, sizeof(num));
if(!first)
printf("\n");
int ui, li;
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));
int x, y;
Point toy;
for( int i = 0; i < m; i++)
{
scanf("%d %d",&toy.x, &toy.y);
int l = 0;
int r = n+1;
int tmp;
while( l <= r)
{
int mid = ( l + r) >> 1;
if(xmul(sta[mid].s, sta[mid].e, toy) < 0)
{
tmp = mid;
r = mid - 1;
}
else l = mid + 1;
}
num[tmp]++;
}
for( int i = 0; i <= n; i++)
printf("%d: %d\n",i,num[i]);
first = false;
}
}
- poj 2318 poj 2398
- poj 2318
- POJ 2318
- poj 2318
- POJ 2318
- poj 2318
- poj.2318
- poj 2318
- poj 2318
- POJ-2318
- poj 2318
- POJ 2318
- POJ 2318 几何 POJ 2398
- POJ 2318 TOYS && POJ 2398 Toy Storage
- 【计算几何】POJ 2318 & POJ 2398
- POJ 2318 TOYS || POJ 2398 Toy Storage
- POJ 2318 TOYS
- poj 2318 TOYS
- WEKA——数据准备
- 知识管理
- 多视点的数据表示
- Discuz!X3.2学习笔记(一)
- 新手入门使用git 简单使用 终端命令
- poj 2318
- moodle基本配置
- 动态链接时如何访问在其他模块中的全局变量
- 微信开发不用xstream来将对象解析成xml
- SSL/TLS 协议详解
- 更新了VMWare Tools后还是不能开启3D加速
- 素数判定方法 转自:http://dongxicheng.org/structure/prime/
- 第十八周OJ之统计成绩
- WEKA——关联规则(购物篮分析)