【HDU - 5477】A Sweet Journey(思维,水题)

题干:

Master Di plans to take his girlfriend for a travel by bike. Their journey, which can be seen as a line segment of length L, is a road of swamps and flats. In the swamp, it takes A point strengths per meter for Master Di to ride; In the flats, Master Di will regain B point strengths per meter when riding. Master Di wonders:In the beginning, he needs to prepare how much minimum strengths. (Except riding all the time,Master Di has no other choice) 

Input

In the first line there is an integer t (1≤t≤501≤t≤50), indicating the number of test cases. 
For each test case: 
The first line contains four integers, n, A, B, L. 
Next n lines, each line contains two integers: Li,RiLi,Ri, which represents the interval [Li,Ri][Li,Ri] is swamp. 
1≤n≤100,1≤L≤105,1≤A≤10,1≤B≤10,1≤Li<Ri≤L1≤n≤100,1≤L≤105,1≤A≤10,1≤B≤10,1≤Li<Ri≤L. 
Make sure intervals are not overlapped which means Ri<Li+1Ri<Li+1 for each i (1≤i<n1≤i<n). 
Others are all flats except the swamps. 

Output

For each text case: 
Please output “Case #k: answer”(without quotes) one line, where k means the case number counting from 1, and the answer is his minimum strengths in the beginning. 

Sample Input

1
2 2 2 5
1 2
3 4

Sample Output

Case #1: 0

题目大意:

Mr.D 带着他的女朋友出去旅行,资金缺乏,就骑着自行车出发了!路途中会遇到沼泽地和平坦路。每在沼泽地骑行一米,Mr.D能量值减少a,每在平坦大路上骑行一米就恢复能量值b。为了能成功到达目的地,在出发前至少需补充多少能量。

解题报告:

跟之前做过的一个机器人的差不多,数形结合一下,横轴是到原点的距离,纵轴是能量变化,先假设原点的能量是0,最后输出图像的最低点就可以了。

AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cctype>
using namespace std;
typedef long long ll;
const int maxn=1e4+5;
int n,L,a,b;
int l[maxn],r[maxn];
int main()
{int t,i,j,k,cnt=0,nf;ll sum,ans;cin>>t;r[0]=0;for(;t;t--){scanf("%d%d%d%d",&n,&a,&b,&L); sum=ans=nf=0;if(nf) continue;for(i=1;i<=n;i++){scanf("%d%d",l+i,r+i);sum+=1LL*(l[i]-r[i-1])*b;sum-=1LL*(r[i]-l[i])*a;if(sum<0) {ans+=-sum;sum=0;}}printf("Case #%d: %lld\n",++cnt,ans);}return 0;
}

 

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

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

相关文章

图解算法学习笔记(八):贪婪算法

目录 &#xff08;1&#xff09;背包问题 &#xff08;2&#xff09;集合覆盖问题 &#xff08;3&#xff09;NP完全问题 &#xff08;4&#xff09;小结 本章内容&#xff1a; 学习如何处理没有快速算法的问题&#xff08;NP完全问题&#xff09;。学习近似算法&#xff…

图解算法学习笔记(九):动态规划

目录 &#xff08;1&#xff09;背包问题 &#xff08;2&#xff09;最长公共子串 &#xff08;3&#xff09;小结 本章内容&#xff1a; 学习动态规划&#xff0c;它将问题分成小问题&#xff0c;并先着手解决这些小问题。学习如何设计问题的动态规划解决方案。 &#xff…

Java(win10安装jdk,第一个hello world)

Java 第一步 &#xff1a;安装jdk 推荐默认安装。&#xff08;安装到C盘&#xff09;第二步 &#xff1a;配置jdk环境 JAVA_HOME C:\Program Files\Java\jdk1.8.0_191 JDK的安装路径 Path&#xff1a; C:\Program Files\Java\jdk1.8.0_191\bin JDK下bin目录的路径 &#xf…

#pragma 详解

#pragma 求助编辑 pragma - 必应词典美[prɡmə]英[prɡmə]n.〔计〕杂注网络编译指示&#xff1b;显示编译指示&#xff1b;特殊指令 百科名片 在所有的预处理指令中&#xff0c;#Pragma 指令可能是最复杂的了&#xff0c;它的作用是设定编译器的状态或者是指示编译器完成一些…

1.绪论

目录 &#xff08;1&#xff09;C语言传值与传地址变量 &#xff08;2&#xff09;算法效率的度量 &#xff08;3&#xff09;基本操作 &#xff08;4&#xff09;主函数 主要由实现基本操作和算法的程序构成。这些程序有6类&#xff1a; 数据存储结构&#xff0c;文件名第…

(ECC)椭圆曲线加密算法原理和C++实现源码

目录 &#xff08;1&#xff09;ECC加密原理&#xff1a; &#xff08;2&#xff09;编译生成LibTommath静态库 &#xff08;3&#xff09;ECC源码 今天介绍一下利用LibTommath数学库实现椭圆曲线加密算法的原理和源码。 &#xff08;1&#xff09;ECC加密原理&#xff1a;…

