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 ...
随机推荐
- 经过两个多月的攻关,终于搞定了live555多线程并稳定压测通过
live555已经发展了十几年了,不得不钦佩作者坚持不懈的奉献和国外的开源生态环境,live555可以说是大部分的安防从业者的入门之选,尤其是在嵌入式或者Linux系统上,其应用还是蛮广泛的,主要是其 ...
- Bootstrap导航栏头部错位问题
代码: <section class="header"> <div class="container"> <div class=& ...
- [note]fhq_treap
fhq_treap 这东西据说是某个叫范浩强的神仙搞出来的, 他的这种treap可以不用旋转并且资磁很多平衡树操作, 复杂度通过随机的键值来保证(树大致平衡,期望一次操作复杂度\(logn\)) 依靠 ...
- Mac下XAMPP环境中安装MySQLdb
环境: Mac OS X. Mac下安装MySQLdb模块着实多了些步骤. 用easy_install或者pip安装时有两大问题,"mysql_config not found"和 ...
- Shiro:学习笔记(2)——授权
Shiro:学习笔记(2)——授权 Shiro的三种授权方式 编程式: Subject subject = SecurityUtils.getSubject(); if(subject.hasRole ...
- url信息
var protocol = window.location.protocol; // "http:" var host = window.location.host; //&qu ...
- python 3 并发编程之多进程 multiprocessing模块
一 .multiprocessing模块介绍 python中的多线程无法利用多核优势,如果想要充分地使用多核CPU的资源(os.cpu_count()查看),在python中大部分情况需要使用多进程. ...
- 第五篇、css补充二
一.内容概要 1.图标 2.目录规划 3.a标签中的img标签在浏览器中的适应性 4.后台管理系统设置 5.边缘提示框 6.登录页面图标 7.静态对话框 8.加减框 补充知识: line-height ...
- hd acm1425
给你n个整数,请按从大到小的顺序输出其中前m大的数. 先看代码: #include<stdio.h>#include<string.h>#define MAX 1100000i ...
- 如何用<Enter>键代替<Tab>键实现光标焦点转移?
1.在主窗体的private中定义过程: procedure doenterastab(var Msg:TMsg;var Handled:Boolean); begin if Msg.messa ...