N - TOYS解题报告(来自网络)

西南交通大学算法设计与分析第一次作业 算法设计与分析第一次作业 阅读详情

N - TOYS
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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 when he is finished playing with them. They gave John a rectangular box to put his toys in, but John 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 John to find his favorite toys. 

John's parents came up with the following idea. They put cardboard partitions into the box. Even if John keeps throwing his toys into the box, at least toys that get thrown into different bins stay separated. The following diagram shows a top view of an example toy box. 
 
For this problem, you are asked to determine how many toys fall into each partition as John throws them into the toy box.

Input

The input file contains one or more problems. The first line of a problem consists of six integers, n m x1 y1 x2 y2. The number of cardboard partitions is n (0 < n <= 5000) and the number of toys is m (0 < m <= 5000). 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 contain two integers per line, Ui Li, indicating that the ends of the i-th cardboard partition is at the coordinates (Ui,y1) and (Li,y2). You may assume that the cardboard partitions do not intersect each other and that they are specified in sorted order from left to right. The next m lines contain two integers per line, Xj Yj specifying where the j-th toy has landed in the box. The order of the toy locations is random. You may assume that no toy will land exactly on a cardboard partition or outside the boundary of the box. The input is terminated by a line consisting of a single 0.

Output

The output for each problem will be one line for each separate bin in the toy box. For each bin, print its bin number, followed by a colon and one space, followed by the number of toys thrown into that bin. Bins are numbered from 0 (the leftmost bin) to n (the rightmost bin). Separate the output of different problems by a single blank line.

Sample Input

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

Sample Output

0: 2
1: 1
2: 1
3: 1
4: 0
5: 1

0: 2
1: 2
2: 2
3: 2
4: 2

Hint

As the example illustrates, toys that fall on the boundary of the box are "in" the box.

解题思路:我是先求出截线段的直线的方程,再判断。方法比较笨,看到网上还有叉积的方法,以后在研究吧,先记下了

#include<stdio.h>
#define MAX 5003
struct Partion{
   double k;
   int x,count;
}par[MAX];
int inbin(int i,int x,int y);
int n,m,x1,y1,x2,y2,xt,yt;
int main(void){ 
    int i,j;
    while(scanf("%d",&n)!=EOF){
if(n==0)break;
         scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2); par[0].k=0; par[0].x=x1; par[0].count=0;
         int U,L,yb=y1-y2;
         for(i=1;i<=n;i++){ scanf("%d%d",&U,&L);
             if(U==L){
                par[i].k=0; par[i].x=U; par[i].count=0;
             }
             else{
                par[i].k=((double)(yb))/(U-L);
                par[i].count=0; par[i].x=U;
             }
         }
         par[i].k=0; par[i].x=x2; par[i].count=0;
         for(j=0;j<m;j++){
             scanf("%d%d",&xt,&yt);
             for(i=0;i<n+1;i++){
                if(inbin(i,xt,yt)!=0){ par[i].count++; break;}
             }
         }
         for(i=0;i<n+1;i++){
             printf("%d: %d\n",i,par[i].count);
         }
         printf("\n");   
    }
    return 0;
}
int inbin(int i,int x,int y){
    double bt;
    int big=0,small=0;
    if(par[i].k==0){
        if(x>par[i].x) big=1;
    }
    else{
        bt=par[i].k*(x-par[i].x)+y1;
        if(par[i].k>0){
            if(y<bt) big=1;
        }
        else {
           if(y>bt)big=1;
       }  
   }
   if(big==1){
        if(par[i+1].k==0){
            if(x<par[i+1].x) small=1;
        }
        else{
            bt=par[i+1].k*(x-par[i+1].x)+y1;
            if(par[i+1].k>0){
               if(y>bt) small=1;
            }
            else {
               if(y<bt)small=1;
            }  
        }

   }
   return (big==1&&small==1);
}





TOYS玩具模型资源 3dmax模型高模,卡通玩偶模型 ~ 立即下载

相关推荐

SAP ABAP BADI_FINS_ACDOC_POSTING_EVENTS 深度应用:KO88工单结算的凭证字段定制与财务数据增强

