题意:有N项工作,每项工作完成需要n天,如果不开始做每天罚fee,开始做即不罚钱,求任务的执行顺序,使得罚钱最少.如果有多组答案,取下标排列最小的那组

解题思路:

考虑工作tn(dn,fn) ,

假如先做工作tj,  0<j<n,0<i<n,那么罚的钱是 dj*f0+dj*f1+.....dj*fn+dj*fi = totalj1,

在做工作ti,  di*f0+di*f1+....di*fn = totalj2,   totalj1 + totalj2 = (di+dj)*fo + (di+dj)*f1 +....(di+dj)fn + (dj*fi)

假如先做工作ti,0<i<n,那么罚的钱是 di*f0+di*f1+....di*fn+di*fj = totali1,

再做tj,dj*f0+dj*f1+.....dj*fn=totali2,   totali1+totali2 = (di+dj)*fo + (di+dj)*f1 +....(di+dj)fn +(di*fj)

差别就是di*fj和dj*fi

#include <algorithm>
#include <iostream> namespace cc
{
using std::cin;
using std::cout;
using std::endl;
using std::move;
using std::qsort;
const int N = ;
class Node
{
public:
int fee;
int day;
int index;
Node(int fee, int day, int index) : day(day), fee(fee), index(index)
{
}
Node() = default;
}; int cmp(const void *a, const void *b)
{
Node *n1 = (Node *)(a);
Node *n2 = (Node *)(b);
int total1 = n1->fee * n2->day;
int total2 = n2->fee * n1->day;
if (total1 == total2)
{
return n1->index - n2->index;
}
if (total1 < total2)
return ;
return -;
} void solve()
{
int n;
cin >> n;
int t = ;
while (n--)
{
if(t!=)
cout<<endl;
++t;
int k;
cin >> k;
int fee, day;
int total = ;
Node nodes[N];
for (int i = ; i < k; i++)
{
cin >> day >> fee;
Node node(fee, day, i + );
nodes[total++] = node;
}
qsort(nodes, total, sizeof(Node), cmp); cout << nodes[].index;
for (int i = ; i < total; i++)
cout << " " << nodes[i].index;
cout << endl;
}
} } // namespace cc int main()
{
#ifndef ONLINE_JUDGE
freopen("/Users/caicai/in", "r", stdin);
#endif // !ONLINE_JUDGE cc::solve();
return ;
}

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

  1. UVA 10026 Shoemaker's Problem 鞋匠的难题 贪心+排序

    题意:鞋匠一口气接到了不少生意,但是做鞋需要时间,鞋匠只能一双一双地做,根据协议每笔生意如果拖延了要罚钱. 给出每笔生意需要的天数和每天的罚钱数,求出最小罚钱的排列顺序. 只要按罚款/天数去从大到小排 ...

  2. (贪心5.2.1)UVA 10026 Shoemaker's Problem(利用数据有序化来进行贪心选择)

    /* * UVA_10026.cpp * * Created on: 2013年10月10日 * Author: Administrator */ #include <iostream> ...

  3. uva 10026 Shoemaker's Problem _贪心

    题意:鞋匠现在有n个工作要做,每个工作要x天,没延迟一天需要付款y,鞋匠每天只能做一个工作,问使得鞋匠最少赔款的工作顺序. 思路:工作和工作之间排序,如果a.value*b.day>b.valu ...

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

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

  5. UVA 11389(贪心问题)

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

  6. uva 10154 贪心+dp

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

  7. uva 10026 Shoemaker's Problem

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

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

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

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

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

  10. uva 10026 Problem C: Edit Step Ladders

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

随机推荐

  1. Linux磁盘监控工具说明

    1.1 iostat 系统systat包里的工具,以kB/s为单位统计,2表示以2秒为频率统计一次:iostat –x –k 2 10000 rrqm/s:每秒这个设备相关的读取请求有多少被Merge ...

  2. Delphi 与 C/C++ 数据类型对照表

    Delphi 数据类型 C/C++ ShorInt 8位有符号整数 char Byte 8位无符号整数 BYTE,unsigned short SmallInt 16位有符号整数 short Word ...

  3. IDEA运行tomcat8.5.35源代码

    前提环境,安装和配置好java1.8+环境,maven,IDEA 1.下载Tomcat源代码:https://tomcat.apache.org/download-80.cgi#8.5.35 2.创建 ...

  4. nginx 隐藏 index.php

    使用情景如下: 在访问 http://php.cc/Att/AttList 的时候.跳转到 http://php.cc/index.php/Att/AttList : 也就是开启重写功能: 在ngin ...

  5. 【springBoot】之定制Banner

    springboot启动时控制台打印图案如下: 1.假如我们不想看到这个图案 public static void main(String[] args) { SpringApplication ap ...

  6. PAT 乙级 1062 最简分数(20) C++版

    1062. 最简分数(20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 一个分数一般写成两个整数相除的形式: ...

  7. python 判断返回结果 in用法

    AA=data[0]["content"] if U"已签收" in AA:(判断 AA里面有没有包含 "已签收的字样") print &q ...

  8. 服务链路追踪(Spring Cloud Sleuth)

    sleuth:英 [slu:θ] 美 [sluθ] n.足迹,警犬,侦探vi.做侦探 微服务架构是一个分布式架构,它按业务划分服务单元,一个分布式系统往往有很多个服务单元.由于服务单元数量众多,业务的 ...

  9. typescript接口扩展、接口的继承

    //接口扩展:接口可以继承接口 // interface Animal{ // eat():void; // } // interface Person extends Animal{ // work ...

  10. 十三篇系列:king转折点,wooga瓶颈,supercell营收结构

    转自:http://gamerboom.com/archives/95125 十三篇系列:king的历史转折点,wooga的瓶颈,supercell的营收结构 第一篇 这句话In other word ...