Moving Tables

moving Tables java 实现moving Tables 立即下载

The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables are big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out the following plan: Moving a table from a room to another room can be done within 10 minutes. When moving a table from room i to room j, the part of the corridor between the front of room i and the front of room j is used. So, during each 10 minutes, several moving between two rooms not sharing the same part of the corridor will be done simultaneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving.

这里写图片描述
Table moving
Reason
Possible
( room 30 to room 50) and (room 60 to room 90)
no part of corridor is shared
(room 11 to room 12) and (room 14 to room 13)
no part of corridor is shared
Impossible
(room 20 to room 40) and (room 31 to room 80)
corridor in front of room 31 to room 40 is shared
(room 1 to room 4) and (room 3 to room 6)
corridor in front of room 3 is shared
(room 2 to room 8) and (room 7 to room 10)
corridor in front of room 7 is shared

For each room, at most one table will be either moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job is to write a program to solve the manager’s problem.

输入
The input consists of T test cases. The number of test cases ( T) is given in the first line of the input file. Each test case begins with a line containing an integer N , 1<= N<=200 , that represents the number of tables to move. Each of the following N lines contains two positive integers s and t, representing that a table is to move from room number s to room number t (each room number appears at most once in the N lines). From the N+3-rd line, the remaining test cases are listed in the same manner as above.

输出
The output should contain the minimum time in minutes to complete the moving, one per line.

样例输入
3
4
10 20
30 40
50 60
70 80
2
1 3
2 200
3
10 100
20 80
30 50
样例输出
10
20
30

题目不难,英文有些难以理解。
题目意思就是从两个不同的房间移桌子,移动桌子需要占用房间之间的过道,占用一次需要10分钟,问至少需要多少时间。
以最后一次输入为例
用数组a[200]初始化为0
3
10 100 经过 5-50过道 这过道的值都+1
20 80 经过 10-80过道

这过道的值都+1
30 50

经过 15-25过道 这过道的值都+1
扫一遍 寻找 a[200]中的最大值 发现 15-25 这10个数都是3 最大 即 15-25这个过道必须得被占用3次
用 3*10(time)就可得出正确结论

#include<stdio.h>
int main()
{
    int x,s,n,t,i,temp;
    scanf("%d",&x);
    while(x--)
    {
        int ans[300]={0};
        //memset(ans,0,sizeof(ans));另一种初始化数组值为0的方法
        scanf("%d",&n);
        while(n--)
        {
            scanf("%d %d",&s,&t);
            if(s>t)
            {
                temp=t;t=s;s=temp;
            }
            for(i=(s+1)/2;i<=(t+1)/2;i++)
            {
                ans[i]++;
            }
        }
        int max=0;
        for(i=1;i<=200;i++)
        {
            if(max<ans[i])
            {
                max=ans[i];
            }
        }
        printf("%d\n",max*10);
    }
} 

memset(a,0,sizeof(a))意思就是将a数组所有值初始为0;
这里初始值只能是0或-1;
因为memset是对每个字节赋值,而int有4字节(32位)
比如这样,memset(a,1,sizeof(a));
则a中的每个元素都被赋值成为2进制数为00000001000000010000000100000001的数
转换成10进制就是16843009
所以,一般用memset对数组赋0或-1,赋其他的值就要用循环来实现。
用int a[10]={0};也可以初始化所有值为0;
int a[10]={10};意思为a[0]的值为10,其他值为0;

TypeError: XGBClassifier.fit() got an unexpected keyword argument ‘early_stopping_rounds‘ 解决方案 本文主要介绍了TypeError: XGBClassifier.fit() got an unexpected keyword argument 'early_stopping_rounds’解决方案,希望能对使用XGBoost的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案 阅读详情

相关推荐

AI虚拟人物 数字人直播,不用出镜,不用露脸的直播方式(附教程 软件)

我们先来看一组数据,这是我通过蝉妈妈查到的某位虚拟主播的一个带货数据,粉丝还不到 3000 人,每次直播 1 到 4 个小时,30天的总销量达到了1200单,15天,总销售额 2 万,可能相对来说客单价还是比较低,最关键的是才直播了 6 场,如果说他能够一个月直播 20 天,每天花 4个小时去直播,当个副业来做,就可以达到最起码月入 3 万的一个收入水平,我个人觉得是非常的不错的。大家把商品图片放在背景,只要场景设置的不错,场景和产品的关联度高,直播的时候挂上购买链接也会有一定的成交。

