跨产品的利用率推断点线段向左或向右,然后你可以2分钟

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int N = 5005; int n, m, x1, y1, x2, y2; struct Point {
int x, y;
Point() {}
Point(int x, int y) {
this->x = x;
this->y = y;
}
}; typedef Point Vector; Vector operator - (Vector A, Vector B) {
return Vector(A.x - B.x, A.y - B.y);
} struct Seg {
Point a, b;
Seg() {}
Seg(Point a, Point b) {
this->a = a;
this->b = b;
}
} seg[N]; int ans[N]; int Cross(Vector A, Vector B) {return A.x * B.y - A.y * B.x;} void gao(Point p) {
int l = 0, r = n;
while (l < r) {
int mid = (l + r) / 2;
if (Cross(seg[mid].a - p, seg[mid].b - p) < 0) r = mid;
else l = mid + 1;
}
ans[l]++;
} int main() {
while (~scanf("%d", &n) && n) {
memset(ans, 0, sizeof(ans));
scanf("%d%d%d%d%d", &m, &x1, &y1, &x2, &y2);
int x, y;
for (int i = 0; i < n; i++) {
scanf("%d%d", &x, &y);
seg[i] = Seg(Point(x, y1), Point(y, y2));
}
for (int i = 0; i < m; i++) {
scanf("%d%d", &x, &y);
gao(Point(x, y));
}
for (int i = 0; i <= n; i++)
printf("%d: %d\n", i, ans[i]);
printf("\n");
}
return 0;
}

POJ 2318 TOYS(计算几何)的更多相关文章

  1. poj 2318 TOYS(计算几何 点与线段的关系)

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12015   Accepted: 5792 Description ...

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

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

  3. poj 2318 TOYS (二分+叉积)

    http://poj.org/problem?id=2318 TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 101 ...

  4. 简单几何(点与线段的位置) POJ 2318 TOYS && POJ 2398 Toy Storage

    题目传送门 题意:POJ 2318 有一个长方形,用线段划分若干区域,给若干个点,问每个区域点的分布情况 分析:点和线段的位置判断可以用叉积判断.给的线段是排好序的,但是点是无序的,所以可以用二分优化 ...

  5. POJ 2318 TOYS && POJ 2398 Toy Storage(几何)

    2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而231 ...

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

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

  7. poj 2318 TOYS &amp; poj 2398 Toy Storage (叉积)

    链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段.而且这些线段坐标是依照顺序给出的. 有n条线段,把盒子分层了n+1个区域,然后有m个玩具.这m个玩具的坐标是已知的,问最后每一个区域 ...

  8. 【POJ】2318 TOYS ——计算几何+二分

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10281   Accepted: 4924 Description ...

  9. 2018.07.03 POJ 2318 TOYS(二分+简单计算几何)

    TOYS Time Limit: 2000MS Memory Limit: 65536K Description Calculate the number of toys that land in e ...

随机推荐

  1. UVa 11045 My T-shirt suits me / 二分图

    二分图建图 判断是否是完全匹配就行 最大流也行 #include <cstdio> #include <cstring> const int MAX = 300; int a[ ...

  2. 基于visual Studio2013解决C语言竞赛题之1023判断排序

         题目 解决代码及点评 /* 23. 有10个两位整数,把这些数作以下变化,如果它是素数, 则把它乘以2,若它是偶数则除以2,其余的数减1, 请将变化后的10个数按从小到大 ...

  3. 阿根廷探戈(Argentine Tango)舞步

    阿根廷探戈(Argentine Tango)舞步 阿根廷探戈(Argentine Tango)舞步 2011-11-22 13:05:11   不像其它大部分的社交舞,阿根廷探戈没有固定的舞步,它是一 ...

  4. gdb 远程qemu-arm调试

    把 c 编译成 arm 指令的可运行文件 /usr/bin/arm-linux-gnueabi-g++ hello.cpp cat hello.cpp #include <stdio.h> ...

  5. EasyUI - 后台管理系统 - 登陆模块

    效果: --- --- Html代码: <div id="login"> <p>账户:<input type="text" id= ...

  6. BaseActivity--上门啦

    package com.fwpt.activity; import com.fwpt.entity.RyUserInfo; import com.fwpt.entity.SmlaUserinfo; i ...

  7. js实现表格的选中一行-------Day58

    最開始想很多其它的用js来动态操作表格,是由于在应用了easyUI之后,发现直接写一个<table id="tt"></table>,这就够了,界面里面就剩 ...

  8. ANTLR4权威參考手冊(一)

    写在前面的话: 此文档是对伟大的Terence Parr的著作<the definitive antlr4 reference>的翻译本.致敬!欢迎转载,请注明原地址,请尊重劳动成果.翻译 ...

  9. static作用

    C程序一直由下列部分组成:      1)正文段——CPU运行的机器指令部分:一个程序仅仅有一个副本:仅仅读,防止程序因为意外事故而改动自身指令:      2)初始化数据段(数据段)——在程序中全部 ...

  10. Hbase初体验

    搭建local模式搭建, 官网:http://hbase.apache.org API:http://hbase.apache.org/apidocs/index.html download:http ...