题意:就是给了m个点,落在n+1个区域中,问各个区域有多少个点。

/*
对于每个玩具,二分其所在的区间,然后用叉积判断。
但是我觉得枚举好像时间复杂度也可以。
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#define N 5010
using namespace std;
int n,m,cnt[N];
struct Point{
int x,y;
};
struct Line{
Point a,b;
}line[N];
int crs(Point p1,Point p2,Point p0){
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
void search(Point p){
int l=,r=n;
while(l<r){
int mid=l+r>>;
if(crs(p,line[mid].a,line[mid].b)<) r=mid;
else l=mid+;
}
if(crs(p,line[l].a,line[l].b)<) cnt[l]++;
else cnt[l+]++;
}
int main(){
int x1,y1,x2,y2;
while(scanf("%d",&n)&&n){
memset(cnt,,sizeof(cnt));
scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2);
for(int i=;i<=n;i++){
int t1,t2;scanf("%d%d",&t1,&t2);
line[i].a.x=t1;
line[i].a.y=y1;
line[i].b.x=t2;
line[i].b.y=y2;
}
for(int i=;i<=m;i++){
Point p;
scanf("%d%d",&p.x,&p.y);
search(p);
}
for(int i=;i<=n+;i++)
printf("%d: %d\n",i-,cnt[i]);
printf("\n");
}
return ;
}

TOYS(poj 2318)的更多相关文章

  1. A - TOYS(POJ - 2318) 计算几何的一道基础题

    Calculate the number of toys that land in each bin of a partitioned toy box. 计算每一个玩具箱里面玩具的数量 Mom and ...

  2. (POJ 2318)TOYS 向量叉积

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

  3. 叉积(POJ - 2318 )

    题目链接:https://cn.vjudge.net/contest/276358#problem/A 题目大意:给你一个矩阵的左上角和右下角,然后n个竖杠,这n个竖杠将这个矩阵分成n+1个方块,给你 ...

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

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

  5. 01背包问题:Charm Bracelet (POJ 3624)(外加一个常数的优化)

    Charm Bracelet    POJ 3624 就是一道典型的01背包问题: #include<iostream> #include<stdio.h> #include& ...

  6. Scout YYF I(POJ 3744)

    Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5565   Accepted: 1553 Descr ...

  7. 广大暑假训练1(poj 2488) A Knight's Journey 解题报告

    题目链接:http://vjudge.net/contest/view.action?cid=51369#problem/A   (A - Children of the Candy Corn) ht ...

  8. Games:取石子游戏(POJ 1067)

    取石子游戏 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37662   Accepted: 12594 Descripti ...

  9. BFS 或 同余模定理(poj 1426)

    题目:Find The Multiple 题意:求给出的数的倍数,该倍数是只由 1与 0构成的10进制数. 思路:nonzero multiple  非零倍数  啊. 英语弱到爆炸,理解不了题意... ...

随机推荐

  1. Js学习文件上传

    // 文件上传 jQuery(function() { var $ = jQuery, $list = $('#thelist'), $btn = $('#ctlBtn'), state = 'pen ...

  2. python中 import 和from ... import 的区别

    先看一个例子: 我自定义的一个moudle,里面有一个方法sayhi,还有一个变量version#!/usr/bin/env python # coding=utf-8 # Filename: mym ...

  3. Delphi7中使用Indy9的IdSmtp发送email时subject过长会出现乱码的解决办法

    procedure TIdMessageClient.SendHeader(AMsg: TIdMessage); var LHeaders: TIdHeaderList; begin LHeaders ...

  4. Struts2 前端与后台之间传值问题

    老是被前端与后台之间的传值给弄糊涂了,特此写一篇blog进行总结. 一. 前端向后台传值 (1)属性驱动 属性驱动是指在Action类里,包含表单里对应的字段(字段名称一样),同时设置对应的gette ...

  5. 46 Simple Python Exercises-Higher order functions and list comprehensions

    26. Using the higher order function reduce(), write a function max_in_list() that takes a list of nu ...

  6. axios添加了header信息后发送的get请求自动编程option请求了

    axios添加了header信息后发送的get请求自动编程option请求了 webpack 代理转发 Provisional headers are shown 在Vue中如何使用axios跨域访问 ...

  7. 激活函数:Swish: a Self-Gated Activation Function

    今天看到google brain 关于激活函数在2017年提出了一个新的Swish 激活函数. 叫swish,地址:https://arxiv.org/abs/1710.05941v1 pytorch ...

  8. syntax error : missing ';' before identifier

    原文解决方案 #include "string.h" #include "stdafx.h" #include "Chapter 01 MyVersi ...

  9. QT_4_QpushButton的简单使用_对象树

    QpushButton的简单使用 1.1 按钮的创建 QPushButton *btn = new QPushButton; 1.2 btn -> setParent(this);设置父窗口 1 ...

  10. 去除ie下select框箭头

    select::-ms-expand { display: none;}兼容ie10及以上