串行调度(serial)

除等价条件, 根据题意设置限制条件,然后求字典序最小拓扑序。

简洁版

#include<bits/stdc++.h>
using namespace std;
const int N=2e4+;
const int M=2e4+;
const int E=8e5+;
template <typename T>
inline void read(T &x){
T f=;char ch=getchar();x=;
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
x*=f;
}
vector<int>lastR[N];int lastW[N];
bitset<M>d[M];
int n,m,pcnt,qcnt,tot,ind[M],to[E],nxt[E],head[M];
inline void add(int x,int y){
if(!x||x==y) return ;
ind[y]++;
to[++tot]=y;nxt[tot]=head[x];head[x]=tot;
}
inline void init(){
read(n);read(m);read(pcnt);read(qcnt);
for(int i=,op,xk,tk;i<=pcnt;i++){
read(op);read(xk);read(tk);
if(op){
if(!lastR[xk].empty()){
for(auto &i:lastR[xk]) add(i,tk);
lastR[xk].clear();
}
else{
add(lastW[xk],tk);
}
lastW[xk]=tk;
}
else{
add(lastW[xk],tk);
lastR[xk].push_back(tk);
}
}
}
priority_queue<int,vector<int>,greater<int> >q;
inline void topo(){
d[]=;
for(int i=;i<=m;i++) d[i]=d[i-]<<;
for(int i=;i<=m;i++) if(!ind[i]) q.push(i);
for(int i=;i<=m;i++){
int x=q.top();q.pop();
printf("%d ",x);
for(int j=head[x];j;j=nxt[j]){
if(!--ind[to[j]]){
q.push(to[j]);
}
d[to[j]]|=d[x];
}
}
puts("");
for(int i=qcnt,x,y;i;i--){
read(x);read(y);
puts(!d[x].test(y)?"YES":"NO");
}
}
int main(){
init();
topo();
return ;
}

纯手写bitset

#include<queue>
#include<vector>
#include<cstdio>
using std::vector;
using std::priority_queue;
const int N=2e4+;
const int M=2e4+;
const int E=8e5+;
template <typename T>
inline void read(T &x){
T f=;char ch=getchar();x=;
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
x*=f;
}
vector<int>lastR[N];int lastW[N];
struct BitSet{//模拟bitset
// unsigned int 以压缩32位
// unsigned long long 可以压缩64位
const static int N = M / + ;
unsigned data[N];
unsigned& operator[](int a){
return data[a];
}
const unsigned& operator[](int a)const{
return data[a];
}
bool get(int a){
return (data[a >> ] >> (a & )) & ;
}
void set(int a){
data[a >> ] |= << (a & );
}
void unset(int a){
data[a >> ] &= ~( << (a & ));
}
BitSet& operator|=(const BitSet& a){
for(int i = ; i < N; i++)
data[i] |= a[i];
return *this;
}
}used[M];
int n,m,pcnt,qcnt,tot,ind[M],to[E],nxt[E],head[M];
inline void add(int x,int y){
if(!x||x==y) return ;
ind[y]++;
to[++tot]=y;nxt[tot]=head[x];head[x]=tot;
}
inline void init(){
read(n);read(m);read(pcnt);read(qcnt);
for(int i=,op,xk,tk;i<=pcnt;i++){
read(op);read(xk);read(tk);
if(op){
if(!lastR[xk].empty()){
for(auto &i:lastR[xk]) add(i,tk);
lastR[xk].clear();
}
else{
add(lastW[xk],tk);
}
lastW[xk]=tk;
}
else{
add(lastW[xk],tk);
lastR[xk].push_back(tk);
}
}
}
priority_queue<int,vector<int>,std::greater<int> >q;
inline void topo(){
for(int i=;i<=m;i++) used[i].set(i);
for(int i=;i<=m;i++) if(!ind[i]) q.push(i);
for(int i=;i<=m;i++){
int x=q.top();q.pop();
printf("%d ",x);
for(int j=head[x];j;j=nxt[j]){
if(!--ind[to[j]]){
q.push(to[j]);
}
used[to[j]]|=used[x];
}
}
puts("");
for(int i=qcnt,x,y;i;i--){
read(x);read(y);
puts(!used[x].get(y)?"YES":"NO");
}
}
int main(){
init();
topo();
return ;
}

