题目链接:http://codeforces.com/problemset/problem/355/B

题目意思:给出四种票种,c1: 某一部bus或者trolley的单程票(暗含只可以乘坐一次);c2、c3、c4乘坐次数没有限制。c2:某一部bus或者trolley可以乘坐无限次;c3:所有的bus或者trolley可以乘坐无限次;c4:所有的bus和trolley可以乘坐无限次。根据给出的n buses 和m trolleys 每一辆的乘坐次数,找出最便宜的买票方式,输出要花费的金额。

对于每一部bus或者trolley,无非从c1或者c2选择。这里以选择某一个序号为 i 的bus的票为例。选择c2的条件是:(ai * c1) >  c2(加多个“=”也可以),否则选择c1。为所有的bus买完票后(每一个选择都符合局部最优的,贪心的核心思想啊~~),统计这个和,再与c3比较,得到不考虑买c4这种票的情况下,对所有bus来说最好的买票和。(有可能买一张所有bus都可以乘坐无限次的票比这个和还要便宜的!)trolley的买票选择也类似。也得到一个撇开c4,对所有trolley来说的最好买票和。把这两个和相加,再与c4比较,哪个较小即是答案。

 #include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std; #define max(x, y) ((x) < (y) ? (x) : (y)) // 比较两个数的较小值 const int maxn = + ;
int a[maxn], b[maxn]; int main()
{
int c1, c2, c3, c4, n, m, i;
while (scanf("%d%d%d%d", &c1, &c2, &c3, &c4) != EOF)
{
scanf("%d%d", &n, &m);
for (i = ; i < n; i++)
scanf("%d", &a[i]); // buses
for (i = ; i< m; i++)
scanf("%d", &b[i]); // trolleys
int sum1, sum2, max1, max2;
sum1 = sum2 = ;
for (i = ; i < n; i++)
{
if (a[i] * c1 <= c2)   // 买第一种票比第二种票便宜
sum1 += a[i] * c1;
else
sum1 += c2;
}
for (i = ; i < m; i++)
{
if (b[i] * c1 <= c2)
sum2 += b[i] * c1;
else
sum2 += c2;
}
max1 = max(sum1, c3);  // 组合了第一和第二种票的买票方式后,与买第三种票(所有bus乘坐次数无限制)作比较,求得较小值
max2 = max(sum2, c3);
max1 += max2;  // 在不考虑买第四种票的情况下buses和trolleys买票的最优值
int maxsum = max(max1, c4); // 有可能买所有的bus和trolley的无限制搭乘次数的票(c4)比之前求得的最优值还好
printf("%d\n", maxsum);
}
return ;
}

codeforces B. Vasya and Public Transport 解题报告的更多相关文章

  1. codeforces A. Vasya and Digital Root 解题报告

    题目链接:http://codeforces.com/problemset/problem/355/A 题目意思:找出某个经过最多四次dr(n)操作等于d的k位数.   千万不要想得太复杂,想得越简单 ...

  2. codeforces C1. The Great Julya Calendar 解题报告

    题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...

  3. codeforces B. Eugeny and Play List 解题报告

    题目链接:http://codeforces.com/problemset/problem/302/B 题目意思:给出两个整数n和m,接下来n行给出n首歌分别的奏唱时间和听的次数,紧跟着给出m个时刻, ...

  4. codeforces 433C. Ryouko's Memory Note 解题报告

    题目链接:http://codeforces.com/problemset/problem/433/C 题目意思:一本书有 n 页,每页的编号依次从 1 到 n 编排.如果从页 x 翻到页 y,那么| ...

  5. Codeforces Round 319 # div.1 & 2 解题报告

    Div. 2 Multiplication Table (577A) 题意: 给定n行n列的方阵,第i行第j列的数就是i*j,问有多少个格子上的数恰为x. 1<=n<=10^5, 1< ...

  6. codeforces 556B. Case of Fake Numbers 解题报告

    题目链接:http://codeforces.com/problemset/problem/556/B 题目意思:给出 n 个齿轮,每个齿轮有 n 个 teeth,逆时针排列,编号为0 ~ n-1.每 ...

  7. codeforces 510B. Fox And Two Dots 解题报告

    题目链接:http://codeforces.com/problemset/problem/510/B 题目意思:给出 n 行 m 列只有大写字母组成的字符串.问具有相同字母的能否组成一个环. 很容易 ...

  8. codeforces 505A. Mr. Kitayuta's Gift 解题报告

    题目链接:http://codeforces.com/problemset/problem/505/A 题目意思:给出一个长度不大于10的小写英文字符串 s,问是否能通过在字符串的某个位置插入一个字母 ...

  9. codeforces 499A.Inna and Pink Pony 解题报告

    题目链接:http://codeforces.com/problemset/problem/499/A 题目意思:有两种按钮:1.如果当前观看的时间是 t,player 可以自动处理下一分钟,姑且理解 ...

随机推荐

  1. POJ1089 Intervals

    Description There is given the series of n closed intervals [ai; bi], where i=1,2,...,n. The sum of ...

  2. BZOJ3172 后缀数组

    题意:求出一篇文章中每个单词的出现次数 对样例的解释: 原文是这样的: a aa aaa 注意每个单词后都会换行 所以a出现次数为6,aa为3 (aa中一次,aaa中两次),aaa为1 标准解法好像是 ...

  3. poj1787Charlie's Change(多重背包+记录路径+好题)

    Charlie's Change Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3720   Accepted: 1125 ...

  4. POJ1703Find them, Catch them

    Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37722   Accepted: ...

  5. Laravel教程 三:视图变量传递和Blade

    Laravel教程 三:视图变量传递和Blade 此文章为原创文章,未经同意,禁止转载. Blade 上一篇我们简单地说了Router,Views和Controllers的工作流程,这一次我就按照上一 ...

  6. spring mvc文件上传和下载

    首先要导入2个包(上传文件包和io的包)

  7. java随机生成简体中文取指定长度随机简体中文实用方法

    /**     * 获取指定长度随机简体中文     * @param len int     * @return String     */    public static String getR ...

  8. 微信内置浏览器的 User Agent的判断

    如何判断微信内置浏览器,首先需要获取微信内置浏览器的User Agent,经过在 iPhone 上微信的浏览器的检测,它的 User Agent 是: Mozilla/5.0 (iPhone; CPU ...

  9. detours安装和使用

    http://blog.csdn.net/evi10r/article/details/6659354 http://blog.csdn.net/donglinshengan/article/deta ...

  10. unity3d的四元数 Quaternion

    原地址:http://www.cnblogs.com/88999660/archive/2013/04/02/2995074.html 今天准备学习和研究下unity3d的四元数 Quaternion ...