题意:从N开始,目标是把数字变成M,每个代理有俩个操作,让数字减一或者变成一半,求最小的花费

能减半就减半.

#include <string>
#include<iostream>
#include<map>
#include<memory.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<math.h>
#include<iomanip>
#include<bitset>
#include"math.h"
namespace cc
{
using std::cout;
using std::endl;
using std::cin;
using std::map;
using std::vector;
using std::string;
using std::sort;
using std::priority_queue;
using std::greater;
using std::vector;
using std::swap;
using std::stack;
using std::bitset; class Input
{
public:
char* name;
int a=0;
int b=0;
int cost=0;
Input() {
name = new char[50];
};
}; constexpr int L = 110; Input ins[L]; bool cmp(Input& a, Input& b)
{
if (a.cost < b.cost)
return true;
if (a.cost > b.cost)
return false;
return strcmp(a.name, b.name) < 0;
}
void solve2(int LL, int N, int M)
{
for (int i = 0;i < LL;i++)
{
//计算花费
int h = N;
while (h/2 >= M && (h - h/2) * ins[i].a >= ins[i].b)
{
ins[i].cost += ins[i].b;
h = h / 2; }
if (h > M)
ins[i].cost += (h - M) * ins[i].a; } sort(ins, ins + LL, cmp);
for (int i = 0;i < LL;i++)
cout << ins[i].name << " " << ins[i].cost << endl;
} void solve()
{
int cases;
cin >> cases;
int t = 1;
while (cases--)
{
int N, M, LL;
cin >> N >> M >> LL;
for (int j = 0;j < LL;j++)
{
char* strs = new char[100];
cin >> strs;
Input inss;
sscanf(strs, "%[^:]:%d,%d", inss.name, &inss.a, &inss.b);
ins[j] = inss;
}
cout << "Case " << t << endl;
t++;
solve2(LL, N, M); } } }; int main()
{ #ifndef ONLINE_JUDGE
freopen("d://1.text", "r", stdin);
#endif // !ONLINE_JUDGE
cc::solve(); return 0;
}

  

uva-10670-贪心的更多相关文章

  1. uva 10670 Work Reduction(贪心)

    题目连接:10670 - Work Reduction 题目大意:有tol的工作量,和要求达到的工作剩余量sur,然后是公司总数,对应每个公司提供两种服务,1.完成一个工作量,2.完成当前未完成工作量 ...

  2. 01_传说中的车(Fabled Rooks UVa 11134 贪心问题)

    问题来源:刘汝佳<算法竞赛入门经典--训练指南> P81: 问题描述:你的任务是在n*n(1<=n<=5000)的棋盘上放n辆车,使得任意两辆车不相互攻击,且第i辆车在一个给定 ...

  3. UVA 11389(贪心问题)

    UVA 11389 Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description II  ...

  4. uva 10154 贪心+dp

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  5. UVa 11389 (贪心) The Bus Driver Problem

    题意: 有司机,下午路线,晚上路线各n个.给每个司机恰好分配一个下午路线和晚上路线. 给出行驶每条路线的时间,如果司机开车时间超过d,则要付加班费d×r. 问如何分配路线才能使加班费最少. 分析: 感 ...

  6. UVa 1467 (贪心+暴力) Installations

    题意: 一共有n项服务,每项服务有安装的时间s和截止时间d.对于每项任务,如果有一项超出截止时间,惩罚值为所超出时间的长度.问如何安装才能使惩罚值最大的两个任务的惩罚值之和最小. 分析: 如果是求总惩 ...

  7. UVa 10670 - Work Reduction

    题目大意:对n份文件进行处理使其减少到m份,有l个机构可供选择.每个机构提供两种方案:每减少一份收费a元,或者减少到文件数量的一半收费b元.根据各个机构收取费用进行排序. 很直接的题目,直接进行模拟就 ...

  8. Party Games UVA - 1610 贪心

    题目:题目链接 思路:排序后处理到第一个不同的字符,贪心一下就可以了 AC代码: #include <iostream> #include <cstdio> #include ...

  9. UVa 1149 (贪心) Bin Packing

    首先对物品按重量从小到大排序排序. 因为每个背包最多装两个物品,所以直觉上是最轻的和最重的放一起最节省空间. 考虑最轻的物品i和最重的物品j,如果ij可以放在一个包里那就放在一起. 否则的话,j只能自 ...

  10. UVA 10037 贪心算法

    题目链接:http://acm.hust.edu.cn/vjudge/contest/122829#problem/A 题目大意:N个人夜里过河,总共只有一盏灯,每次最多过两个人,然后需要有人将灯送回 ...

随机推荐

  1. xenserver挂载新硬盘

    注意:新加硬盘请不要加入raid,否则不认盘 一: 1.1:查看磁盘列表 fdisk -l [root@xenserver zz]# fdisk -l Disk /dev/sdb: 7999.4 GB ...

  2. Problem B: 类的初体验(II)

    Description 定义一个类Data,只有一个double类型的属性和如下3个方法: 1.   带1个参数的构造函数——初始化属性值为参数值. 2.   double getValue()——获 ...

  3. winfrom 关闭别的应用程序的窗体或者弹出框(winform 关闭句柄)

    在word转换成html的时候,由于系统版本不一样,office总是抛出异常,Microsoft Word停止工作,下面有三个按钮,关闭程序等等,但是我的转换工作需要自动的,每当抛出异常的时候我的程序 ...

  4. Locust 参数化

    概述: 和Loadrunner一样对于多用户并发时,重复登入或者数据的重复使用会造成脚本的失败,那么我们引入Loadrunner的参数化概念,对用户数据进行参数化来使脚本运行成功. 头绪:   use ...

  5. ChIP-seq motif ROC 相关资料

    [怪毛匠子]独家整理 不可以转载 MEME工具 http://meme-suite.org DNA motif 搜索算法总结 http://www.bbioo.com/lifesciences/40- ...

  6. 读取Excel表格中数据原型

    写下这篇博客来记录自己的工作,这部分功能是读取Excel表格中的数据,并通过c#中的datagridview控件将读取的数据显示出来.为了方便用户,我设计了一个read按钮,用户点击这个按钮,会弹出打 ...

  7. [LeetCode&Python] Problem 257. Binary Tree Paths

    Given a binary tree, return all root-to-leaf paths. Note: A leaf is a node with no children. Example ...

  8. PAT 乙级 1089 狼人杀 && 1090 危险品装箱 (我的时间最短哦)

    1 1089的点在注释里面,核心就是遍历任意两个人说谎,看结果是否满足题目要求 2  1090 是一道好题目, 考虑到了时间复杂度 通常想法是看清单中每一个物品 是否存在与其不能存放的物品  那么复杂 ...

  9. [ Codeforces Round #549 (Div. 2)][D. The Beatles][exgcd]

    https://codeforces.com/contest/1143/problem/D D. The Beatles time limit per test 1 second memory lim ...

  10. PythonStudy——函数嵌套定义 Function nesting definition

    # 在一个函数内部定义另一个函数 # 函数对象(变量)与普通对象(变量)一样,在函数内部定义,随函数调用而产生, # 调用结束而销毁,所以只能在函数内部调用 def outer(): print('o ...