POJ 2355 Railway tickets
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 2472 | Accepted: 865 |
Description
Cost of the ticket between any two stations depends only on a distance between them. The prices for the tickets are specified in the following table.
distance between stations -X |
price for the ticket |
0<X<=L1 |
C1 |
L1<X<=L2 |
C2 |
L2<X<=L3 |
C3 |
Direct tickets from one station to another can be booked if and only if the distance between these station does not exceed L3. So sometimes it is necessary to book several tickets to pay for the parts of the whole way between stations.
For example, on the railway line shown at the figure above there are seven stations. The direct ticket from the second station to the sixth one can not be booked. There are several ways to pay for the travel between these stations. One of them is to book two tickets: one ticket at price C2 to travel between the second and the third stations, and other at price C3 to travel between the third and the sixth stations. Note, that though the distance between the second and the sixth stations is equal to 2*L2, the whole travel can not be paid by booking two tickets at price C2, because each ticket is valid for only one travel and each travel should start and end only at stations.
Your task is to write a program, that will find the minimal cost of the travel between two given stations.
Input
Output
Sample Input
3 6 8 20 30 40
7
2 6
3
7
8
13
15
23
Sample Output
70
题目大意:有一个铁路线,线上有n个站,每个站之间都有一段距离,这个车站根据路程的长短出售3种票,每种票能够乘坐的距离不同,一个票只能用于从一个站到另一个站,问从站a到站b花费的最少金钱。
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
int dist[], dp[]; int main()
{
int L1, L2, L3, C1, C2, C3;
int n, s, e;
scanf("%d%d%d%d%d%d", &L1, &L2, &L3, &C1, &C2, &C3);
scanf("%d", &n);
scanf("%d%d", &s, &e);
if (s > e)
{
s ^= e;
e ^= s;
s ^= e;
}
for (int i = s; i <= e; i++)
{
dp[i] = 0x7fffffff;
}
dist[] = ;
for (int i = ; i <= n; i++)
{
scanf("%d", &dist[i]);
}
dp[s] = ;
for (int i = s; i < e; i++)
{
for (int j = i + ; j <= e; j++)
{
if (dist[j] - dist[i] <= L1 && dp[j] > dp[i] + C1)
{
dp[j] = dp[i] + C1;
}
if (dist[j] - dist[i] <= L2 && dp[j] > dp[i] + C2)
{
dp[j] = dp[i] + C2;
}
if (dist[j] - dist[i] <= L3 && dp[j] > dp[i] + C3)
{
dp[j] = dp[i] + C3;
}
}
}
printf("%d\n", dp[e]);
return ;
}
POJ 2355 Railway tickets的更多相关文章
- poj 2828 Buy Tickets (线段树(排队插入后输出序列))
http://poj.org/problem?id=2828 Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissio ...
- poj 2828 Buy Tickets 树状数组
Buy Tickets Description Railway tickets were difficult to buy around the Lunar New Year in China, so ...
- poj 2828 Buy Tickets (线段树 单节点 查询位置更新)
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 15533 Accepted: 7759 Desc ...
- POJ 2828 Buy Tickets(线段树 树状数组/单点更新)
题目链接: 传送门 Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Description Railway tickets were d ...
- POJ 2828 Buy Tickets
Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...
- poj 2828 Buy Tickets【线段树单点更新】【逆序输入】
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 16273 Accepted: 8098 Desc ...
- 线段树(倒序操作):POJ 2828 Buy Tickets
Buy Tickets Description Railway tickets were difficult to buy around the Lunar New Year in China, ...
- POJ 2828 Buy Tickets(排队问题,线段树应用)
POJ 2828 Buy Tickets(排队问题,线段树应用) ACM 题目地址:POJ 2828 Buy Tickets 题意: 排队买票时候插队. 给出一些数对,分别代表某个人的想要插入的位 ...
- POJ - 2828 Buy Tickets (段树单点更新)
Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...
随机推荐
- SAP ERP和C4C Account和Contact的双向同步
Account和Contact是C4C里唯一支持可以和ERP进行双向同步的主数据类别. C4C里创建一个Account:Mouser Electronics 在C4C里保存Account,自动同步到E ...
- Lua与游戏的不解之缘
本文转载自秦元培博客:blog.csdn.net/qinyuanpei 一.什么是Lua? Lua 是一个小巧的脚本语言,巴西里约热内卢天主教大学里的一个研究小组于1993年开发,其设计目的是为了嵌入 ...
- GPnP profile内容
<?xml version="1.0" encoding="UTF-8"?> <gpnp:GPnP-Profile Version=&quo ...
- UVA12906 Maximum Score (组合)
对于每个元素,最理想的情况就是都在它的左边或者右边,那么sort一下就可以得到一个特解了,然后大的中间不能有小的元素,因为如果有的话,那么无论选小的还是选大的都不是最优.对小的元素来说,比它大的元素在 ...
- React组件间通信
众所周知,ReactJS组件与组件之间的通信是一个难点.在React实际开发中,父子组件之间的传值是比较常见的,刚入门的小伙伴很容易被组件之间的通信绕懵. 今天花了点时间总结了一下React父子组件之 ...
- JavaScript -- 内置对象字符串
charAt和charCodeAt charAt语法: stringObject.charAt(index) 功能: 返回stringObject中index位置的字符. charCodeAt语法 s ...
- $|^|\z|\Z|/a|/l
#!/usr/bin/perl use strict; use warnings; foreach(<>) { if (/(\w*)/a){print "$1\n";} ...
- java,编写一个从1循环到150并在每行打印一个值,另外在每个3的倍数行上打印出foo,在每个5的倍数行上打印biz,在每个7的倍数上打印baz.
需求:编写一个从1循环到150并在每行打印一个值,另外在每个3的倍数行上打印出foo,在每个5的倍数行上打印biz,在每个7的倍数上打印baz. package study01; public cla ...
- [vijos]P1514 天才的记忆
背景 神仙飞啊飞 描述 从前有个人名叫W and N and B,他有着天才般的记忆力,他珍藏了许多许多的宝藏.在他离世之后留给后人一个难题(专门考验记忆力的啊!),如果谁能轻松回答出这个问题,便可以 ...
- Golang 简单静态web服务器
直接使用 net.http 包,非常方便 // staticWeb package main import ( "fmt" "net/http" "s ...