【POJ - 2398】Toy Storage (计算几何,二分找位置,叉积,点和直线的位置关系)

题干:

 

Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing with them. They gave Reza a rectangular box to put his toys in. Unfortunately, Reza is rebellious and obeys his parents by simply throwing his toys into the box. All the toys get mixed up, and it is impossible for Reza to find his favorite toys anymore. 
Reza's parents came up with the following idea. They put cardboard partitions into the box. Even if Reza keeps throwing his toys into the box, at least toys that get thrown into different partitions stay separate. The box looks like this from the top: 


We want for each positive integer t, such that there exists a partition with t toys, determine how many partitions have t, toys.

Input

The input consists of a number of cases. The first line consists of six integers n, m, x1, y1, x2, y2. The number of cardboards to form the partitions is n (0 < n <= 1000) and the number of toys is given in m (0 < m <= 1000). The coordinates of the upper-left corner and the lower-right corner of the box are (x1, y1) and (x2, y2), respectively. The following n lines each consists of two integers Ui Li, indicating that the ends of the ith cardboard is at the coordinates (Ui, y1) and (Li, y2). You may assume that the cardboards do not intersect with each other. The next m lines each consists of two integers Xi Yi specifying where the ith toy has landed in the box. You may assume that no toy will land on a cardboard. 

A line consisting of a single 0 terminates the input.

Output

For each box, first provide a header stating "Box" on a line of its own. After that, there will be one line of output per count (t > 0) of toys in a partition. The value t will be followed by a colon and a space, followed the number of partitions containing t toys. Output will be sorted in ascending order of t for each box.

Sample Input

4 10 0 10 100 0
20 20
80 80
60 60
40 40
5 10
15 10
95 10
25 10
65 10
75 10
35 10
45 10
55 10
85 10
5 6 0 10 60 0
4 3
15 30
3 1
6 8
10 10
2 1
2 8
1 5
5 5
40 10
7 9
0

Sample Output

Box
2: 5
Box
1: 4
2: 1

解题报告:

跟这题一样【POJ - 2318】TOYS,只是输出的格式不一样 。那个题是要输出第i个盒子中有多少玩具,这个是要输出共装有i个玩具的盒子有多少个。

