中国大学生计算机系统与程序设计竞赛 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. 删除光标前或者光 ...
随机推荐
- java中System.err.print和System.out.print区别
System.err.print 是报错专用输输出,有颜色标记,所有err打印的都在顶行输出 System.out.print 是标准输出,白底黑字 package iobuffer; pu ...
- XML Schema 基本结构
<?xml version='1.0'?> <Schema name="cangchuSchema" metamodelVersion="4.0&quo ...
- C#读写修改设置调整UVC摄像头画面-滚动
有时,我们需要在C#代码中对摄像头的滚动进行读和写,并立即生效.如何实现呢? 建立基于SharpCamera的项目 首先,请根据之前的一篇博文 点击这里 中的说明,建立基于SharpCamera的摄像 ...
- 象棋中“车”的攻击范围_Java
代码如下: String[][] a = new String[8][8]; int h, l; Scanner scan = new Scanner(System.in); System.out.p ...
- vs2017添加引用提示“找不到 Microsoft.VisualStudio.Shell.Interop.IVsReferenceManager 服务的实例”解决方案
vs2017添加引用提示“找不到 Microsoft.VisualStudio.Shell.Interop.IVsReferenceManager 服务的实例” 不知道是不是安装时候的问题?解决方法: ...
- ASP.NET SignalR 系列(八)之跨域推送
前面几章讲的都是同域下的推送和订阅.这种讲讲如何跨域 对于SignalR来说,默认是不允许跨域的,因为安全问题.虽如此,但同时提供了跨域方案. 两种跨域方式: 1:JSONP2:CORS JSONP的 ...
- Matlab中介者模式
中介者模式(Mediator Pattern)是用来降低多个对象和类之间的通信复杂性.这种模式提供了一个中介类,该类通常处理不同类之间的通信,并支持松耦合,使代码易于维护.想象一个乱糟糟的开发小组的工 ...
- js根据json数组多个字段排序
/**数组根据数组对象中的某个属性值进行排序的方法 * 使用例子:newArray.sort(sortByArr(['number'],false)) //表示根据number属性降序排列;若第二个参 ...
- Linux基础:时间同步工具Chrony
在Linux下,默认情况下,系统时间和硬件时间,并不会自动同步.在Linux运行过程中,系统时间和硬件时间以异步的方式运行,互不干扰.硬件时间的运行,是靠Bios电池来维持,而系统时间,是用CPU t ...
- web模拟终端 --使用shellinabox
关于shellinabox ShellInABox实现了一个Web服务器,可以将任意命令行工具导出到基于Web的终端仿真器.任何支持JavaScript和CSS的Web浏览器都可以访问此模拟器,并且不 ...