您的位置:首页 > 其它

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

代码:

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: