hdoj 5477 A Sweet Journey
2016-04-24 00:14
176 查看
E - A Sweet Journey
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit
Status
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 \leq t \leq 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: $L_i, R_i$, which represents the interval $[L_i, R_i]$ is swamp.
$1 \leq n \leq 100, 1 \leq L \leq 10^5,1 \leq A \leq 10,1 \leq B \leq 10,1 \leq L_i < R_i \leq L$.
Make sure intervals are not overlapped which means $R_i < L_{i + 1}$ for each i ($1 \leq 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
代码:
代码:
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit
Status
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 \leq t \leq 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: $L_i, R_i$, which represents the interval $[L_i, R_i]$ is swamp.
$1 \leq n \leq 100, 1 \leq L \leq 10^5,1 \leq A \leq 10,1 \leq B \leq 10,1 \leq L_i < R_i \leq L$.
Make sure intervals are not overlapped which means $R_i < L_{i + 1}$ for each i ($1 \leq 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
代码:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,a,b,l; int shu[101000]; int main() { int t;scanf("%d",&t); for (int ca=1;ca<=t;ca++) { int x,y; scanf("%d%d%d%d",&n,&a,&b,&l); for (int i=1;i<=l;i++) shu[i]=b; for (int i=0;i<n;i++) { scanf("%d%d",&x,&y); for (int j=x+1;j<=y;j++) shu[j]=-a; } int s=0,sum=0; for (int i=1;i<=l;i++) { s+=shu[i]; sum=min(sum,s); } printf("Case #%d: %d\n",ca,-1*sum); } return 0; }
代码:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,a,b,l; int shu[101000]; int main() { int t;scanf("%d",&t); for (int ca=1;ca<=t;ca++) { int x,y; scanf("%d%d%d%d",&n,&a,&b,&l); memset(shu,0,sizeof(shu)); for (int i=0;i<n;i++) { scanf("%d%d",&x,&y); shu[y]=-1*(y-x)*(a+b); } int s=0,sum=0; for (int i=1;i<=l;i++) { s+=shu[i]+b; sum=min(sum,s); } printf("Case #%d: %d\n",ca,-1*sum); } return 0; }
相关文章推荐
- 内存分类
- 深度理解链式前向星
- Jquery settimeout
- iOS开发——Autolayout的实践与技巧
- curl库函数简介
- Arm9+linux fl2440 驱动移植之RTC(实时时钟)和USB host
- Android中View的绘制
- 八、文件函数库 序列化数据 文件包含
- html table的坑
- TextView中ellipsize属性
- 集线器,交换机,路由器的作用
- ubuntu安装配置ssh-connect to host localhost port 22: Connection refused
- Oracle的pipelined函数实现高性能大数据处理
- javascript语言两种变量类型及存储方式
- 第四周总结
- Part 15 AngularJS ng init directive
- Integer Break | Leetcode 整数分解
- 多线程的简单介绍
- 如何使用google搜索
- Python数据可视化练习