. 7万+

Moving Tables ——经典贪心和区间覆盖问题

The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.      The floor has 200 rooms each on the north side and south side along th...

mumei的博客 893

MOSFET导通电阻Rdson全解析:物理组成、公式推导与工程选型要点

在功率电子设计中,MOSFET作为核心开关器件,其导通电阻Rdson直接决定导通损耗与系统效率。从半导体物理角度看,Rdson并非单一固定值,而是由源极电阻、沟道电阻、累积层电阻、JFET区电阻、漂移区电阻及衬底电阻等多个分量串联而成,并随栅极驱动电压、结温以及击穿电压等级发生显著变化。理解Rdson的物理来源与数学表达,有助于工程师在低压大电流与高压小电流等不同场景中合理选型、优化驱动电压并准确估算热损耗。文章从沟道电阻公式出发,深入剖析耐压与导通电阻的物理矛盾、温度系数的影响规律,并给出数据手册参数的正

weixin_29163857的博客 199

Moving Tables(贪心算法)

题目描述 著名的ACM公司租用了一幢楼的一层,其形状如下。 整个楼层在走廊的北面和南面各有300个房间。最近公司制定了一个改变布局的方案,包括在不同房间之间移动许多桌子。由于走廊狭窄,而且桌子都很大,只有一张桌子可以穿过走廊。为了提高工作效率,经理制定了如下方案:把一张桌子从一个房间搬到另一个房间可以在5分钟内完成。当移动一张桌子从I房间搬到J房间时,房间I前面和房间J前面的走廊部分被使用了。因此,在每5分钟,在不共用走廊的情况下,不同的移动方案可以同时进行。为了说明问题,经理举例说明了可能发生的情况和不可

weixin_47511190的博客 2096

手把手教你用AI工具快速开发UniApp首页:从设计稿到完整页面的实战流程

本文详细介绍了如何利用Claude Code、Cursor等AI工具高效开发UniApp首页的完整工作流。从设计稿解析、Prompt工程、代码生成优化到调试适配,提供了一套可复用的实战流程,帮助前端开发者大幅提升从设计到代码的转化效率。

weixin_29199873的博客 321

Spring Boot 实现多图片上传并回显,涨姿势了~

