Codeforces Round #222 (Div. 1)B:http://codeforces.com/contest/377/problem/B
题意:m个任务,每个任务会有一个复杂度,然后给你n个人,每个人会有一个能力值,一个任务只有被能力值不少于它的人所完成。并且每个人完成任务会有一个费用,这个费用是固定,不论完成多少任务,只要付一次,一个任务只由一个人完成,一个人可以完成多个任务,但是每个人每天只能完成一个任务,现在给以一个总的费用,让你找出在不超过总费用的情况下,去完成这m个任务,并且要求时间短。
题解:想到了贪心,但是没想到要二分天数。最多需要m天去完成,这是显然的,这是在能够完成的前提下。还是那句话,二分一定要有线性关系,这里的线性关系就是,天数越多,任务被完成的可能性越大。对于t天来说,对于任务中复杂度最高的那个任务来说,应该找一个能力水平不小于它,并且费用最少的那个人来完成,这样的费用一定是最少的,那个人花了1天完成了那个任务之后,对于其他任务来说,它肯定是可以完成的,而且他完成后面的任务都是不需要费用的,所以再让他完成t-1个任务。只花了一个任务钱,对于前面的任务来说,要想完成,又要找一个人,让他来完成,重复上面的,直到所有的任务都被完成。实现的时候,可以用一个优先队列来存,然后任务按复杂度从小到大的顺序排序,人按照能力值从小到大排序。然后每一次选择一个当前最复杂的那个任务,把所有比它大=的人都放进队列,然后选择一个最小,去完成前t个任务,然后不断重复,不断二分,最后得到答案。
 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int N=1e5+;
struct Node{
int val;
int id;
bool operator<(const Node a)const{
return val<a.val;
}
}task[N];
struct Edge{
int b;
int c;
int id;
bool operator<(const Edge a)const{
return b<a.b;
}
}stu[N];
struct result{
int id;
int cost;
bool operator<(const result a)const{
return cost>a.cost;
}
};
int ans[N],temp[N];
int n,m,s;
bool judge(int t){
int len=m,p=n,tp=s;
priority_queue<result>Q;
while(len>=){
while(p>=&&stu[p].b>=task[len].val){
result aaa;
aaa.cost=stu[p].c;
aaa.id=stu[p].id;
Q.push(aaa);
p--;
}
if(Q.size()==)return false;
result ta=Q.top();
Q.pop();
tp-=ta.cost;
if(tp<)return false;
for(int i=max(,len-t);i<=len;i++)
ans[task[i].id]=ta.id;
len-=t;
}
for(int i=;i<=m;i++)
temp[i]=ans[i];
return true;
}
int main(){
while(~scanf("%d%d%d",&n,&m,&s)){
for(int i=;i<=m;i++){
scanf("%d",&task[i].val);
task[i].id=i;
}
for(int i=;i<=n;i++)
scanf("%d",&stu[i].b);
for(int i=;i<=n;i++){
scanf("%d",&stu[i].c);
stu[i].id=i;
}
sort(task+,task+m+);
sort(stu+,stu+n+);
int minn=-,l=,r=m;
while(l<=r){
int mid=(l+r)/;
if(judge(mid)){
r=mid-;
minn=mid;
}
else l=mid+;
}
if(minn==-)printf("NO\n");
else{
printf("YES\n");
for(int i=;i<=m;i++){
printf("%d ",temp[i]);
}
printf("\n");
}
}
}

Preparing for the Contest的更多相关文章

  1. Codeforces Round #222 (Div. 1) B. Preparing for the Contest 二分+线段树

    B. Preparing for the Contest 题目连接: http://codeforces.com/contest/377/problem/B Description Soon ther ...

  2. 【CF】222 Div.1 B Preparing for the Contest

    这样类似的题目不少,很多都是一堆优化条件求最优解,这个题的策略就是二分+贪心.对时间二分, 对费用采用贪心. /* 377B */ #include <iostream> #include ...

  3. codeforces 377B Preparing for the Contest 二分+优先队列

    题目链接 给你m个bug, 每个bug都有一个复杂度.n个人, 每个人有两个值, 一个是能力值, 当能力值>=bug的复杂度时才可以修复这个bug, 另一个是雇佣他需要的钱,掏一次钱就可以永久雇 ...

  4. CodeForces 377B---Preparing for the Contest(二分+贪心)

    C - Preparing for the Contest Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d ...

  5. POJ3967Ideal Path[反向bfs 层次图]

    Ideal Path Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 1754   Accepted: 240 Descri ...

  6. Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉

    Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  7. uav 11258 String Partition (DP)

    Problem F - String Partition                                                                         ...

  8. UVA1599-Ideal Path(BFS进阶)

    Problem UVA1599-Ideal Path Time Limit: 3000 mSec Problem Description New labyrinth attraction is ope ...

  9. Codeforces Round #222 (Div. 1) (ABCDE)

    377A Maze 大意: 给定棋盘, 保证初始所有白格连通, 求将$k$个白格变为黑格, 使得白格仍然连通. $dfs$回溯时删除即可. #include <iostream> #inc ...

随机推荐

  1. iOS IAP教程

    1. 创建应用 首先进入iTunes Connect然后按下 Manage Your Applications 接下来按下Add New Applicationbutton创建应用 2. 在应用中创建 ...

  2. C++实现二叉树(转)

    /************************************************************************* 这是一个二叉查找树,实现了以下操作:插入结点.构造 ...

  3. div css背景图片不显示

    我们在写页面时,为了便于维护,css样式通常都是通过link外部导入html的,有时在css中写入背景图片时,此时背景图片的路径应该是相对css文件的.比如,此时的文件有index.html,css. ...

  4. iOS UIKit:viewController之Present (3)

    弹出和转换view controller技术是一种快速且简单的方式将新view content展示在屏幕中.目前有两种方式弹出新的view controller:Present方式和segues方式. ...

  5. Axiom3D学习日记 3.Cameras, Lights, and Shadows

    Camera 相机: 相机基础知识不写了,需要注意的是:axiom目前不支持同时操作多个相机. 创建,设置位置基本操作. _camera = _scene.CreateCamera("Mai ...

  6. WPF Paragraph获取或修改文本内容

    一.说明 Paragraph继承自Block,Block继承自TextElement,在TextElement中 // // 摘要: // 获取表示元素中内容末尾的 System.Windows.Do ...

  7. Web Service属性介绍

    每个 Web Service都需要唯一的命名空间,它可使客户端应用程序区分出可能使用相同方法名称的 Web Service.在 Visual Studio.NET中创建的Web Service的默认命 ...

  8. 由App的启动说起(转)

    The two most important days in your life are the day you are born and the day you find out why. -- M ...

  9. hdoj 1060

    代码: #include <stdio.h>#include <math.h> int main(){    int t;    while(scanf("%d&qu ...

  10. 【模板】【网络流】Dinic

    /* 唐代杜荀鹤 <小松> 自小刺头深草里,而今渐觉出蓬蒿. 时人不识凌云木,直待凌云始道高. */ #include <iostream> #include <cstd ...