Problem - 1789

  继续贪心。经典贪心算法,如果数据比较大就要用线段树来维护了。

  思路很简单,只要按照代价由大到小排序,然后靠后插入即可。RE了一次,是没想到deadline可以很大。如果deadline比任务总量要大,显然这个任务是能做的,直接加上去。

代码如下:

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector> using namespace std; typedef pair<int, int> PII;
typedef vector<PII> VPII; VPII rec;
vector<bool> vis; inline bool cmp(PII a, PII b) { return a > b;}
int insert(PII x, int n) {
int t = x.second;
if (t >= n) return x.first;
while (t > && vis[t]) t--;
vis[t] = true;
// cout << "~~~ " << t << endl;
return t ? x.first : ;
} int main() {
int T, n;
cin >> T;
while (T-- && cin >> n) {
int x;
rec.clear();
vis = vector<bool>(n + , false);
for (int i = ; i < n; i++) {
cin >> x;
rec.push_back(PII(, x));
}
int sum = ;
for (int i = ; i < n; i++) {
cin >> rec[i].first;
sum += rec[i].first;
}
sort(rec.begin(), rec.end(), cmp);
int ans = ;
for (int i = ; i < n; i++) ans += insert(rec[i], n);
cout << sum - ans << endl;
}
return ;
}

——written by Lyon

hdu 1789 Doing Homework again (Greedy)的更多相关文章

  1. hdu 1789 Doing HomeWork Again (贪心算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 /*Doing Homework again Time Limit: 1000/1000 MS ...

  2. HDU 1789 Doing Homework again (贪心)

    Doing Homework again http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has ...

  3. HDU 1789 - Doing Homework again - [贪心+优先队列]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...

  4. HDU 1789 Doing Homework again(非常经典的贪心)

    Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  5. 题解报告:hdu 1789 Doing Homework again(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has just come back ...

  6. HDU 1789 Doing Homework again(贪心)

    Doing Homework again 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...

  7. HDU 1789 Doing Homework again(贪心)

    在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案 ...

  8. HDU 1789 Doing Homework again(馋)

    意甲冠军  参加大ACM竞争是非常回落乔布斯  每一个工作都有截止日期   未完成必要的期限结束的期限内扣除相应的积分   求点扣除的最低数量 把全部作业按扣分大小从大到小排序  然后就贪阿  能完毕 ...

  9. HDU 1789 Doing Homework again(排序,DP)

    Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

随机推荐

  1. java根据list中的对象某个属性排序

    1. Collections.sort public class Test { public static void main(String[] args) throws Exception { Ci ...

  2. UvaLive1347

    Programming contests became so popular in the year 2397 that the governor of New Earck — the largest ...

  3. java简单jdbc查询操作

    所采用的mysql的数据库驱动版本:5.0.8 mysql-connector-java-5.0.8-bin.jar 程序结构图: 表结构: 创表sql: Create Table CREATE TA ...

  4. oracle-DML-2

    1.update 语句 update  table set  [column,column......] where  column ='' 示例: update   customers set   ...

  5. simple 单例

    Message* Message::m_pInstance = ;//类外初始 Message::Message() { } Message::~Message() { ) { delete Inst ...

  6. (转载)http压缩 Content-Encoding: gzip

    (内容转自http://liuviphui.blog.163.com/blog/static/20227308420141843933379/) HTTP内容编码和HTTP压缩的区别 HTTP压缩,在 ...

  7. webpack学习之——Entry Points(入口起点)

    1.Entry property(entry属性) 1.1 Single Entry (Shorthand) Syntax(单个入口语法) 用法:entry: string | Array<st ...

  8. C# 模拟POST上传图片

    做到一个上传图片的需求,网页已经可以了,模拟网页在客户端上传图片,试了很多次都没成功, 最后发现是少了一个换行符,而且是网页上的字符全部一字不漏的转换成文件流,上传. 先看下网页下的完整请求: 前面这 ...

  9. 洛谷 P1567 统计天数【最长上升子序列/断则归一】

    题目背景 统计天数 题目描述 炎热的夏日,KC非常的不爽.他宁可忍受北极的寒冷,也不愿忍受厦门的夏天.最近,他开始研究天气的变化.他希望用研究的结果预测未来的天气. 经历千辛万苦,他收集了连续N(1& ...

  10. 如何在Data Lake Analytics中使用临时表

    前言 Data Lake Analytics (后文简称DLA)是阿里云重磅推出的一款用于大数据分析的产品,可以对存储在OSS,OTS上的数据进行查询分析.相较于传统的数据分析产品,用户无需将数据重新 ...