ACM--过沼泽--模拟--HDOJ 5477--A Sweet Journey

HDOJ题目地址:传送门

A Sweet Journey

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 759    Accepted Submission(s): 397

Problem Description

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≤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,Ri,
which represents the interval [Li,Ri] is
swamp.

1≤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+1 for
each i (1≤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<iostream>
#include<stdio.h>
#include<memory.h>
#include<algorithm>
using namespace std;
struct Node{
   int begin;
   int end;
   int chazhi;
}zhaoze[101];
bool cmp(Node a,Node b){
   if(a.begin<b.begin)
	   return true;
   return false;
}
int main(){
  int n,m,i,a,b,l,kaishi,jieshu,result,temp,index=1;
  cin>>n;
  while(n--){
      cin>>m>>a>>b>>l;
	  for(i=0;i<m;i++){
	     cin>>zhaoze[i].begin>>zhaoze[i].end;
		 zhaoze[i].chazhi=zhaoze[i].end-zhaoze[i].begin;
	  }
	  sort(zhaoze,zhaoze+m,cmp);
	  result=0;
	  temp=0;
	  kaishi=0;
	  jieshu=0;
	  for(i=0;i<m;i++){
	     temp=temp+(zhaoze[i].begin-jieshu)*b-zhaoze[i].chazhi*a;
		 jieshu=zhaoze[i].end;
		 if(result>temp){
		   result=temp;
		 }
	  }
	  temp+=(l-jieshu)*b;
	  if(result>temp){
		   result=temp;
	  }
	  if(result<0){
	       printf("Case #%d: %d\n",index,-result);
	  }else{
	      printf("Case #%d: 0\n",index);
	  }
	  index++;
  }
}
时间: 2024-10-09 17:31:42

ACM--过沼泽--模拟--HDOJ 5477--A Sweet Journey的相关文章

HDU 5477 A Sweet Journey

A Sweet Journey Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 741    Accepted Submission(s): 383 Problem Description Master Di plans to take his girlfriend for a travel by bike. Their journey

模拟 HDOJ 4552 Running Rabbits

题目传送门 1 /* 2 模拟:看懂题意,主要是碰壁后的转向,笔误2次 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <vector> 8 using namespace std; 9 10 const int MAXN = 1e3 + 10; 11 const int INF = 0x3f3f3f3f; 12 struct Rabbit 13

模拟 HDOJ 5387 Clock

题目传送门 1 /* 2 模拟:这题没啥好说的,把指针转成角度处理就行了,有两个注意点:结果化简且在0~180内:小时13点以后和1以后是一样的(24小时) 3 模拟题伤不起!计算公式在代码内(格式:hh/120, mm/120, ss/120) 4 */ 5 /************************************************ 6 * Author :Running_Time 7 * Created Time :2015-8-13 13:04:31 8 * Fil

模拟 HDOJ 5095 Linearization of the kernel functions in SVM

题目传送门 1 /* 2 题意:表达式转换 3 模拟:题目不难,也好理解题意,就是有坑!具体的看测试样例... 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <iostream> 8 #include <cstring> 9 #include <cmath> 10 #include <string> 11 #include <vector> 12 #i

模拟 HDOJ 5099 Comparison of Android versions

题目传送门 1 /* 2 题意:比较型号的大小 3 模拟:坑点在长度可能为5,此时设为'A' 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <iostream> 8 #include <cstring> 9 #include <cmath> 10 #include <string> 11 #include <vector> 12 #include &l

HDU5477(模拟)

A Sweet Journey Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 975    Accepted Submission(s): 504 Problem Description Master Di plans to take his girlfriend for a travel by bike. Their journey,

【转】ACM/ICPC生涯总结暨退役宣言—alpc55

转自:http://hi.baidu.com/accplaystation/item/ca4c2ec565fa0b7fced4f811 ACM/ICPC生涯总结暨退役宣言—alpc55 前言 早就该写这篇文章了,但是也很不想去写.毕竟是为之奋斗了两年的目标,不是说舍得就舍得的.然而,自己毕竟是到了该退的时候了,与其扭扭捏捏,不如挥一挥衣袖,尚落得一份潇洒.回首这两年来,有很多是需要总结的.在这里不分巨细的记录下来,或许有点像流水账,但是更多的,是一份对过去的难忘. 童年 我的ACM/ICPC的生

50题(ACM学习推荐题)

POJ推荐50题 1. 标记"难"和"稍难"的题目可以看看,思考一下,不做要求,当然有能力的同学可以直接切掉. 2. 标记为 A and B 的题目是比较相似的题目,建议大家两个一起做,可以对比总结,且二者算作一个题目. 3. 列表中大约有70个题目.大家选做其中的50道,且每类题目有最低数量限制. 4. 这里不少题目在 BUPT ACM FTP 上面都有代码,请大家合理利用资源. 5. 50个题目要求每个题目都要写总结,养成良好的习惯. 9. 这个列表的目的在于让

线程中 模拟死锁问题

package hpu.acm.lzl.demos; /** * 模拟一个死锁的环境. * 死锁就是用synchronized实现的. * 一个线程使用synchronized 锁定一个方法之后 等待第二个线程释放资源完成第二个锁的操作. * 另一个线程使用synchronized 锁定一个方法后 等待第一个线程释放资源完成第二个锁. * 因此产生了 死锁 * @author admin * */ public class DeadLockdemos implements Runnable{ s