【POJ - 2553】The Bottom of a Graph(tarjan强连通分量缩点,模板题)

题干&#xff1a; We will use the following (standard) definitions from graph theory. Let V be a nonempty and finite set, its elements being called vertices (or nodes). Let E be a subset of the Cartesian product VV, its elements being called edges. Then G(…

机器学习笔记(1):Introduction

目录 1&#xff09;welcome 2&#xff09;What is Machine Learning 3&#xff09;Supervised Learning 4&#xff09;Unsupervised Learning 1&#xff09;welcome 第一个视频主要介绍了机器学习目前的案例&#xff0c;主要有&#xff1a;数据库挖掘、医疗记录、生物工程…

【POJ - 3352】Road Construction(Tarjan,边双连通分量)

题干&#xff1a; Its almost summer time, and that means that its almost summer construction time! This year, the good people who are in charge of the roads on the tropical island paradise of Remote Island would like to repair and upgrade the various roads…

机器学习简易入门-附推荐学习资料

目录 &#xff08;1&#xff09;机器学习正规学习路线 &#xff08;2&#xff09;机器学习快速入门 &#xff08;3&#xff09;总结 感谢黄海广博士的分享 原创&#xff1a; 机器学习初学者 机器学习初学者 今天 机器学习如何入门&#xff1f;目前没有明确的答案。本站面向…

C++11中的std::function

原文地址&#xff1a;http://www.jellythink.com/archives/771 看看这段代码 先来看看下面这两行代码&#xff1a; std::function<void(EventKeyboard::KeyCode, Event*)> onKeyPressed; std::function<void(EventKeyboard::KeyCode, Event*)> onKeyReleased; 这两…

【HDU - 3394】Railway(点双连通分量,Tarjan算法,思维tricks)

题干&#xff1a; There are some locations in a park, and some of them are connected by roads. The park manger needs to build some railways along the roads, and he would like to arrange tourist routes to each circuit. If a railway belongs to more than one …

飞机大战(简易版)

一、游戏分析 飞机大战中的主要“角色”有&#xff1a; 1.英雄 2.敌方飞机 3.英雄发射的子弹 我们需要控制的有&#xff1a; 1.绘制屏幕内的角色 2.控制角色的逻辑&#xff0c;比如&#xff1a;敌方飞机与我方飞机的碰撞检测&#xff0c;我方飞机发射的子弹与敌方飞机之间的碰撞…

在Ubuntu上安装Keras深度学习框架

目录 1&#xff09;安装pip 2&#xff09;安装Python科学套件 3&#xff09;安装TensorFlow 4&#xff09;安装keras 5&#xff09;安装Jupyter Notebook 6&#xff09;运行Keras 本文介绍如何在Ubuntu上安装Keras深度学习框架。 1&#xff09;安装pip 安装pip包&#…

【POJ - 1523】SPF(Tarjan求割点,求分割成的连通块数,模板题,tricks)

题干&#xff1a; Consider the two networks shown below. Assuming that data moves around these networks only between directly connected nodes on a peer-to-peer basis, a failure of a single node, 3, in the network on the left would prevent some of the still…

机器学习笔记(2):单变量线性回归

目录 1&#xff09;Model representation 2&#xff09;Cost function 3&#xff09;Cost function intuition 1 4&#xff09;Cost function intuition2 5&#xff09;Gradient descent 6&#xff09;Gradient descent intuition 7&#xff09;Gradient descent for li…

安装VMware tools

点击“虚拟机” 安装VMware tools提取图中文件到“下载” 提取登入root 进入 cd 下载/vmware-tools-distrib 执行 ./vmware-install-pl 输入yes或者点击“enter”出现图中&#xff0c;即为成功安装

Keras入门实战(1):MNIST手写数字分类

目录 1)首先我们加载Keras中的数据集 2&#xff09;网络架构 3&#xff09;选择编译(compile参数) 4&#xff09;准备图像数据 5) 训练模型 6&#xff09;测试数据 前面的博客中已经介绍了如何在Ubuntu下安装Keras深度学习框架。 现在我们使用 Keras 库来学习手写数字分…

【BZOJ - 2574】[Poi1999] Store-Keeper(点双连通分量,求割点,记忆化bfs)

题干&#xff1a; 有一个仓库被分成n*m 个矩形区域&#xff0c;如果两个区域有一条公共边&#xff0c;则被认为这两个区域相邻。包裹都放在一个区域中&#xff0c;剩余的区域或者空闲或者被集装箱占有&#xff0c;这是因为集装箱太重&#xff0c;仓库管理员不能将集装箱搬走。…

机器学习笔记(3):线性代数回顾

目录 1&#xff09;Matrices and vectors 2&#xff09;Addition and scalar multiplication 3&#xff09;Matrix-vector multiplication 4&#xff09;Matrix-matrix multiplication 5&#xff09;Matrix multiplication properties 6&#xff09;Inverse and transpos…