poj 2318 TOYS 2012-01-11

http://poj.org/problem?id=2318

___________________________________________________

题目大意:一个箱子用木板分成几个区间,给一些玩具的坐标,求各个区间有几个玩具。

对于每一个玩具,因为输入的区间是有序的,所以采用二分木板,判断一个玩具在哪个区间。

___________________________________________________

 1 Program Stone;
 2 var i,n,m,x1,x2,y1,y2,xi,yi:longint;
 3     ui,li:array[0..10000]of longint;
 4     ans:array[0..10000]of longint;
 5  procedure init;
 6  var i,j,k:longint;
 7   begin
 8      readln(n,m,x1,y1,x2,y2);
 9      ui[0]:=x1;li[0]:=x1;
10      ui[n+1]:=x2;li[n+1]:=x2;
11      if n=0 then halt;
12      for i:=1 to n do readln(ui[i],li[i]);
13   end;
14  Function cross(x1,y1,x2,y2,x3,y3,x4,y4:longint):longint;    //叉积
15   begin
16     cross:=(x2-x1)*(y4-y3)-(y2-y1)*(x4-x3);
17   end;
18  function ef(x,y:longint):longint;
19  var i,j,k,left,right,mid:longint;
20   begin
21      left:=0;right:=n+1;
22      while left+1<right do
23       begin
24          mid:=(left+right)div 2;
25          k:=cross(li[mid],y2,ui[mid],y1,li[mid],y2,x,y);
26          if k<0 then left:=mid;
27          if k>0 then right:=mid;
28       end;
29      ef:=left;
30   end;
31  Procedure print;
32  var i:longint;
33   begin
34     for i:=0 to n do
35      writeln(i,‘: ‘,ans[i]);
36     writeln;
37     fillchar(ans,sizeof(ans),0);
38   end;
39 Begin
40  assign(input,‘input.in‘);reset(input);
41    while true do
42     begin
43        init;
44        for i:=1 to m do
45         begin
46           readln(xi,yi);
47           inc(ans[ef(xi,yi)]);
48         end;
49        print;
50     end;
51 end.
52
53  
时间: 2024-10-05 14:54:40

poj 2318 TOYS 2012-01-11的相关文章

POJ 2318 TOYS(叉积+二分or暴力)

题目链接:POJ 2318 TOYS [写在前面]前几天跟队友分了方向,学渣开始进行计算几何的专题了,真是脑壳有点痛啊.但是我想做多了就没这么坑爹了 [题意]大体意思就是给你一个矩形,有被若干直线分成N个格子,给出M个点的坐标,问你每个点位于哪个格子中. [思路]其实就是点在凸四边形内的判断,然后就可以利用叉积的性质,当然可以用暴力枚举也可以过,但是时间复杂度有点高,最好是用二分求解.(一直觉得二分真是牛逼啊) 下面贴AC代码,用二分219MS就过了: 1 /* 2 ** POJ 2318 TO

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

链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段,并且这些线段坐标是按照顺序给出的, 有n条线段,把盒子分层了n+1个区域,然后有m个玩具,这m个玩具的坐标是已知的,问最后每个区域有多少个玩具 分析:从左往右,直到判断玩具是否在线段的逆时针方向为止,这个就需要用到叉积,当然可以用二分查找优化. 叉积:已知向量a(x1,y1),向量b(x2,y2),axb=x1*y2-x2*y1, 若axb>0,a在b的逆时针方向,若axb<0,则a在b的顺时针方向 注:每组数据后要多空一行

POJ 2318 TOYS 叉积的应用

A - TOYS Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2318 Appoint description:  lijunle  (2011-07-18)System Crawler  (2016-05-08) Description Calculate the number of toys that land in each b

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

TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12015   Accepted: 5792 Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a problem - their child John never puts his toys away w

POJ 2318 TOYS 叉积

题意: 给出一个矩形范围,给出n条线段,这n条线段一定与矩形上下边界相交且互不相交,将矩形分成n+1个划分.给出m个玩具的坐标.求每个划分放的玩具数,玩具保证不会在线段和左右边界上. 分析: 判断点是否在两条直线中间,利用叉积,如果在两条直线间,必定会有两个叉积一个小于0,一个大于0(不能把相乘小于0作为判断条件) #include <iostream> #include <cstdio> #include <cstring> using namespace std;

POJ 2318 TOYS 叉积应用

点击打开链接 TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11078   Accepted: 5312 Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a problem - their child John never puts his toys

poj 2318 TOYS (点与线段位置关系判断)

TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10848   Accepted: 5206 Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a problem - their child John never puts his toys away w

poj 2318 TOYS(判点与线段的关系)

TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11643   Accepted: 5616 Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a problem - their child John never puts his toys away w

poj 2318 TOYS(计算几何)

TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13159   Accepted: 6357 Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a problem - their child John never puts his toys away w