uoj problem 10
uoj problem 10
题目大意:
给定任务若干,每个任务在\(t_i\)收到,需要\(s_i\)秒去完成,优先级为\(p_i\)
你采用如下策略:
每一秒开始时,先收到所有在该秒出现的任务,然后取出当前优先级最高的任务,一直工作这个任务到下一秒,该任务的需要的时间-1s,如此循环进行,直到任务全部完成.
现在有一任务的优先级未知,但知道其被完成的时间点.确定一个合法的优先级.并计算出所有任务完成的时间
题解:
其实vfk的题解很详细.
那我就写一写我的理解吧.
首先拿到这道题我们就会去想枚举优先级然后判定.
分析一下我们发现优先级是具有单调性的,所以我们可以二分.
这样直接就能拿到90%的分数.
然后题解上说:
第一问的二分是建立在单调性上的,而有单调性的题,往往可以试着利用扫描的方法去优化。
WTF...我好是第一次用扫描优化有单调性的题...
我们扫描一边所有的题目,先将未知的优先级按照\(-inf\)算,计算出所有的任务的结束时间
设未知优先级的任务编号为x,结束时间为T
那么我们计算出所有在\([t_x,T]\)内的工作量,然后我们将所有的任务按照优先级排序.
现在我们就确定一个优先级是的所有优先级\(<\)它的任务的工作量之和等于\(s_x\)
不难发现这样是对的.
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(ll &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch=='-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
const int maxn = 300010;
struct Node{
ll t;
ll s,p,id,idx;
bool friend operator < (const Node &a,const Node &b){
return a.p < b.p;
}
}a[maxn],b[maxn];
inline bool cmp(const Node &a,const Node &b){
return a.t < b.t;
}
ll n,T,Xl,Xr,ans[maxn];
inline void add(ll l,ll r,int id){
ll x = min(r,Xr) - max(l,Xl) + 1;
if(x <= 0) return ;
b[id].s += x;
}
inline void work(int n){
priority_queue<Node>q;
ll la = 0;
for(int i=1;i<=n;++i){
ll ti = a[i].t - 1;
if(ti > la){
ll x = ti - la,y = 0;
while(!q.empty() && q.top().s <= x){
Node no = q.top();q.pop();
x -= no.s;y += no.s;
ans[no.id] = la + y;
add(la+y-no.s+1,la+y,no.idx);
}
if(!q.empty() && x){
Node no = q.top();q.pop();
add(la+y+1,la+y+x,no.idx);
no.s -= x;q.push(no);
}
}
while(a[i].t == a[i+1].t){
q.push(a[i]);
++ i;
}q.push(a[i]);la = a[i].t - 1;
}
}
int main(){
read(n);int tx;
for(int i=1;i<=n;++i){
read(a[i].t);
read(a[i].s);
read(a[i].p);
a[i].id = i;
}
a[n+1].t = 1LL<<60;
a[n+1].s = 1e9;
a[n+1].p = -1e9;
a[n+1].id = n+1;
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;++i){
a[i].idx = i;
b[i] = a[i];b[i].s = 0;
if(a[i].p == -1){
b[i].p = a[i].p = 0;
tx = i;
}
}
read(T);--T;
Xl = a[tx].t;Xr = T;work(n+1);
sort(b+1,b+n+1);
ll s = a[tx].s,ans1 = 0;
for(int i=1;i<=n;++i){
s -= b[i].s;
if(s == 0 && b[i].p + 1 != b[i+1].p){
ans1 = b[i].p + 1;
break;
}
}
printf("%lld\n",ans1);
a[tx].p = ans1;
work(n+1);
for(int i=1;i<=n;++i){
printf("%lld",ans[i]+1);
if(i != n) putchar(' ');
else putchar('\n');
}
return 0;
}
uoj problem 10的更多相关文章
- Project Euler Problem 10
Summation of primes Problem 10 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of ...
- Problem 10
Problem 10 # Problem_10.py """ The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. ...
- leetcode problem 10 Regular Expression Matching(动态规划)
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- (Problem 10)Summation of primes
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two milli ...
- uoj problem 31 猪猪侠再战括号序列
题目大意: 给定一个长度为2n的括号序列.定义一个关于区间[l,r]的翻转操作为位置平移对调. 即翻转")))()("可以得到"()()))((" 用不超过n次 ...
- uoj problem 14 DZY Loves Graph
题目: DZY开始有 \(n\) 个点,现在他对这 \(n\) 个点进行了 \(m\) 次操作,对于第 \(i\) 个操作(从 \(1\) 开始编号)有可能的三种情况: Add a b: 表示在 \( ...
- uoj problem 21 缩进优化
题目: 小O是一个热爱短代码的选手.在缩代码方面,他是一位身经百战的老手.世界各地的OJ上,很多题的最短解答排行榜都有他的身影.这令他感到十分愉悦. 最近,他突然发现,很多时候自己的程序明明看起来比别 ...
- uoj problem 11 ydc的大树
题目大意: 给定一颗黑白树.允许删除一个白点.最大化删点后无法与删点前距自己最远的黑点连通的黑点个数.并求出方案数. 题解: 这道题很棒棒啊. 一开始想了一个做法,要用LCT去搞,特别麻烦而且还是\( ...
- Problem 10: Summation of primes
def primeslist(max): ''' 求max值以内的质数序列 ''' a = [True]*(max+1) a[0],a[1]=False,False for index in rang ...
随机推荐
- 基于jquery的bootstrap在线文本编辑器插件Summernote (转)
Summernote是一个基于jquery的bootstrap超级简单WYSIWYG在线编辑器.Summernote非常的轻量级,大小只有30KB,支持Safari,Chrome,Firefox.Op ...
- 【BZOJ2460】[BeiJing2011]元素 贪心+高斯消元求线性基
[BZOJ2460][BeiJing2011]元素 Description 相传,在远古时期,位于西方大陆的 Magic Land 上,人们已经掌握了用魔法矿石炼制法杖的技术.那时人们就认识到,一个法 ...
- c++的检测的确比C++更严格
见下面代码 #include <stdio.h> #include <stdlib.h> #include <time.h> enum guess { paper, ...
- Java内部类{[普通内部类][静态内部类]}
package Learn.com.seven; /** * * @author tqw * 本例主要学习内部类的使用 * Java的内部类分成两部分来讲: * 1:内部类 * 2:静态内部类 * * ...
- Hadoop生态优秀文章集锦
如何用形象的比喻描述大数据的技术生态?Hadoop.Hive.Spark 之间是什么关系? https://www.zhihu.com/question/27974418 HBase 和 Hive 的 ...
- Cordova-安装Cordova过程详细解
官方网站Apache Cordova 前提是你电脑上 1:全局安装了Node 2:全局安装了npm 3:安装了java,并配置好环境 4:下载安装好android-sdk,并配好环境,注意安卓虚拟机可 ...
- scala语法解析(解码指环)
看惯了JAVA的语法,再看scala的语法,有的晦涩难懂.正好遇到一个介绍scala语法的文章,就直接截图留念.省的再临时抱佛脚了.
- 数组的includes操作
数组实例的 includes() Array.prototype.includes方法返回一个布尔值,表示某个数组是否包含给定的值,与字符串的includes方法类似.ES2016 引入了该方法. [ ...
- linux多个分区合并为一个分区
备份# rsync -avP -e ssh /data xxx卸载# umount /data /data?设置分区类型为8e# fdisk /dev/sdb 创建PV# pvcreate /dev/ ...
- 获取android模拟器的IP地址
http://blog.csdn.net/yjkwf/article/details/7244632 1.输入adb devices查看加载的设备 2.使用 adb -s [设备] [命令]执行命令 ...