这样类似的题目不少,很多都是一堆优化条件求最优解,这个题的策略就是二分+贪心。
对时间二分, 对费用采用贪心。

 /* 377B */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 typedef struct node_t {
int x, id;
node_t() {}
node_t(int x_, int id_):
x(x_), id(id_) {}
friend bool operator< (const node_t& a, const node_t& b) {
return a.x > b.x;
}
} node_t; typedef struct student {
int x, p, id;
student() {}
student(int x_, int p_, int id_):
x(x_), p(p_), id(id_) {}
friend bool operator< (const student& a, const student& b) {
return a.x > b.x;
}
} student; const int maxn = 1e5+;
int a[maxn];
int n, m, s;
node_t N[maxn];
student S[maxn]; bool comp(const student& a , const student& b) {
return a.x > b.x;
} bool judge(int t) {
priority_queue<int,vi, greater<int> > Q;
int i, j, k;
int p;
int tot = s; i = ; // i for student
j = ; // j for Q
while (j < m) {
while (i<n && S[i].x>=N[j].x) {
Q.push(S[i].p);
++i;
}
if (Q.empty())
break;
p = Q.top();
Q.pop();
if (p > tot)
return false;
tot -= p;
j += t;
} return j>=m;
} void bfs(int t) {
priority_queue<pii,vpii, greater<pii> > Q;
int i, j, k, id;
int m_; i = ; // i for student
j = ; // j for Q
while (j < m) {
while (i<n && S[i].x>=N[j].x) {
Q.push(mp(S[i].p, S[i].id));
++i;
}
id = Q.top().sec;
Q.pop();
m_ = min(m, j+t);
for (k=j; k<m_; ++k)
a[N[k].id] = id;
j += t;
}
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int ans = -; scanf("%d %d %d", &n, &m, &s);
rep(i, , m) {
scanf("%d", &N[i].x);
N[i].id = i;
}
rep(i, , n) {
scanf("%d", &S[i].x);
S[i].id = i+;
}
rep(i, , n)
scanf("%d", &S[i].p); sort(N, N+m);
sort(S, S+n); if (S[].x < N[].x) {
puts("NO");
return ;
} int l = ;
int r = m+;
int mid; while (l <= r) {
mid = (l+r)>>;
if (judge(mid)) {
ans = mid;
r = mid - ;
} else {
l = mid + ;
}
} if (ans > ) {
puts("YES");
bfs(ans);
rep(i, , m)
printf("%d ", a[i]);
putchar('\n');
} else {
puts("NO");
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}

【CF】222 Div.1 B 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】121 Div.1 C. Fools and Roads

    题意是给定一棵树.同时,给定如下k个查询: 给出任意两点u,v,对u到v的路径所经过的边进行加计数. k个查询后,分别输出各边的计数之和. 思路利用LCA,对cnt[u]++, cnt[v]++,并对 ...

  3. 【CF】310 Div.1 C. Case of Chocolate

    线段树的简单题目,做一个离散化,O(lgn)可以找到id.RE了一晚上,额,后来找到了原因. /* 555C */ #include <iostream> #include <str ...

  4. 【CF】110 Div.1 B. Suspects

    这题目乍眼一看还以为是2-sat.其实很水的,O(n)就解了.枚举每个人,假设其作为凶手.观察是否满足条件.然后再对满足的数目分类讨论,进行求解. /* 156B */ #include <io ...

  5. 【CF】207 Div.1 B.Xenia and Hamming

    这题目一看很牛逼,其实非常easy.求求最小公倍数,最大公约数,均摊复杂度其实就是O(n). /* 356B */ #include <iostream> #include <str ...

  6. 【CF】142 Div.1 B. Planes

    SPFA.注意状态转移条件,ans的求解需要在bfs中间求解.因为只要到了地点n,则无需等待其他tourist.还是蛮简单的,注意细节. /* 229B */ #include <iostrea ...

  7. 【CF】196 Div.2 D. Book of Evil

    显然这个图是一课树,看着题目首先联想到LCA(肯定是可以解的).但是看了一下数据大小,应该会TLE.然后,忽然想到一个前面做过的题目,大概是在一定条件下树中某结点旋转成为根后查询最长路径.结果灵感就来 ...

  8. 【CF】223 Div.1 C Sereja and Brackets

    水线段树. /* 380C */ #include <iostream> #include <string> #include <map> #include < ...

  9. 【CF】259 Div.1 B Little Pony and Harmony Chest

    还蛮有趣的一道状态DP的题目. /* 435B */ #include <iostream> #include <string> #include <map> #i ...

随机推荐

  1. 将商品SKU数据按商品分组,组装成json数据

    需要封装的数据   将这些数据,分组出来,OLGoodsID相同的为一组,然后每个组的OLSKUID,放在一个字段里,变成 [{"OLGoodID":"test06261 ...

  2. iis的路径

    每次打开iis管理器查看iis指定路径下的文件过于麻烦,而且iis管理器耗资源,以下是iis的路径,以及其对应在本地磁盘的地址 SP2013\Sites\SharePoint - 80\_contro ...

  3. java.lang.IllegalStateException: You need to use a theme.appcompat theme (or descendant) with this activity

    错误描述:java.lang.IllegalStateException: You need to use a theme.appcompat theme (or descendant) with t ...

  4. Net中exe之间的消息传递

    1.创建一个消息通讯类 using System;using System.Collections.Generic;using System.Linq;using System.Text;using ...

  5. Mysql JDBC 连接串参数说明

    MySQL的 JDBC URL 格式 for  Connector/J 如下例: jdbc:mysql://[host:port],[host:port].../[database][?参数名1][= ...

  6. Hdu 1452 Happy 2004(除数和函数,快速幂乘(模),乘法逆元)

    Problem Description Considera positive integer X,and let S be the sum of all positive integer diviso ...

  7. JNI学习总结

    JNI学习总结 标签(空格分隔): java JNI:Java Native Interface,是一种通过java调用本地方法的技术(当然也可以反过来),随着JDK版本的提升,JNI的效率也一直在提 ...

  8. tomcat内存溢出问题

    内存泄露java.lang.OutOfMemoryError: PermGen space解决办法 今天访问web服务器,tomcat服务就瘫痪了,通过查看日志,发现java.lang.OutOfMe ...

  9. 将数据库二进制图片导出显示到EPPlus Excel2007中

    1.EPPlus Excel 控件可以参考我的另一篇博客:http://blog.163.com/pei_huiping/blog/static/206573067201281810549984/ 这 ...

  10. 高效的VS调试技巧

    本文总结了十个调试技巧,当你使用VS的时候可以节省你很多时间. 1.悬停鼠标查看表达式 调试有时候很有挑战性,当你步入一个函数想看看哪块出错的时候,查看调用栈来想想值是从哪来的.另一些情况下,则需要添 ...