pku 1771Elevator Stopping Plan

2023-10-30 10:48
文章标签 plan pku stopping 1771elevator

本文主要是介绍pku 1771Elevator Stopping Plan,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

有两道Elevator Stopping Plan,做了一道,另一道也顺便过了

方法是二分+贪心

一旦时间确定了,就可以用贪心来处理,只要保证每个人在时限之内到达,如果成功就进一步缩时间,不能就放宽时限。

还有一道也是这样做的。 3388 Japanese puzzle,二分枚举最大行数,一旦行数确定了,就可以用贪心的方式,看能否达到。

http://acm.pku.edu.cn/JudgeOnline/problem?id=1064,这个也是的,二分枚举+验证。

/*change from 1774*/
#include <iostream>
#define N 30001
using namespace std;
bool stop[N];
int n;
int stk[N];
bool satisfy(int t)
{
int I,J=0,nStop=0;
I=(t/20+1+1); // below(not including) walk
while (I<n)
{
while (I<n && stop[I] == false) ++I;
if (I>=n) return true;
if ((I-1)*4 + nStop*10>t)
return false;
J = (t + 4 + 20*I - 10*nStop)/24; // elevator stops here
I = (t + 16*J + 4 -10*nStop)/20 +1; // below (not inclu.) ok
++ nStop;
} 
return true;
}
void print(int t)
{
int I,J=0,nStop=0;
I=(t/20+1+1); // below(not including) walk
while (I<n)
{
while (I<n && stop[I] == false) ++I;
if (I>=n) break;
J = (t + 4 + 20*I - 10*nStop)/24; // elevator stops here
I = (t + 16*J + 4 -10*nStop)/20 +1; // below (not inclu.) ok
stk[nStop] = J;
++ nStop;
}
printf("%d",nStop);
for (int I=0; I<nStop; ++I)
{
printf(" %d",stk[I]);
}
printf("/n");
}
int main()
{
int I,J;
int high;
while (scanf("%d",&n)!=EOF)
{
if (n==0) break;
memset(stop,0,sizeof(stop));
high=0;
for (I=0; I<n; ++I)
{
scanf("%d",&J);
high=max(high,J);
stop[J] = true;
}
int maxt, mint, midt;
maxt=12*high+24;
mint=0;
n = high+1;
while (mint<=maxt)
{
midt=(mint+maxt)/2;
if (satisfy(midt))
{
maxt=midt-1;
}
else
{
mint=midt+1;
}
}
printf("%d/n",mint);
print(mint);
}
}

这篇关于pku 1771Elevator Stopping Plan的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/307385

相关文章

Study Plan For Algorithms - Part24

1. 包含min函数的栈 定义栈的数据结构,要求在该类型中实现一个 min 函数,能够获取栈的最小元素。在该栈中,调用 min、push 以及 pop 函数的时间复杂度均为 O (1)。 方法: class MinStack:def __init__(self):self.stack = []self.min_stack = [float('inf')]def push(self, x):sel

执行计划查看方法(Explain plan)

什么是执行计划 所谓执行计划,顾名思义,就是对一个查询任务,做出一份怎样去完成任务的详细方案。举个生活中的例子,我从珠海要去英国,我可以 选择先去香港然后转机,也可以先去北京转机,或者去广州也可以。但是到底怎样去英国划算,也就是我的费用最少,这是一件值得考究 的事情。同样对于查询而言,我们提交的SQL仅仅是描述出了我们的目的地是英国,但至于怎么去,通常我们的SQL中是没有给出提示信息

Study Plan For Algorithms - Part21

1. 二叉树的镜像 输入一个二叉树,输出它的镜像。 方法一: class TreeNode:def __init__(self, val=0, left=None, right=None):self.val = valself.left = leftself.right = rightdef mirrorTree(root):if not root:return Nonetemp, left,

人工智能:模型复杂度、模型误差、欠拟合、过拟合/泛化能力、过拟合的检测、过拟合解决方案【更多训练数据、Regularization/正则、Shallow、Dropout、Early Stopping】

人工智能:模型复杂度、模型误差、欠拟合、过拟合/泛化能力、过拟合的检测、过拟合解决方案【更多训练数据、Regularization/正则、Shallow、Dropout、Early Stopping】 一、模型误差与模型复杂度的关系1、梯度下降法2、泛化误差2.1 方差2.2 偏差2.3 噪声2.4 泛化误差的拆分 3、偏差-方差窘境(bias-variance dilemma)4、Bias

【ORACLE】如何使用EXPLAIN PLAN来分析 listagg() 函数的性能瓶颈?

在Oracle数据库中,EXPLAIN PLAN 语句用于显示SQL语句的执行计划,这对于分析和优化查询性能至关重要。要使用 EXPLAIN PLAN 来分析包含 LISTAGG 函数的查询的性能,你可以按照以下步骤操作: 步骤 1: 生成执行计划 首先,你需要为包含 LISTAGG 的查询生成执行计划。这可以通过以下命令完成: EXPLAIN PLAN FORSELECT departm

导入项目时报以下错误Could not calculate build plan: Plugin org.apache.maven.plugins:maven-

导入项目时报以下错误. Could not calculate build plan: Plugin org.apache.maven.plugins:maven-war-plugin:2.1.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for ...     此问题

因路径规划异常导致导航停止 Failed to pass global plan to the controller

因路径规划异常导致导航停止 Failed to pass global plan to the controller 控制台错误信息: [ WARN] [1718875656.343893537, 93.698000000]: Transformed plan is empty. Aborting local planner![ERROR] [1718875656.343922719,

PKU Campus 2011 B A Problem about Tree lca倍增

B:A Problem about Tree 总时间限制:  1000ms  内存限制:  65536kB 描述 Given a tree with Nvertices and N- 1 edges, you are to answer Qqueries on "which vertex isY's parent if we choose Xas the ro

uvalive 2949 - Elevator Stopping Plan(贪心+二分)

题目连接:2949 - Elevator Stopping Plan 题目大意:某个抠门的公司只有一个电梯, 现在有n 个人从1楼, 他们有各自想要到达的楼层, 然后电梯每上一楼需要4 秒, 每在一个楼层开门需要10 秒, 然后然爬楼梯的话需要20一楼。问, 如何用最短的时间让所有人都到达各自想要到的楼层。 解题思路:因为人可以爬楼梯, 所以可以在某个楼层下楼之后走楼梯到达想要到的

How Resource Plan Directives Interact--多个执行命令都引用了同一个用户组

文档地址:http://docs.oracle.com/cd/B19306_01/server.102/b14231/dbrm.htm#ADMIN027     How Resource Plan Directives Interact If there are multiple resource plan directives that refer to thesame consumer gr