题意:

有一个长方形,里面从左到右有n条线段,将矩形分成n+1个格子,编号从左到右为0~n。

端点分别在矩形的上下两条边上,这n条线段互不相交。

现在已知m个点,统计每个格子中点的个数。

分析:

用叉积判断点与线段的相对位置,对于每个点二分查找所在的格子。

 #include <cstdio>
#include <cmath>
#include <cstring> struct Point
{
int x, y;
Point(int x=, int y=):x(x), y(y) {}
};
typedef Point Vector; Point read_point()
{
int x, y;
scanf("%d%d", &x, &y);
return Point(x, y);
} Point operator + (const Point& A, const Point& B)
{ return Point(A.x+B.x, A.y+B.y); } Point operator - (const Point& A, const Point& B)
{ return Point(A.x-B.x, A.y-B.y); } int Cross(const Point& A, const Point& B)
{ return A.x*B.y - A.y*B.x; } const int maxn = + ;
int up[maxn], down[maxn], ans[maxn];
int n, m, kase = ;
Point A0, B0; int binary_search(const Point& P)
{
int L = , R = n;
while(L < R)
{
int mid = L + (R - L + ) / ;
Point A(down[mid], B0.y), B(up[mid], A0.y);
Vector v1 = B - A;
Vector v2 = P - A;
if(Cross(v1, v2) < ) L = mid;
else R = mid - ;
}
return L;
} int main()
{
//freopen("in.txt", "r", stdin); while(scanf("%d", &n) == && n)
{
memset(ans, , sizeof(ans)); scanf("%d", &m); A0 = read_point(); B0 = read_point();
for(int i = ; i <= n; ++i) scanf("%d%d", &up[i], &down[i]);
for(int i = ; i < m; ++i)
{
Point P; P = read_point();
int pos = binary_search(P);
ans[pos]++;
} if(kase++) puts("");
for(int i = ; i <= n; ++i) printf("%d: %d\n", i, ans[i]);
} return ;
}

代码君

POJ 2318 (叉积) TOYS的更多相关文章

  1. poj 2318 叉积+二分

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13262   Accepted: 6412 Description ...

  2. (POJ 2318)TOYS 向量叉积

    题目链接:http://poj.org/problem?id=2318 #include<stdio.h> #include<cstdlib> #include<cstr ...

  3. 【POJ 2318】TOYS 叉积

    用叉积判断左右 快速读入写错了卡了3小时hhh #include<cmath> #include<cstdio> #include<cstring> #includ ...

  4. poj 2318(叉积判断点在线段的哪一侧)

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13120   Accepted: 6334 Description ...

  5. POJ 2318 叉积判断点与直线位置

    TOYS   Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom ...

  6. 「POJ - 2318」TOYS (叉乘)

    BUPT 2017 summer training (16) #2 A 题意 有一个玩具盒,被n个隔板分开成左到u右n+1个区域,然后给每个玩具的坐标,求每个区域有几个玩具. 题解 依次用叉积判断玩具 ...

  7. POJ 2318/2398 叉积性质

    2318 2398 题意:给出n条线将一块区域分成n+1块空间,再给出m个点,询问这些点在哪个空间里. 思路:由于只要求相对位置关系,而对具体位置不关心,那么易使用叉积性质得到相对位置关系(左侧/右侧 ...

  8. POJ 2318 TOYS(叉积+二分)

    题目传送门:POJ 2318 TOYS Description Calculate the number of toys that land in each bin of a partitioned ...

  9. 向量的叉积 POJ 2318 TOYS & POJ 2398 Toy Storage

    POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由ab ...

随机推荐

  1. Linux各发行版本 优缺点 简介

    2008.01.21 13:43 Linux最早由Linus Benedict Torvalds在1991年开始编写.在这之前,RichardStallman创建了Free SoftwareFound ...

  2. Demo学习: ClientInfo

    ClientInfo 获取客户端环境参数,从0.9版本开始新增了TUniClientInfoRec对象,可以得到客户端的一些信息,之前为了获取浏览器版本号需要自己写函数,现在可以直接使用TUniCli ...

  3. Microsoft Visual Studio Ultimate 2013 旗舰版 有效注册密钥

    Visual Studio Ultimate 2013 KEY(密钥):BWG7X-J98B3-W34RT-33B3R-JVYW9 Visual Studio Premium 2013 KEY(密钥) ...

  4. 转 在无法通过yum下载非标准包时,怎么办

    在CentOS下,我们可以通过yum来下载或更新rpm包,但是标准的源(repository)里只提供一部分的rpm包,虽然大部分情况下,这些包是够用的.但是有时候还是需要下载其他的一些非标准的包,如 ...

  5. CodeBlocks去掉拼写检查

    打开: 选择Compiler... 将红框里面的勾都点掉即可!

  6. Android中获取应用程序(包)的大小-----PackageManager的使用(二)

    通过第一部分<<Android中获取应用程序(包)的信息-----PackageManager的使用(一)>>的介绍,对PackageManager以及 AndroidMani ...

  7. UIImagePickerController拍照与摄像(转)

    转载自:http://blog.sina.com.cn/s/blog_68edaff101019ppe.html (2012-11-23 14:38:40) 标签: ios iphone 拍照 摄像 ...

  8. 机器学习基石的泛化理论及VC维部分整理

    第四讲 机器学习的可行性 一.Hoeffding's Inequality \(P[\left | \nu -\mu  \right |>\epsilon ] \leq 2exp(-2\epsi ...

  9. poj 1094 Sorting It All Out (拓扑排序)

    http://poj.org/problem?id=1094 Sorting It All Out Time Limit: 1000MS   Memory Limit: 10000K Total Su ...

  10. oracle 导出数据和导入数据

    导出数据 exp zl_gj/zlkj@gqxt  grants=y tables=(zl_gj.ckgj,zl_gj.gjlx,zl_gj.rkgj) file=c:\gj.dmp log=c:\g ...