题目详见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. SpringCloud Gateway快速入门

    SpringCloud Gateway cloud笔记第一部分 cloud笔记第二部分Hystrix 文章目录 SpringCloud Gateway Zull的工作模式与Gateway的对比 Rou ...

  2. Java内存模型与线程(一)

    Java内存模型与线程 TPS:衡量一个服务性能的标准,每秒事务处理的总数,表示一秒内服务端平均能够响应的总数,TPS又和并发能力密切相关. 在聊JMM(Java内存模型)之前,先说一下Java为什么 ...

  3. Centos 6 下安装 OSSEC-2.8.1 (一)

    ossec -2.8.1 安装: ## 1 ) 安装依赖包: RedHat / Centos / Fedora / Amazon Linux yum install -y pcre mysql mys ...

  4. 【Linux】iptables配置文件中的一些疑问

    1.看到配置文件中开头会写一句话,但是数值还都不一样 括号里面的数值的含义是:通过该规则的数据包和字节总数 Chain FORWARD (policy DROP 0 packets, 0 bytes) ...

  5. 如何创建一个 PostgreSQL 数据库?

    PostgreSQL 官网截图 PostgreSQL 是什么? PostgreSQL 是一个功能非常强大的,历史悠久,开源的关系数据库.PostgreSQL支持大部分的SQL标准并且提供了很多其他现代 ...

  6. SQL 语法速成手册

    本文针对关系型数据库的一般语法.限于篇幅,本文侧重说明用法,不会展开讲解特性.原理. 一.基本概念 数据库术语 数据库(database) - 保存有组织的数据的容器(通常是一个文件或一组文件). 数 ...

  7. 【Android初级】如何动态添加菜单项(附源码+避坑)

    我们平时在开发过程中,为了灵活多变,除了使用静态的菜单,还有动态添加菜单的需求.今天要分享的功能如下: 在界面的右上角有个更多选项,点开后,有两个子菜单:关于和退出 点击"关于", ...

  8. iDRAC RAC0218 最大会话数

    戴尔服务器IDRAC能ping通,但是网页打不开的时候: 用putty登录: /admin1-> racadm racreset RAC reset operation initated suc ...

  9. Linux下运行java报错:Error: Could not find or load main class SocketIOPropertites

    [root@node01 testfileio]# javac SocketIOPropertites.java && java Soc ketIOPropertitesError: ...

  10. https://www.cnblogs.com/AloneSword/p/3209653.html

    proc/sys/net/ipv4/下各项的意义 - 孤剑 - 博客园 https://www.cnblogs.com/AloneSword/p/3209653.html