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(贪心)
在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案 ...
随机推荐
- jQuery星级评分插件
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta http-equiv="Con ...
- 去掉CI框架默认url中的index.php
1:.htaccess //放置在根目录下,和入口文件index.php的同级目录<IfModule mod_rewrite.c>RewriteEngine onRewriteCond % ...
- 【LeetCode】327. Count of Range Sum
题目: Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusiv ...
- 读RCNN论文笔记
1. RCNN的模型(如下图)描述: RCNN相比传统的物体检测,还是引入传统的物体检测的基本流程,先找出候选目标物体,逐个的提取特征,不过rbg大神引入了当时炙手可热的CNN卷积网络取代传统上的HO ...
- Linux用户管理-中
添加用户组命令groupadd 提示:groupadd命令的使用非常简单,但在生产环境中使用的不多,因此,会简单应用即可. 与groupadd命令有关的文件有:/etc/group :用户组相关文件/ ...
- Ext常用开发基础知识
Ext常用开发基础知识 组件定义 //这种方法可以缓存所需要的组件 调用起来比较方便(方法一 ) Ext.define('MySecurity.view.home.HomePanel', { //添加 ...
- 【SqlServer系列】表单查询
1 概述 如下几个问题,如果你能解决,请继续往下看,若不能解决,请先复习SQL基础知识,再来阅读本篇文章.本篇文章深度中等左右. Q1:表StudentScores如下,用一条SQL语句查询出每门 ...
- QTCreator 更改代码高亮主题为 VS+VA助手 风格
VS Dark-VA 主题下载地址 链接:http://pan.baidu.com/s/1jIOeZxc 密码:2gp2 另外还有喜欢 solarized 配色的也可以从这里下载 https ...
- codeforces 129B students and shoes
https://vjudge.net/problem/CodeForces-129B 题意: 有n个学生,他们之间被鞋带缠住了.现在,老师首先把所有只与一个学生直接相连的学生找出来,让他们聚集到一起, ...
- java三大框架介绍
常听人提起三大框架,关于三大框架,做了如下了解: 三大框架:Struts+Hibernate+Spring java三大框架主要用来做WEN应用. Struts主要负责表示层的显示 Spring利用它 ...