中国大学生计算机系统与程序设计竞赛 CCF-CCSP-2017 串行调度(serial)
串行调度(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)的更多相关文章
- 中国大学生计算机系统与程序设计竞赛 CCF-CCSP-2016 选座( ticket_chooser )
选座( ticket_chooser ) 不会正解,欢迎讨论 //60分 #include<cstdio> #define max(a,b) (a)>(b)?a:b #define ...
- “知乎杯”2018 CCF 大学生计算机系统与程序设计竞赛 分组加密器(encryption)
分组加密器(encryption) 题解点这里 #include<map> #include<stack> #include<vector> #include< ...
- “知乎杯”2018 CCF 大学生计算机系统与程序设计竞赛 贪心算法(greedy)
--> 贪心算法 1)题解 • 分别用V0.V1和V>=2表示度为0.1以及至少为2的顶点集合 • 对于每个顶点,维护三个属性: • degree ...
- “知乎杯”2018 CCF 大学生计算机系统与程序设计竞赛 绝地求生(battleground)
/* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-ts ...
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目9 : Minimum
时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2^k-1. You need t ...
- 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. ...
- 【分类讨论】【计算几何】【凸包】hihocoder 1582 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E. Territorial Dispute
题意:平面上n个点,问你是否存在一种黑白染色方案,使得对于该方案,无法使用一条直线使得黑色点划分在直线一侧,白色点划分在另一侧.如果存在,输出一种方案. 如果n<=2,显然不存在. 如果所有点共 ...
- 【线段树】hihocoder 1586 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 I. Minimum
题意:给你一个序列(长度不超过2^17),支持两种操作:单点修改:询问区间中最小的ai*aj是多少(i可以等于j). 只需要线段树维护区间最小值和最大值,如果最小值大于等于0,那答案就是minv*mi ...
- 【最短路】【Heap-dijkstra】hihocoder 1587 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 J. Typist's Problem
题意:给你一个串,仅含有a~g,且每个字母只出现最多一次.和一个光标初始位置,以及一个目标串,问你最少要多少的代价变化成目标串. 有五种操作:在光标前添加一个未出现过的字母,代价1. 删除光标前或者光 ...
随机推荐
- spring注解@postConstruct与constructor与@Autowired的启动顺序
本文链接:https://blog.csdn.net/zpflwy1314/article/details/80797756 @Postcontruct’在依赖注入完成后自动调用,例如要将对象a注入到 ...
- 【C#】58. .Net中的并发集合——BlockingCollection
https://blog.csdn.net/huiwuhuiwu/article/details/53608269 这篇是并发集合中的最后一篇,介绍一下BlockingCollection.在工作中我 ...
- html 显示 pdf
html 显示 pdf文件四种方式: 1. <embed src="pdf/wobu.pdf" type="application/pdf" width= ...
- 什么是B+树
什么是B+树呢?在说B+树之前我们先了解一下为什么要有B树,其实这些树最开始都是为了解决某种系统中,查询效率低的问题.B树其实最开始源于的是二叉树,二叉树是只有左右孩子的树,当数据量越大的时候,二叉树 ...
- Beego学习笔记四:编写Model
MVC实践一:编写模型 1> 打开mysql数据库,设计表的结构 <1>登录mysql数据库,如下 <2>这三个标注的参数皆有用,需要谨记. <3>创 ...
- Springboot jpa多数据源
1.SpringBootApplication package com.xx.xxx; import org.springframework.beans.factory.annotation.Auto ...
- Python 序列、列表(List)、元组(Tuple)
序列 序列是Python中最基本的数据结构,包括字符串.列表.元组. 序列,顾名思义,是有序的,序列都有索引,都能进行索引.切片(截取).加(连接).乘(倍增).检查成员的操作. 因为序列有序,可通过 ...
- day 33
目录 数据库是什么 为什么使用数据库 数据库的分类 关系型(把数据保存在硬盘里) 非关系型(把数据保存在内存里) mysql的架构 初识mysql 操作数据库 增 删 改 查 数据库是什么 数据库即存 ...
- 微信小程序引入外部组件 iView Weapp
iview Weapp组件的使用方法: 1. 下载小程序组件库 (前提是你已经有了项目目录) 你可以直接去github把iView Weapp的代码下载下来,也可以用过npm来下载. github地址 ...
- find 和grep的区别
find(以文件属性为查找条件) grep(以文件内容为查找条件) grep works /usr/local/apache/htdocs/index.html 1.将/etc/passwd,有出现 ...