上传 Controller的代码非常简单,由于用了SpringMVC框架,所以直接用MultipartFile来接即可。由于是多图片上传所以用数组来接。此处应该注意参数名应该和<input>中的name值相对应: @RequestMapping("/pic") @ResponseBody publicResponseEntity<String>pic(MultipartFile[]pictures)throwsException{ ResponseEnti...

weixin_54556126的博客 894

Moving Tables贪心

题目:传送门 大概意思就是说:有一条走廊,两边各有两百个总共四百个房间(有编号的),任务是在这些房间之间移动桌子。当一张桌子从房间 s 移动到房间 t,那它们之间的走廊部分就被征用了,这部分的房间就不可以移动桌子,其他部分的房间可以移动桌子。移动一张桌子需要十分钟,求最短的移动桌子所花的时间。 思路:用数组mark标记走廊位置被标记的次数,若移动多个桌子时,所需要经过的走廊没有重合处,即可以同时移动。若有一段走廊有m个桌子都要经过,一次只能经过一个桌子,走过的走廊都要被标记一次,走廊被经过最多的次数乘以时间

G191018的博客 342

Labview程序框架介绍

当掌握LabVIEW基础知识并达到,理解单个小型模块程序会相对轻松。而若想进一步探索大型程序,就必然需要了解程序框架相关内容。LabVIEW常用的程序架构包括等。在多年工作中,我接触过的众多高级工程师所开发的大型程序,基本都基于这些架构搭建。接下来,将为大家详细介绍这些框架。

Misterlhw的博客 4626

算法-------moving tables

下图是著名的ACM(高级计算机制造商)公司租用的建筑物的地板。 该楼层在走廊的北侧和南侧各有200个房间。最近,公司制定了改革其系统的计划。改革包括在房间之间移动很多桌子。由于走廊狭窄且所有桌子都很大,因此只有一张桌子可以穿过走廊。需要一些计划来提高移动效率。经理制定了以下计划:将桌子从一个房间移到另一个房间可以在10分钟内完成。将桌子从房间i移到房间j时,将使用房间i的正面和房间j的正面之间的走廊部分。因此,在每10分钟内,将在不共享走廊同一部分的两个房间之间同时移动几个房间。为了清楚起见,经理说明了同

weixin_43846020的博客 597

Qt for Android:基于libusb实现CH340x串口通信的高效开发方案

本文详细介绍了在Qt for Android环境下,基于libusb实现CH340x串口通信的高效开发方案。通过绕过Android高版本系统的权限限制,利用libusb+JNI技术实现稳定通信,适用于工业手持终端等场景。文章涵盖环境搭建、核心实现、常见问题解决方案及性能调优经验,帮助开发者快速掌握这一关键技术。

weixin_42715608的博客 428

vscode配置matlab工作环境

前面有两篇文章我们分别讲了在vscode里面如何配置C语言环境和python环境,那两篇文章总体来说比较复杂,当然这篇也有许多有趣的问题。 附上链接: 文章目录matlab简介基本要求code runner插件与matlab相关的插件添加路径小结code runner是否支持更多语言更多选择另一个选择 matlab简介 MATLAB是美国MathWorks公司出品的商业数学软件,用于数据分析、无线通信、深度学习、图像处理与计算机视觉、信号处理、量化金融与风险管理、机器人,控制系统等领域。 MATLAB是ma

Cachel Wood的博客 4543

【HDOJ】1050 moving tables

2.对于两次搬运而言,上一次的end和下一次的begin相同时是可以搬到,没有重叠的走廊空间。3.begin不一定小于end,他可能反着搬,即从房间序号大的搬到房间序号小的。杭电oj里的moving tables问题,可以用贪心算法解决。1.每次循环过后记得重定义ismoved为0.

Coyilla的博客 343

欺诈文本分类微调(一):基座模型选型

通义千问Qwen2具有0.5B、1.5B、7B、72B等一系列参数大小不等的模型,我们需要做的是从大到小依次测试每个模型的能力,找到满足自己需要的最小参数模型。依1.5B和1.5B-Instruct的主要区别:按照官方文档,前者是预训练模型,后者是经过指令微调的模型。

golfxiao的专栏 2656

HDOJ_1050 Moving Tables 解题报告

Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.  The floor has 200 rooms each on the north sid

xxm137164869的专栏 2024

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

POJ1083 Moving Tables

POJ1083 Moving Tables Time Limit:1000MS Memory Limit:10000K Total Submissions:35297 Accepted:11774 Description The famous ACM (Advanced Computer Maker) Company has ...

weixin_30760895的博客 156

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

1050 Moving Tables 贪心算法

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12304    Accepted Submission(s): 4226 Problem Description The famous

Jolesen的博客 715

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

POJ 1083 Moving Tables

POJ 1083 Moving Tables The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure. The floor has 200 rooms each on the north side and sout...

不屈不挠的拉普 288

hdu-1050 Moving Tables

hdu-1050 Moving Tables 题目链接 Problem description The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure. The floor has 200 rooms...

bayleexu 350

hdoj.1050 Moving Tables 20140811

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 19258    Accepted Submission(s): 6579 Problem Description The famous AC

>>--» 唯n1.情缘«--<< 286

POJ 1083 Moving Tables 已被翻译

woniupengpeng的专栏 382

zoj1029 Moving Tables

//zoj1029 Moving Tables //Accepted 1029 C++ 00:00.01 436K #include #include #include using namespac

fairylan的专栏 944

HDOJ 1050 Moving Tables 【贪心】

HDOJ 1050 Moving Tables 【贪心】 题目链接 acm.hdu.edu.cn/showproblem.php?pid=1050 这个题是根据贪心训练所以写的贪心 但是有一种更简单的求法就是求最大重复区间: 【将走廊分成200块,每次输入后就对涉及到的走廊+1 最后输出这些数组里最大的数*10就可以了】 上面这种写法比较简单,不贴代码了 贪心的话首先

... 343

杭电 1150 moving tables

http://acm.hdu.edu.cn/showproblem.php?pid=1050 Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18850    Accepted Submiss...

weixin_34067102的博客 102

HDU-1050-Moving Tables(C++ && 贪心初步)

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 23147    Accepted Submission(s): 7779 Problem Description The famous

保持对编程的热情! 1656

Moving tables

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 36594    Accepted Submission(s): 12040 Problem Description The famous

穆梓先生 1397
上一篇: Elevator
下一篇: 希尔排序
Ethan_YS
博客等级 码龄10年 3粉丝 7原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值