A Sweet Journey (沼泽地和平地)

HDU - 5477 

 

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

 

题意:走一段有沼泽有平路的路,走沼泽地时每米消耗a点体力,走平路时每秒恢复b点体力,求最开始需要最少的体力。

可以直接模拟这个状态就可以做出来,也有的大佬用二分做,我当时是直接进行的模拟。

简单模拟:

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
typedef long long ll;

struct ss{
	int l;
	int r;	
}s[200];

int main()
{
	int n,a,b,l,t;
	cin>>t;
	int k=0;
	while(t--){
		k++;
		cin>>n>>a>>b>>l;
		for(int i=0;i<n;i++){
			scanf("%d %d",&s[i].l,&s[i].r);
		}
		int ans=0;
		int temp=0;
		int c=0;
		for(int i=0;i<n;i++){
			c+=b*(s[i].l-temp);
			if(c<(s[i].r-s[i].l)*a){
				ans+=((s[i].r-s[i].l)*a-c);
				c=0;
			}
			else{
				c-=(s[i].r-s[i].l)*a;
			}
			temp=s[i].r;
		}
		printf("Case #%d: %d\n",k,ans);	
	}

	return 0;
}

 

二分:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
const int maxn=110;
struct Node{
	int l,r;
}A[maxn];
int a,b;
bool judge(int mid,int n){
	int ans=mid,l=0;
	for(int i=0;i<n;++i){
		ans+=b*(A[i].l-l);
		ans-=a*(A[i].r-A[i].l);
		l=A[i].r;
		if(ans<0)return false;
	}
	return true;
}
int main()
{
	int t,i,j,k=1,l,n;
	scanf("%d",&t);
	while(t--){
		scanf("%d%d%d%d",&n,&a,&b,&l);
		int l=0,r=0;
		for(i=0;i<n;++i){
			scanf("%d%d",&A[i].l,&A[i].r);
			r+=(A[i].r-A[i].l)*a;
		}
		printf("Case #%d: ",k++);
		int ans=r;
		while(l<=r){
			int mid=(l+r)>>1;
			if(judge(mid,n)){
				ans=mid;
				r=mid-1;
			}
			else {
				l=mid+1;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值