AC代码:

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int n,m,x1,x2,y1,y2;//n个板子,m个玩具,左上角,右下角。 
int num[2005];
struct Edge {int x1,y1;//上 int x2,y2;//下 
} e[5005];
struct Node {int x,y;
} node[5005];
int ans[5005];
int cal(int tar,int line) {return (node[tar].x - e[line].x2)*(e[line].y1-e[line].y2) - (e[line].x1 - e[line].x2)*(node[tar].y - e[line].y2);
} 
bool cmp(Edge a,Edge b) {return a.x1 < b.x1;
}
int main()
{while(cin>>n) {memset(num,0,sizeof num);if(n == 0) break;cin>>m>>x1>>y1>>x2>>y2;memset(ans,0,sizeof ans);for(int i = 1; i<=n; i++) {scanf("%d%d",&e[i].x1,&e[i].x2);e[i].y1 = y1;e[i].y2 = y2;}sort(e+1,e+n+1,cmp);for(int i = 1; i<=m; i++) {scanf("%d%d",&node[i].x,&node[i].y);}//process each for(int i = 1; i<=m; i++) {int l = 1,r = n;int mid = (l+r)/2;while(l<r) {mid = (l+r)/2;if(cal(i,mid) > 0) l=mid+1;else r=mid; }if(l == n) {if(cal(i,l) < 0) ans[l]++;else ans[l+1]++;				}else ans[l]++;}for(int i = 1; i<=n+1; i++) {num[ans[i]]++;}puts("Box");for(int i = 1; i<=m; i++) {if(num[i]!=0) printf("%d: %d\n",i,num[i]);}}return 0 ;}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441387.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【POJ - 1269 】Intersecting Lines (计算几何,直线间的位置关系)

题干&#xff1a; We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection because they are parallel, 2) intersect in a line because they are on top of …

java servlet 转发和重定向_JavaWeb(一)Servlet中乱码解决与转发和重定向的区别

前言前面其实已经把Servlet中所有的内容都介绍完了&#xff0c;这篇讲补充一点乱码和重定向与转发之间的区别&#xff01;一、request请求参数出现乱码问题1.1、get请求1)乱码示例get请求的参数是在url后面提交过来的&#xff0c;也就是在请求行中。结果&#xff1a;Servlet_de…

【POJ - 3304 】Segments(计算几何,思想转化,直线和线段相交)

题干&#xff1a; Given n segments in the two dimensional space, write a program, which determines if there exists a line such that after projecting these segments on it, all projected segments have at least one point in common. Input Input begins with a…

java调用lingo_使用Lingo增强JMS

虽然activemqjencks的jms轻量级解决方案已经很好地在psa中work了&#xff0c;尤其spring的JmsTemplate使得代码更简单&#xff0c;但是还是存在问题。问题来自暑期做psa的时候&#xff0c;linke突然提出要求&#xff0c;需要MDP返回些处理信息&#xff0c;比如处理结果、异常&a…

jsk Star War (线段树维护区间最小最大值 + 二分)

Description 公元20XX年&#xff0c;人类与外星人之间的大战终于爆发。 现有一个人类军团&#xff0c;由n名士兵组成&#xff0c;第i个士兵的战斗力值对应一个非负整数ai (1 \leq i \leq n1≤i≤n)。 有一天&#xff0c;某个战力爆表的外星人NaN单独向地球人宣战&#xff0c…

java jsp导出pdf文件_JSP页面导出PDF格式文件

JSP页面导出PDF格式文件基本在前端页面可以全部完成添加下载链接的点击事件var downPdf document.getElementById("downLoad");downPdf.onclick function() {downPdf.parentNode.removeChild(downPdf);html2canvas(document.body, {onrendered:function(canvas) {v…

【51Nod - 1094】和为k的连续区间 (前缀和,二分查找)

题干&#xff1a; 一整数数列a1, a2, ... , an&#xff08;有正有负&#xff09;&#xff0c;以及另一个整数k&#xff0c;求一个区间i,ji,j&#xff0c;(1 < i < j < n)&#xff0c;使得aii ... ajj k。 Input 第1行&#xff1a;2个数N,K。N为数列的长度。K为需…

简述java的线程_Java多线程的简述

线程与进程进程&#xff1a;​ 是指一个内存中运行的应用程序&#xff0c;每个进程都有一个独立的内存空间&#xff0c;一个应用程序可以同时运行多个进程&#xff1b;进程也是程序的一次执行过程&#xff0c;是系统运行程序的基本单位&#xff1b;系统运行一个程序即是一个进程…

【POJ - 3253】Fence Repair(贪心,时光倒流)

题干&#xff1a; Description Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each having some integer length Li (1 ≤ Li ≤ 50,000) units. He t…

java unsafe park_Java中Unsafe类详解

http://www.cnblogs.com/mickole/articles/3757278.htmlJava不能直接访问操作系统底层&#xff0c;而是通过本地方法来访问。Unsafe类提供了硬件级别的原子操作&#xff0c;主要提供了以下功能&#xff1a;1、通过Unsafe类可以分配内存&#xff0c;可以释放内存&#xff1b;类中…

【CodeForces - 124D】Squares (旋转坐标系,计算几何,思维)

题干&#xff1a; You are given an infinite checkered field. You should get from a square (x1; y1) to a square (x2; y2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any…

java图形设计_java图形界面设计含答案

十一章 图形用户界面程序设计入门一&#xff0e;选择题&#xff1a;1. 容器Panel和applet缺省使用的布局编辑策略是 BA、BorderLayout B、FlowLayoutC、GridLayout D、CarLayout2. .applet类的直接父类是&#xff1a; BA、Component类 B、Container类C、Frame类 D、Panel类3. .…

【qduoj - 夏季学期创新题】骑士游历(递推dp)

题干&#xff1a; 描述 输入 输入包含多组数据&#xff0c;第一行T表示数据组数接下来每行六个整数n&#xff0c;m&#xff0c;x1&#xff0c;y1&#xff0c;x2&#xff0c;y2(分别表示n&#xff0c;m&#xff0c;起点坐标&#xff0c;终点坐标) 输出 输出T行&#xff0c;表示…

java ee 6 源码_Java EE 6开发手册·高级篇(第4版)

资源名称&#xff1a;Java EE 6开发手册高级篇(第4版)内容简介&#xff1a;《Java EE 6 开发手册?高级篇(第4 版)》是一本面向实战、以示例为驱动、在Java 平台企业版6(Java EE 6)上开发企业级应用的指南。该指南基于The Java EE 6 Tutorial: Basic Concepts&#xff0c;Fourt…

【qduoj - 夏季学期创新题】矩形剖分(递归,dp)

题干&#xff1a; 描述 对一个给定的矩形&#xff0c;将其划分成尽可能少的正方形&#xff0c;输出正方形的最少个数。例如&#xff0c;如下图所示的情况&#xff0c;则输入为3和4&#xff0c;输出为4。 输入 输入两个整数中间用空格分开。 输出 输出最少分割成的正方形的个…

java8 nio_Java8之 NIO的学习

一、什么是NIO&#xff1f;Java NIO(New IO)是从Java 1.4版本开始引入的一个新的IO API&#xff0c;可以替代标准的Java IO API。NIO与原来的IO有同样的作用和目的&#xff0c;但是使用的方式完全不同&#xff0c;NIO支持面向缓冲区的、基于通道的IO操作。NIO将以更加高效的方式…

【牛客 - 125A】灰魔法师(打表,暴力)

题干&#xff1a; 给出长度为n的序列a, 求有多少对数对 (i, j) (1 < i < j < n) 满足 ai aj 为完全平方数。 输入描述: 第一行一个整数 n (1 < n < 105) 第二行 n 个整数 ai (1 < ai < 105) 输出描述: 输出一个整数&#xff0c;表示满足上述条件的数…

学分绩点计算编程java_方便我们计算学分绩点的JavaScript

基于目前我们学校教务处的管理系统, 依靠Javascript的帮忙, 我们可以很方便地计算成绩.测试用HTML:style"width: 100%; border-collapse: collapse;">课程代码课程名称课程性质成绩补考成绩重修成绩学分绩点辅修标记24109505数据库系统实验专业基础课优秀0.54.502…

【POJ - 2663】Tri Tiling (简单dp)

题干&#xff1a; In how many ways can you tile a 3xn rectangle with 2x1 dominoes? Here is a sample tiling of a 3x12 rectangle. Input Input consists of several test cases followed by a line containing -1. Each test case is a line containing an integer …

java 反射 代码_java反射机制学习代码

根据http://www.iteye.com/topic/137944文档进行学习代码如下:package reflectTest;import java.lang.reflect.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.*;class A{}class B extends A{}class C extends B{}class TestClass …