HDU 4864 (2014 Multi-University Training Contest 1 )
考试时,想到了一个很类似的方法,但是总是差那么点,就是这么点,需要不断的努力啊!!!
题解:
基本思想是贪心。
对于价值c=500*xi+2*yi,yi最大影响100*2<500,所以就是求xi总和最大。可以先对机器和任务的时间从大到小排序。从最大时间的任务开始,找出满足任务时间要求的所有机器,从中找出等级最低且满足任务等级要求的机器匹配。依次对任务寻找满足要求的机器。
这几乎是把标程复制了一遍,因为其中的STL用的实在巧妙而且准确,自己写的话确实搞不出来。
#include <cstdio> #include <iostream> #include <algorithm> #include <map> using namespace std; typedef long long LL; struct Task {int time;int level; }; Task task[100002],machine[100002]; bool cmp(Task a,Task b){if(a.time==b.time) return(a.level>b.level);else return(a.time>b.time); } int main() {int n,m;while(scanf("%d%d", &n,&m)!=EOF){for(int i=0;i<n;i++)scanf("%d%d",&machine[i].time,&machine[i].level);for(int i=0;i<m;i++)scanf("%d%d",&task[i].time,&task[i].level);sort(machine,machine+n,cmp);sort(task,task+m,cmp);int j=0,count=0;LL ans=0;map<int,int> le;for(int i=0;i<m;i++){while(j<n&&task[i].time<=machine[j].time){le[machine[j].level]++;j++;}map<int,int>::iterator it=le.lower_bound(task[i].level);if(it!=le.end()){count++;ans+=task[i].time*500+task[i].level*2;int t=it->first;le[t]--;if(le[t]==0) le.erase(t);}}printf("%d %I64d\n",count,ans);}return 0; }
刚才发现大神博客题解上可以不用STL ,直接扫一遍就行了,自己还是太弱了。
转:http://blog.csdn.net/a601025382s/article/details/38046927
#include <iostream> #include <cstdio> #include <cstring> using namespace std;#define LL __int64 const int maxn=1e5+10; struct node{int x,y; }e[maxn],f[maxn]; int c[101]; int cmp(node a,node b) {if(a.x==b.x)return a.y>b.y;return a.x>b.x; } int main() {int n,m;while(scanf("%d%d",&n,&m)!=EOF){int i,j,k,num=0;LL ans=0;for(i=0;i<n;i++)scanf("%d%d",&e[i].x,&e[i].y);for(i=0;i<m;i++)scanf("%d%d",&f[i].x,&f[i].y);sort(e,e+n,cmp);sort(f,f+m,cmp);memset(c,0,sizeof(c));for(i=0,j=0;i<m;i++){while(j<n&&e[j].x>=f[i].x){c[e[j].y]++;j++;}for(k=f[i].y;k<=100;k++){if(c[k]){num++;c[k]--;ans=ans+500*f[i].x+2*f[i].y;break;}}}printf("%d %I64d\n",num,ans);}return 0; }
转载于:https://www.cnblogs.com/Mathics/p/3866901.html
HDU 4864 (2014 Multi-University Training Contest 1 )相关推荐
- hdu 4925 Apple Tree--2014 Multi-University Training Contest 6
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others ...
- HDU 5768 Lucky7(2016 Multi-University Training Contest 4 -1005)——中国剩余定理 + 容斥原理
[传送门](http://acm.hdu.edu.cn/showproblem.php?pid=5768) Lucky7 Time Limit: 2000/1000 MS (Java/Others) ...
- Fibonacci Sum HDU - 6755【2020 Multi-University Training Contest 1】斐波那契数列变形+二项式定理
[杭电多校2020]Distinct Sub-palindromes 分析: 题目: The Fibonacci numbers are defined as below: Given three i ...
- HDU 6091 - Rikka with Match | 2017 Multi-University Training Contest 5
思路来自 某FXXL 不过复杂度咋算的.. /* HDU 6091 - Rikka with Match [ 树形DP ] | 2017 Multi-University Training Conte ...
- HDU 6051 - If the starlight never fade | 2017 Multi-University Training Contest 2
/* HDU 6051 - If the starlight never fade [ 原根,欧拉函数 ] | 2017 Multi-University Training Contest 2 题意: ...
- HDU 6058 - Kanade's sum | 2017 Multi-University Training Contest 3
/* HDU 6058 - Kanade's sum [ 思维,链表 ] | 2017 Multi-University Training Contest 3 题意:给出排列 a[N],求所有区间的第 ...
- HDU 2019 Multi-University Training Contest 1 杭电2019多校联合训练赛 第一场 1001 Blank (6578)
HDU 2019 Multi-University Training Contest 1 杭电2019暑期多校集训第一场 1001 Blank (6578) Problem Description T ...
- HDU 6638 [2019 Multi-University Training Contest 6]
Snowy Smile Problem Description There are n pirate chests buried in Byteland, labeled by 1,2,-,n. Th ...
- HDU 4864 Task(2014多校--贪心)
Task 比赛当时思路想的差不多,感觉能过的,该处理的也都处理到了,最后还是没过,可能是二分写错了吧-.- 大意:给你n个机器,m个要完成的任务,每个机器跟任务都有两个属性,机器是最大工作时间跟等级, ...
- hdu 4864 Task(贪婪啊)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 Task Time Limit: 4000/2000 MS (Java/Others) M ...
最新文章
- 软件项目经理新手上路8 - 最后期限的迷局
- 广义回归神经网络(GRNN)的数据预测
- Unable to handle kernel paging request at virtual address 问题定位
- php中的foreach如何使用?
- Arcengine 10 ecp
- 消息队列—主要消息中间件优势对比
- 话里话外:浅谈国企绩效考核问题(二)
- 数据结构-第九章 内部排序-知识点总结1
- 初一模拟赛总结(5.18)
- jquery miniui , 普加甘特图,流程管理
- gvim最简化设置,去掉工具栏和菜单栏
- 机器学习1---基本概念
- pthread线程传递数据回主线程_操作系统4:线程(1)
- 千亿级照片,毫秒间匹配最佳结果,微软开源 Bing 搜索背后的关键算法!
- C++中多线程并发介绍
- 2017年中国网络安全报告
- win10锁屏壁纸路径
- 前端图片在线转换Base64 图片编码Base64
- SSM酒店预订客房管理系统(包含数据库及项目说明)
- <Zhuuu_ZZ>大数据技术之Flume详解