hdu--1798--Doing Homework again(贪心)
Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13847 Accepted Submission(s): 8036
Each test case start with a positive integer N(1<=N<=1000) which indicate the number of homework.. Then 2 lines follow. The first line contains N integers that indicate the deadlines of the subjects, and the next line contains N integers that indicate the reduced scores.
/* Name: hdu--1798--Doing Homework again Copyright: 2017 日天大帝 Author: 日天大帝 Date: 21/04/17 15:32 Description: 贪心,思路让当前分数大的替换当前分数小的作业 */ #include<iostream> #include<queue> #include<cstring> #include<algorithm> using namespace std; struct work{ int score,deadline; bool operator<(const work &a)const{ return score>a.score; } }arr[]; bool cmp(work a,work b){ return a.deadline<b.deadline; } priority_queue<work> q;//按照分数排序 int main(){ ios::sync_with_stdio(false); int T;cin>>T; while(T--){ memset(arr,,sizeof(arr)); while(!q.empty())q.pop(); int n;cin>>n; ; i<n; ++i)cin>>arr[i].deadline; ; i<n; ++i)cin>>arr[i].score; ,ans = ; sort(arr,arr+n,cmp);//按照时间排序 ; i<n; ++i){ q.push(arr[i]); if(t < arr[i].deadline){ t++;continue; } ans += q.top().score; q.pop(); } cout<<ans<<endl; } ; }
/*大神的代码,优先队列和排序很巧妙*/ #include <cstdio> #include <cstring> #include <iostream> #include <string> #include <algorithm> #include <map> #include <set> #include <queue> #include <utility> #include <vector> #include <iterator> using namespace std; typedef long long ll; typedef pair<int, int> P; << ; const int INF = 0x3f3f3f3f; P arr[MAX_N]; int main() { //ios::sync_with_stdio(false); //cin.tie(NULL); //cout.tie(NULL); int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); ; i < n; ++i) scanf("%d", &arr[i].first); ; i < n; ++i) scanf("%d", &arr[i].second); sort(arr, arr + n); , day = ; priority_queue<int, vector<int>, greater<int> > pque; ; i < n; ++i) { pque.push(arr[i].second); if (day < arr[i].first) { ++day; continue; } ans += pque.top(); pque.pop(); } printf("%d\n", ans); } ; }
hdu--1798--Doing Homework again(贪心)的更多相关文章
- hdu 1789 Doing HomeWork Again (贪心算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 /*Doing Homework again Time Limit: 1000/1000 MS ...
- HDU 1789 - Doing Homework again - [贪心+优先队列]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...
- HDU 1789 Doing Homework again(贪心)
Doing Homework again 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...
- 【状态DP】 HDU 1074 Doing Homework
原题直通车:HDU 1074 Doing Homework 题意:有n门功课需要完成,每一门功课都有时间期限t.完成需要的时间d,如果完成的时间走出时间限制,就会被减 (d-t)个学分.问:按怎样 ...
- HDU 1074 Doing Homework (动态规划,位运算)
HDU 1074 Doing Homework (动态规划,位运算) Description Ignatius has just come back school from the 30th ACM/ ...
- hdu 4825 Xor Sum(trie+贪心)
hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include ...
- HDU 1789 Doing Homework again(非常经典的贪心)
Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 题解报告:hdu 1789 Doing Homework again(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has just come back ...
- HDU 1789 Doing Homework again (贪心)
Doing Homework again http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has ...
- HDU 1789 Doing Homework again(贪心)
在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案 ...
随机推荐
- js动态参数作为Object的属性取值
js动态参数作为Object的属性取值var myObj = {"a":1,"b":2};var a = 'a';myObj[a] 就可以获取到 属性a的值了
- Appcan开发笔记:结合JQuery的$.Deferred()完善批量异步发送
appcan的 uexXmlHttpMgr.send 或者 appcan.ajax无法同步请求(没有找到这个属性),只能异步,造成循环多次提交时由于延迟或网络堵塞等原因无法同步响应,导致提交顺序混乱, ...
- Python爬虫学习之爬美女图片
最近看机器学习挺火的,然后,想要借助业余时间,来学习Python,希望能为来年找一份比较好的工作. 首先,学习得要有动力,动力,从哪里来呢?肯定是从日常需求之中来.我学Python看网上介绍.能通过P ...
- nodejs模块学习: connect解析
nodejs模块学习: connect解析 nodejs 发展很快,从 npm 上面的包托管数量就可以看出来.不过从另一方面来看,也是反映了 nodejs 的基础不稳固,需要开发者创造大量的轮子来解决 ...
- 简单总结一下 XSS
你听说过XSS吗? XSS(Cross-site scripting, 跨站脚本)是一种网站应用程序的安全漏洞攻击,是代码注入的一种. 研究表明,最近几年 XSS 已经超过 "缓冲区溢出&q ...
- OJ2237第k小数题解
题目描述: 有n个数,请你找出第k小的数. 输入描述: 第一行有2个正整数n,k(n,k<=10^7)第二行有n个非负数ai(ai<=10^5) 输出描述: 输出第k小的数. 输入样例: ...
- Java异常体系简析
最近在阅读<Java编程思想>的时候看到了书中对异常的描述,结合自己阅读源码经历,谈谈自己对异常的理解.首先记住下面两句话: 除非你能解决这个异常,否则不要捕获它,如果打算记录错误消息,那 ...
- RabbitMQ系列教程之七:RabbitMQ的 C# 客户端 API 的简介
今天这篇博文是我翻译的RabbitMQ的最后一篇文章了,介绍一下RabbitMQ的C#开发的接口.好了,言归正传吧. Net/C# 客户端 API简介1.主要的命名空间,接口和类 定义核心的API的 ...
- MAC本上appium连接真机
简单介绍一下appium连接ios真机测试环境的软件安装及配置过程: 目前我用的是desktop版本的appium, 所以MAC版本必须要升级到10.12以上,Xcode版本必须要在8.0以上,否则亲 ...
- springJdbc like模糊查询,Spring namedParameterJdbcTemplate like查询
springJdbc like模糊查询,Spring namedParameterJdbcTemplate like查询, SpringJdbc命名参数like模糊查询,namedParameterJ ...