题目详见http://7xjob4.com1.z0.glb.clouddn.com/3f644de6844d64706eb36baa3a0c27b0

这题是普通的拓扑排序,要把每一层的都保存下来。

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
#define inf 99999999
#define pi acos(-1.0)
#define MOD 1000000007
struct edge{
int to,next;
}e[2*20050];
int first[5050],du[5050];
int q[1111111];
int n,m;
int ceng[5050][5050],num[5050],deep[5050],cengshu,sum[5050]; void topu()
{
int i,j;
int front,rear;
front=1;rear=0;
memset(num,0,sizeof(num));
memset(deep,0,sizeof(deep));
for(i=1;i<=n;i++){
if(!du[i]){
rear++;
q[rear]=i;
deep[i]=1;
}
}
int x,y,xx,yy;
cengshu=1;
while(front<=rear){
x=q[front];
front++;
cengshu=max(cengshu,deep[x]);
num[cengshu]++;
ceng[cengshu ][num[cengshu] ]=x;
for(i=first[x];i!=-1;i=e[i].next){
int v=e[i].to;
du[v]--;
if(!du[v]){
rear++;
q[rear]=v;
deep[v]=deep[x]+1;
}
}
} sum[0]=0;
for(i=1;i<=cengshu;i++){
sum[i]=sum[i-1]+num[i];
}
} int main()
{
int i,j,l,r,tot,c,d;
while(scanf("%d%d%d%d",&l,&r,&n,&m)!=EOF)
{
memset(first,-1,sizeof(first));
memset(du,0,sizeof(du));
tot=0;
for(i=1;i<=m;i++){
scanf("%d%d",&c,&d);
c++;d++;
du[d]++;
tot++;
e[tot].next=first[c];e[tot].to=d;
first[c]=tot;
} topu();
int num1,num2,num3;
for(i=1;i<=cengshu;i++){
if(sum[i]>l)break;
}
i--;
num1=sum[i]; for(i=1;i<=cengshu;i++){
if(sum[i]>r)break;
}
i--;
num2=sum[i]; for(i=1;i<=cengshu;i++){
if(sum[i]>=r)break;
}
if(i>=cengshu)num3=0;
else num3=sum[cengshu]-sum[i];
printf("%d\n%d\n%d\n",num1,num2,num3);
}
return 0;
}

A - Promotions的更多相关文章

  1. Integral Promotions整数提升和符号扩展(char,unsigned char,signed char)

    以下来自msdn: Objects of an integral type can be converted to another wider integral type (that is, a ty ...

  2. LED Keychain-Ideal For Mass Promotions

    Looking for something memorable to remind people of your business or nonprofit? Consider custom LED ...

  3. Chapter 5. Conversions and Promotions

    JLS解读:https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html 基本数据类型的转换 1) boolean不可以转换为其他的数据类型 ...

  4. 很好的脑洞题:dfs+暴力 Gym - 101128A Promotions

    http://codeforces.com/gym/101128 题目大意:给你一个a,b,e,p.有e个点,p条有向边,每条边为(x,y),表示x->y,每次我们都取出一个入度为0的,并且一次 ...

  5. LA 7272 Promotions(dfs)

    https://vjudge.net/problem/UVALive-7272 题意: 公司要提拔人,现在有n个人,现在有m条有向边,A->B表示A的表现比B好,也就是如果B晋升了,那么A肯定会 ...

  6. 【拓扑排序】【bitset】Gym - 101128A - Promotions

    给你一张DAG,若选择u点,则必须先选择所有能到达其的点.问你在选择A个点的情况下,哪些点必选:选择B个点的情况下,哪些点必选:选择B个点的情况下,哪些点一定不选. 选择A个点的情况,必选的点是那些其 ...

  7. Gym 101128A :Promotions (Southwestern Europe Regional Contest )

    题意 一个公司里有E个员工P个上下级关系.这个公司有一种晋升制度.如果要晋升员工a,那么必须要先晋升a的所有领导.给出一个区间[A,B],如果要晋升A个员工,有哪些员工是一定会被晋升的?如果要晋升B个 ...

  8. Light Up Your Business Promotions With LED Keychain

    Imagine you want to insert the car key into the keyhole in the dark. What would you do? You will def ...

  9. Gym 101128A Promotions(思维 + dfs)题解

    题意:给一有向图,如果A指向B,则A是B的上级.一直i要升职那么他的上级必须都升职.现在给你一个升职人数的区间[a, b],问你升职a人时几个人必被升职,b时几个人必升职,b时几个人没有可能被升职. ...

随机推荐

  1. 剑指offer 树的基本操作:四种遍历方式

    前序遍历 递归版 编程思想 即借助系统栈,效率较低.二叉树的前序遍历规则:1. 访问根结点: 2. 遍历左子树: 3. 遍历右子树 编程实现 //树的定义 struct TreeNode { int ...

  2. MongoDB的管理-深度长文

    (1) 启动和停止MongoDB: Ubuntu18下启动关闭MongoDB 启动MongoDB: 方法一: systemctl start mongod.service 方法二: 在MongoDB的 ...

  3. (十九)hashlib模块

    hashlib模块用于加密相关的操作,3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法 注意:md5和sha25 ...

  4. 【Linux】以001格式循环到100保证位数是3位

    这里有一个前提,要保证数位是相同的 确实数字是1-100  但是数位是不同的,需要统一一下位数必须是3位的 这个问题在很多论坛上用的都是printf这个命令,确实可以达到这个效果,但是没有我下面介绍的 ...

  5. P2327 [SCOI2005]扫雷(递推)

    题目链接: https://www.luogu.org/problemnew/show/P2327 题目描述 相信大家都玩过扫雷的游戏.那是在一个$n*m$的矩阵里面有一些雷,要你根据一些信息找出雷来 ...

  6. mount: /dev/sdxx already mounted or /xxxx busy解决方法

    异常现象: 解决方法: 1.    輸入root的密碼,進入單用戶2.    重新掛載/目錄,使其變為可讀可寫 # mount –o rw,remount / 3.    修改/etc/fstab文件 ...

  7. JMS监听Oracle AQ

    该文档中,oracle版本为11g,jdk版本1.8,java项目为maven构建的springboot项目,springboot的版本为2.1.6,并使用了定时任务来做AQ监听的重连功能,解决由于外 ...

  8. Ubuntu创建桌面图标

    以火狐为例 创建"~/.local/share/applications/firefox_dev.desktop"文件, 文件内容为: [Desktop Entry] Name=F ...

  9. linux搭建ARM可调式环境

    0x00 前言 本文中所介绍的方法目前只测试了单个的demo,并没有拿大型的项目做测试,但是应该是大同小异.这里介绍两种方法,一种是有独立的ARM硬件,另一种是依靠qemu实现的模拟化,其实其本质都是 ...

  10. Kubernetes 存储简介

    存储分类结构图 半持久化存储 1.EmptyDir EmptyDir是一个空目录,生命周期和所属的 Pod 是完全一致的,EmptyDir的用处是,可以在同一 Pod 内的不同容器之间共享工作过程中产 ...