博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3553 Task schedule【拓扑排序 + 优先队列 / 贪心】
阅读量:7045 次
发布时间:2019-06-28

本文共 2652 字,大约阅读时间需要 8 分钟。

Task schedule

Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 515 Accepted: 309 Special Judge
Description

There are n preemptive jobs to be processed on a single machine. Each job j has a processing time pj and deadline dj. Preemptive constrains are specified by oriented graph without cycles. Arc (i,j) in this graph means that job i has to be processed before job j. A solution is specified by a sequence of the jobs. For any solution the completion time Cj is easily determined.

The objective is to find the optimal solution in order to minimize

max{Cj-dj, 0}.

Input

The first line contains a single integer n, 1 ≤ n ≤ 50000. Each of the next n lines contains two integers pj and dj, 0 ≤ pj ≤ 1000, 0 ≤ dj ≤ 1000000, separated by one or more spaces. Line n+2 contains an integer m (number of arcs), 0 ≤ m ≤ 10*n. Each of the next m lines contains two integers i and j, 1 ≤ i, j ≤ n.

Output

Each of the n lines contains integer i (number of job in the optimal sequence).

Sample Input

2

4 1
4 0
1
1 2
Sample Output

1

2
Source

Northeastern Europe 2003, Western Subregion

【代码】:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define debug() puts("++++")#define gcd(a,b) __gcd(a,b)#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define fi first#define se second#define pb push_back#define sqr(x) ((x)*(x))#define ms(a,b) memset(a,b,sizeof(a))#define sz size()#define be begin()#define pu push_up#define pd push_down#define cl clear()#define lowbit(x) -x&x#define all 1,n,1#define rep(i,n,x) for(int i=(x); i<(n); i++)#define in freopen("in.in","r",stdin)#define out freopen("out.out","w",stdout)using namespace std;typedef long long LL;typedef unsigned long long ULL;typedef pair
P;const int INF = 0x3f3f3f3f;const LL LNF = 1e18;const int maxm = 1e6 + 10;const double PI = acos(-1.0);const double eps = 1e-8;const int dx[] = {-1,1,0,0,1,1,-1,-1};const int dy[] = {0,0,1,-1,1,-1,1,-1};const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};using namespace std;const int maxn = 1e6+5;const int mod = 142857;int n,m,num,u,v;int p[maxn],d[maxn];priority_queue

q;vector

G[maxn];int inDeg[maxn];void topSort(){ int ok=0; while(!q.empty()) q.pop(); for(int i=1; i<=n; i++) if(!inDeg[i]) q.push(P(d[i],i)); while(!q.empty()) { int now = q.top().second; q.pop(); printf("%d\n",now); for(int i=0;i

转载于:https://www.cnblogs.com/Roni-i/p/9181509.html

你可能感兴趣的文章
Andrew Ng机器学习课程笔记--week1(机器学习介绍及线性回归)
查看>>
【nodejs】让nodejs像后端mvc框架(asp.net mvc)一样处理请求--请求处理结果适配篇(7/8)...
查看>>
用Python告诉你,现在的房租有多高?
查看>>
CSS3动画表单
查看>>
Spring Data JPA 持久层开发
查看>>
轻松 get 报表模糊查询技能
查看>>
SparkSQL实践与优化
查看>>
团队绩效考核的思考
查看>>
死磕 Elasticsearch 方法论:普通程序员高效精进的 10 大狠招!(Elasticsearch教程序章)|MVP讲堂...
查看>>
PostgreSQL 10.1 手册_部分 II. SQL 语言_第 10 章 类型转换_10.6. SELECT 输出列
查看>>
使用Java类加载SpringBoot、SpringCloud配置文件
查看>>
Java枚举
查看>>
如何把 Markdown 文件批量转换为 pdf?
查看>>
给信息安全爱好者的一封信
查看>>
swift 协议的写时拷贝
查看>>
为什么会出现微服务和分布式?
查看>>
SpringMVC源码分析3:DispatcherServlet的初始化与请求转发
查看>>
《当幸福来敲门》观后感
查看>>
Confluence 6 后台中的默认空间模板设置
查看>>
人工生命 1.0.0 版发布,第一个人工生命诞生
查看>>