本文深入探讨了SAP ABAP中BADI_FINS_ACDOC_POSTING_EVENTS在KO88工单结算中的应用,详细解析了如何通过BADI实现财务凭证字段的定制与数据增强。文章提供了从结构扩展到BADI方法实现的完整步骤,包括性能优化建议和实际应用中的测试验证流程,帮助开发人员高效解决企业个性化财务需求。

weixin_26869081的博客 389

TOYS

点击打开链接 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 when he is finished

650

Microduck机器鸭开源AI项目:本地部署与模型微调实战指南

开源AI模型的本地化部署与定制化训练正成为开发者关注的技术趋势。与依赖云端API的在线服务不同,本地部署允许用户将模型权重下载至自有GPU环境,通过命令行或WebUI完成推理、批量任务处理及API集成,在数据隐私、离线使用和接口稳定性方面具备天然优势。模型微调则基于预训练权重,利用领域数据训练特定任务,从而提升生成质量与业务适配度。这一技术路径广泛应用于内容生成、智能对话、自动标注等场景,尤其适合消费级显卡开发者、数据敏感型团队及二次开发研究者。Microduck(机器鸭)作为近期预售火爆的开源项目,围绕“

weixin_29082143的博客 409

pku 2398

http://acm.pku.edu.cn/JudgeOnline/problem?id=2398. 敲的时候sb掉了。。写数论习惯性的是 unsigned __int64 u64..于是乎也贴了上去...于是乎。。因为unsigned....... #include #include #include #include #include #include #include

timluoTC的专栏 517

利用LATX技术在龙芯安同AOCS OS上部署坚果云:跨架构文件同步实战

本文详细介绍了如何在龙芯安同AOCS OS上,利用LATX指令翻译技术部署坚果云客户端,实现跨架构文件同步。通过安装LATX环境、解压x64安装包、运行安装脚本三步,成功在loongarch64架构上运行仅支持x86_64的软件,解决了国产平台办公协同的痛点,并分享了性能实测与优化建议。

weixin_29305337的博客 456

Codex智能体从零搭建:环境配置、代码管理与MCP扩展实战

AI智能体(Agent)作为连接大语言模型与实际应用的关键技术,通过感知、决策与执行框架,将AI能力融入具体工作流。其核心原理在于利用提示工程、上下文管理与工具调用,将自然语言指令转化为可执行操作。在软件开发领域,AI智能体能够显著提升代码生成、项目管理和自动化任务的效率。通过Model Context Protocol(MCP)等标准化协议,智能体可以安全、结构化地集成外部工具与服务,实现能力扩展。本文聚焦于Codex这一AI驱动的代码助手平台,详细解析其环境配置、代码索引、记忆系统等核心模块,并深入探讨

weixin_34220179的博客 589

放玩具,用几何方法求解+二分

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 when he is finished playing with them. They gave John a rectangular box to put his toys in,

Conqueror_demons的博客 509

VizCut 全自动批量视频二次去重处理!支持视频无水印解析下载和批量剪辑,完全免费,使用简单!

可制作和分享剪辑模板,已提供20+种剪辑方案,内置众多扫光蒙版素材。支持二次去重批量处理,完全免费,无广告,且支持视频无水印解析下载,非常强大。如果说我们处理的视频需要进行一样的参数设置的话,就可以把我,1设置的参数设置为模板,后面就可以一键调用。1. 本地CPU处理,可设置线程数,可开启GPU加速,无任何限制,全看机器性能。适用场景:自媒体搬运、短视频二创、批量去重等,完全免费,无广告干扰!3. 20+种参数可调可选,内置很多相关素材。可保存为模板,可复用、可分享、可导入。2. 所有参数的设置,

goodfat的博客 5312

poj2318

题意:一个矩形箱子,左上角与右下角的坐标给出,里面有n块板把箱子里的空间分隔成许多个分区,给出这些板在上边的x坐标、下边的x坐标,以及一堆玩具的坐标,求这些分区里的玩具数目。 分析:记玩具在点p0,某块板的上边点是p1,下边点是p2,p2p1(向量)×p2p0>0表示p0在p1p2的左面,<0表示在右面。接下来就是用二分法找出每个点所在的分区。 叉积+二分查找 #includ...

