题意:

有一个长方形,里面从左到右有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. jQuery 点击按钮刷新页面

    //页面加载时绑定按钮点击事件 $(function () { $("#按钮id").click(function () { refresh(); }); }); //点击按钮调用 ...

  2. 【BZOJ 1088】 [SCOI2005]扫雷Mine

    Description 相信大家都玩过扫雷的游戏.那是在一个n*m的矩阵里面有一些雷,要你根据一些信息找出雷来.万圣节到了,“余”人国流行起了一种简单的扫雷游戏,这个游戏规则和扫雷一样,如果某个格子没 ...

  3. 微软职位内部推荐-This Job is no longer available.

    微软近期Open的职位: 如果你想试试这个职位,请跟我联系,我是微软的员工,可以做内部推荐.发你的中英文简历到我的邮箱:Nicholas.lu.mail(at)gmail.com

  4. python学习笔记2(变量)

    变量是只不过保留的内存位置用来存储值,这意味着,当创建一个变量,那么它在内存中保留一些空间. Python是弱类型,无需明确指定变量类型,赋值的同时会自动声明类型. x = 1 y = 2.0 nam ...

  5. git/ TortoiseGit 在bitbucket.org 使用证书登陆

    背景:使用https协议在bitbucket中进行pull,push 时每次都要输入密码,比较麻烦还耽误时间,在网上找了下保存密码的方式 使用在用户环境变量中配置_netrc 文件的方式(http:/ ...

  6. c#无标题窗体点击任务栏图标正常最小化或还原

    FormBorderStyle等于System.Windows.Forms.FormBorderStyle.None的窗体,点击任务栏图标的时候,是不能象标准窗体那样最小化或还原的. protecte ...

  7. [转]深度理解依赖注入(Dependence Injection)

    http://www.cnblogs.com/xingyukun/archive/2007/10/20/931331.html 前面的话:提到依赖注入,大家都会想到老马那篇经典的文章.其实,本文就是相 ...

  8. spring mvc中的@PathVariable(转)

    鸣谢:http://jackyrong.iteye.com/blog/2059307 ------------------------------------------------ spring m ...

  9. Spring.net Could not load type from string value问题解决办法

    Spring.net Could not load type from string value "xxx" 错误原因可能有: 1.spring.net配置错误,注意要区别配置文件 ...

  10. -webkit-text-size-adjust: none;该如何处理

    -webkit-text-size-adjust: none; 在中文版Chrome里面,网页CSS里所有小于12px的字体设置都无效,最终将显示12px.这样弄的本意可能 是好的,因为中文一旦小于1 ...