嘟嘟嘟




题面:先告诉你一个矩形抽屉的坐标,然后\(n\)个隔板将抽屉分成了\(n + 1\)格(格子从\(0\)到\(n - 1\)标号),接下来随机输入\(m\)个玩具的坐标。问最后每一个格子里有多少个玩具。




仔细想想就是一道计算几何入门题。

对于一个玩具\((x_0, y_0)\),我们只要找到在他的左面且离他最近的隔板\(i\),则这个玩具就在第\(i\)格里。

怎么判断隔板\(AB\)(规定\(A\)点是隔板的上端,\(B\)点是隔板下端)是否在玩具的左边?用叉积即可:只要\(\overrightarrow{OA} \times \overrightarrow{OB} > 0\),就说明在左边。

然后因为有人说从左到右枚举会超时,所以我就把枚举改成倍增了。

然鹅枚举\(O(n ^2)\)能过呀,于是我就枚举交了一发,也过了……(???)

代码里注释掉的是枚举的

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 5e3 + 5;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) {last = ch; ch = getchar();}
while(isdigit(ch)) {ans = (ans << 1) + (ans << 3) + ch - '0'; ch = getchar();}
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
} int n, m, xl, yl, xr, yr;
int ans[maxn]; struct Vec
{
int x, y;
int operator * (const Vec& oth)const
{
return x * oth.y - oth.x * y;
}
};
struct Point
{
int x, y;
Vec operator - (const Point& oth)const
{
return (Vec){x - oth.x, y - oth.y};
}
}ad[maxn], au[maxn], P; const int N = 13;
void solve()
{
int L = 0;
for(int i = N, t; i >= 0; --i) if((t = L + (1 << i)) <= n)
{
if((au[t] - P) * (ad[t] - P) > 0) L = t;
}
/*int L = 0;
while(L < n)
{
if((au[L + 1] - P) * (ad[L + 1] - P) < 0) break;
L++;
}*/
ans[L]++;
} int main()
{
while(scanf("%d", &n) && n)
{
Mem(ans, 0);
m = read();
xl = read(); yl = read(); xr = read(); yr = read();
au[0].y = yl;
for(int i = 1; i <= n; ++i)
{
au[i].x = read(); au[i].y = yl;
ad[i].x = read(); ad[i].y = yr;
}
for(int i = 1; i <= m; ++i)
{
P.x = read(); P.y = read();
solve();
}
for(int i = 0; i <= n; ++i) write(i), putchar(':'), space, write(ans[i]), enter;
enter;
}
return 0;
}

POJ2318 TOYS的更多相关文章

  1. POJ2318 TOYS[叉积 二分]

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14433   Accepted: 6998 Description ...

  2. POJ2318 TOYS(叉积判断点与直线的关系+二分)

    Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a prob ...

  3. POJ-2318 TOYS,暴力+叉积判断!

                                                                 TOYS 2页的提交记录终于搞明白了. 题意:一个盒子由n块挡板分成n+1块区 ...

  4. POJ-2318 TOYS 计算几何 判断点在线段的位置

    题目链接:https://cn.vjudge.net/problem/POJ-2318 题意 在一个矩形内,给出n-1条线段,把矩形分成n快四边形 问某些点在那个四边形内 思路 二分+判断点与位置关系 ...

  5. [poj2318]TOYS(直线与点的位置关系)

    解题关键:计算几何入门题,通过叉积判断. 两个向量的关系: P*Q>0,Q在P的逆时针方向: P*Q<0,Q在P的顺时针方向: P*Q==0,Q与P共线. 实际就是用右手定则判断的. #i ...

  6. POJ2318:TOYS(叉积判断点和线段的关系+二分)&&POJ2398Toy Storage

    题目:http://poj.org/problem?id=2318 题意: 给定一个如上的长方形箱子,中间有n条线段,将其分为n+1个区域,给定m个玩具的坐标,统计每个区域中的玩具个数.(其中这些线段 ...

  7. 【kuangbin专题】计算几何基础

    1.poj2318 TOYS 传送:http://poj.org/problem?id=2318 题意:有m个点落在n+1个区域内.问落在每个区域的个数. 分析:二分查找落在哪个区域内.叉积判断点与线 ...

  8. poj分类解题报告索引

    图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...

  9. POJ2318:TOYS——题解

    http://poj.org/problem?id=2318 题目大意:给一个大矩形,分成n+1份,求落在每一份的点的数量. —————————————————— 首先叉积可以判断一个点在边界的左边还 ...

随机推荐

  1. [转]如何选择Html.RenderPartial和Html.RenderAction

    Html.RenderPartial与Html.RenderAction这两个方法都是用来在界面上嵌入用户控件的. Html.RenderPartial是直接将用户控件嵌入到界面上: <%Htm ...

  2. 一、Java多线程基础

    一.简介 1.操作系统 在早起的裸机时代,计算机非常地昂贵,而且也没有操作系统的概念,计算机从头到尾只能执行一个程序.如果程序在执行一个耗时的操作,那么在这个过程中,计算机就有大量的资源闲置在那里,这 ...

  3. 第一个Windows窗口应用程序

    学习目的 熟悉开发工具Visual C++ 6.0和MSDN 2001的使用. 应用Windows API函数, 手工编写具有最基本构成的Windows窗口应用程序(包含WinMain入口函数, 消息 ...

  4. HDU 4747(AC不能)

    http://acm.hdu.edu.cn/showproblem.php?pid=4747

  5. 理解域名插槽:slot-scope

    作用域插槽 | 带数据的插槽 最后,就是我们的作用域插槽.这个稍微难理解一点.官方叫它作用域插槽,实际上,对比前面两种插槽,我们可以叫它带数据的插槽.什么意思呢,就是前面两种,都是在组件的templa ...

  6. 51nod1538:一道难题(常系数线性递推/Cayley-Hamilton定理)

    传送门 Sol 考虑要求的东西的组合意义,问题转化为: 有 \(n\) 种小球,每种的大小为 \(a_i\),求选出大小总和为 \(m\) 的小球排成一排的排列数 有递推 \(f_i=\sum_{j= ...

  7. java截取字符串

    public class Temp { public static void main(String[] args) { String a="dsadgafa34"; System ...

  8. apm飞控飞行模式详解

    1.稳定模式Stabilize稳定模式是使用得最多的飞行模式,也是最基本的飞行模式,起飞和降落都应该使用此模式.此模式下,飞控会让飞行器保持稳定,是初学者进行一般飞行的首选,也是FPV第一视角飞行的最 ...

  9. Activity 四种launchMode

    launchMode在多个Activity跳转的过程中扮演着重要的角色,它可以决定是否生成新的Activity实例,是否重用已存在的 Activity实例,是否和其他Activity实例公用一个tas ...

  10. 【转】OmniGraffle (一)从工具栏开始

    原文链接:http://www.jianshu.com/p/52f3ecbe8f2d OmniGraffle的软件布局和大多数图形类软件类似,中间是编辑区,左边是页面和对象组织的管理,右边是参数设置和 ...