中国大学生计算机系统与程序设计竞赛 CCF-CCSP-2017 串行调度(serial)的更多相关文章

  1. 中国大学生计算机系统与程序设计竞赛 CCF-CCSP-2016 选座( ticket_chooser )

    选座( ticket_chooser ) 不会正解,欢迎讨论 //60分 #include<cstdio> #define max(a,b) (a)>(b)?a:b #define ...

  2. “知乎杯”2018 CCF 大学生计算机系统与程序设计竞赛 分组加密器(encryption)

    分组加密器(encryption) 题解点这里 #include<map> #include<stack> #include<vector> #include< ...

  3. “知乎杯”2018 CCF 大学生计算机系统与程序设计竞赛 贪心算法(greedy)

    --> 贪心算法 1)题解 •        分别用V0.V1和V>=2表示度为0.1以及至少为2的顶点集合 •        对于每个顶点,维护三个属性: •        degree ...

  4. “知乎杯”2018 CCF 大学生计算机系统与程序设计竞赛 绝地求生(battleground)

    /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-ts ...

  5. ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目9 : Minimum

    时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2^k-1. You need t ...

  6. ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 i题 Minimum(线段树)

    描述 You are given a list of integers a0, a1, …, a2^k-1. You need to support two types of queries: 1. ...

  7. 【分类讨论】【计算几何】【凸包】hihocoder 1582 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E. Territorial Dispute

    题意:平面上n个点,问你是否存在一种黑白染色方案,使得对于该方案,无法使用一条直线使得黑色点划分在直线一侧,白色点划分在另一侧.如果存在,输出一种方案. 如果n<=2,显然不存在. 如果所有点共 ...

  8. 【线段树】hihocoder 1586 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 I. Minimum

    题意:给你一个序列(长度不超过2^17),支持两种操作:单点修改:询问区间中最小的ai*aj是多少(i可以等于j). 只需要线段树维护区间最小值和最大值,如果最小值大于等于0,那答案就是minv*mi ...

  9. 【最短路】【Heap-dijkstra】hihocoder 1587 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 J. Typist's Problem

    题意:给你一个串,仅含有a~g,且每个字母只出现最多一次.和一个光标初始位置,以及一个目标串,问你最少要多少的代价变化成目标串. 有五种操作:在光标前添加一个未出现过的字母,代价1. 删除光标前或者光 ...

随机推荐

  1. SQL Server SSIS中的变量使用表达式后,就无法更改其值了

    在SQL Server SSIS中,我们可以为变量定义初始值和表达式,其实SSIS的变量定义为表达式后我们就无法更改变量的值了,我们来做如下实验: 首先我们在SSIS包中定义一个String类型的变量 ...

  2. c#调用python脚本实现排序(适用于python脚本中不包含第三方模块的情况)

    引用:https://www.cnblogs.com/zoe-yan/p/10374757.html 利用vs2017c#调用python脚本需要安装IronPython.我是通过vs2017的工具- ...

  3. 一次golang应用的docker部署经历

    开发平台win10,服务器centos7.5 编写dockerfile # scratch 为空镜像,因为golang的build的可执行文件不需要什么环境 FROM scratch # 作者署名 M ...

  4. 获取Excel

    默认Excel文档为 代码如下   需要下载  "EPPlus.Core" var file = Directory.GetCurrentDirectory() + "\ ...

  5. ERP会计科目表初始化

    2019会计科目表 一.资产类 顺序号 编号 会计科目名称 会计科目适用范围 顺序号 编号 会计科目名称 会计科目适用范围 1 1001 库存现金 38 1431 周转材料 建造承包商专用 2 100 ...

  6. javascript实现网页倒计时效果

    一.HTML代码如下: <div class="timer" id="timer"> <span style="color: bla ...

  7. springboot-发布jar包

    其他参考链接: https://www.cnblogs.com/blog5277/p/5920560.html 环境变量配置: 新建系统变量MAVEN_HOME: 在path中添加: ;%MAVEN_ ...

  8. 【Iterm2】如何解决iterm2窗口自动隐藏的问题

    一.问题描述 当我们使用Iterm2的Hotkey Windom功能时,通过快捷键唤起Iterm2窗口后,然后鼠标在iterm2窗口之外触发点击操作就会让 iterm2窗口自动隐藏.. 这样有时候会觉 ...

  9. free - 显示系统内存信息

    free - Display amount of free and used memory in the system 显示系统中空闲和已使用内存的数量 格式: free [options] opti ...

  10. Introduction to Linux Threads

    Introduction to Linux Threads A thread of execution is often regarded as the smallest unit of proces ...