weixin_33721427的博客 165

详解Xilinx FPGA高速串行收发器GTX/GTP(6)--Pattern Generator/Pattern Checker

详解Xilinx FPGA高速串行收发器GTX/GTP(6)--Pattern Generator/Pattern Checker

孤独的单刀 1624

线性自抗扰控制(LADRC)系统算法框图

NLADRC自抗扰控制从Simulink仿真到PLC控制实现_自抗扰控制器 simulink仿真-优快云博客本文介绍了如何将ADRC自抗扰控制算法从Simulink仿真应用到PLC控制中,包括Simulink框图、TD微分器模型、MATLAB函数的使用、SCL控制代码,以及非线性状态误差反馈控制率的实现。提供了详细的MATLAB仿真步骤和PLC源代码链接。ADRC自抗扰控制算法(含梯形图完整源代码和算法公式)_adrc算法-优快云博客。

RXXW_Dor的博客 1461

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

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 when he is finished playing with

叶梨子 865

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

[USACO Nov08]玩具toys解题报告

题目 http://cojs.tk/cogs/problem/problem.php?pid=2007 分析 首先,稍有常识的人都会看出,这道题其实就是网络流24题中“餐巾问题”的加强版。 “餐巾问题”的标准做法是费用流:每天拆成两点(i,i'),然后S向i'连容量Ti(第i天用量),费用0的边,代表当天的脏餐巾。当然还有别的边,但这个是最重要的。 其实“餐巾

uKJLThHU$(eQ 6334

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

【CodeForces】CodeForces Round #504 (Div. 1 + Div. 2) 题解

【比赛链接】 点击打开连接 【题解链接】 点击打开链接 **【A】**Single Wildcard Pattern Matching 【思路要点】 判断 SSS 的星号前后是否为 TTT 中不相交的前缀和后缀。 时间复杂度 O(N+M)O(N+M) O(N+M) 。 【代码】 #include&amp;amp;amp;lt;bi...

cz_xuyixuan的博客 401

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

ACM计算几何题目推荐

把下面的东东都看看,题目刷刷应该就差不多了吧哈。。哈哈。。 其实也谈不上推荐,只是自己做过的题目而已,甚至有的题目尚未AC,让在挣扎中。之所以推荐计算几何题,是因为,本人感觉ACM各种算法中计算几何算是比较实际的算法,在很多领域有着重要的用途(例如本人的专业,GIS)。以后若有机会,我会补充、完善这个列表。 计算几何题的特点与做题要领: 1.大部分不会很难,少

街角的花街糖 2457

POJ 2318 - TOYS (计算几何)

POJ 2318- TOYS 一个比较适合入门的基础题 题目: 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 when he is finished ...

weixin_45691686的博客 340

poj 2318 TOYS(叉积的应用)

TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7307   Accepted: 3453 Description Calculate the number of toys that land in each bin of a partitioned

志当存高远 849

计算几何-点、线、面、形

1.TOYS 双语描述: 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 when he is...

weixin_30765319的博客 194

笔试小技巧--隔板法解排列组合问题(附代码)

笔试小技巧--隔板法

li27z的博客 6691

poj 2318(计算几何)

TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13238 Accepted: 6396Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad

qq_31457873的博客 474

POJ2318 TOYS

叉积+二分 当物品在直线右侧,叉积大于0,在直线左侧叉积小于0. TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7249   Accepted: 3426 Description Calculate the number of toys that lan

863

POJ 2318 TOYS

POJ 2318

Vontroy 514

TOYS(计算几何--点与线的关系(叉积+二分(二分之前必须排序!!!)))

Link:http://poj.org/problem?id=2318 TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12022   Accepted: 5799 Description Calculate the nu

林下的码路 1033

TOYS(计算几何基础+点与直线的位置关系)

题目链接:http://poj.org/problem?id=2318 题面:                                  TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17413 Accepted: 8300 Desc...

di6499的博客 237

TOYS(水解析)

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 when he is finished playing with them. They gave Jo

Techay的博客 740
上一篇: M - Toy Storage解题报告(来自网络)
下一篇: A - Truck History
CSUST_ACM
博客等级 码龄15年 42粉丝 127原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值