题目详见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】06.从尾到头打印链表

    题目描述 输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回). 示例 1: 输入:head = [1,3,2] 输出:[2,3,1] 限制: 0 <= 链表长度 <= 10 ...

  2. ansible 安装和使用

                                ansible 安装和使用   ## 安装epel 源: rpm -ivh https://dl.fedoraproject.org/pub/e ...

  3. MySQL查询优化之 index 索引的分类和使用

    索引的分类 主键索引 (PRIMARY KEY) 唯一的标识符, 主键不可重复, 只能有一列作为主键 唯一索引 (Unique KEY) 避免重复的列出现, 唯一索引可以重复, 多个列都可以标识为唯一 ...

  4. +load和+initialize方法调用时机

    一.+load方法什么时候调用 +load方法会在runtime加载类.分类时调用(程序运行起来会先去加载调用+load 跟你引用没有引用其头文件没有关系).每个类.分类的+load,在程序运行过程中 ...

  5. DDOS攻击方式总结以及免费DDOS攻击测试工具大合集

    若有雷同或者不足之处,欢迎指正交流,谢谢! DoS(Denial Of Service)攻击是指故意的攻击网络协议实现的缺陷或直接通过野蛮手段残忍地耗尽被攻击对象的资源,目的是让目标计算机或网络无法提 ...

  6. 自监督SOTA框架 | BYOL(优雅而简洁) | 2020

    文章原创自微信公众号「机器学习炼丹术」 作者:炼丹兄 联系方式:微信cyx645016617 本篇文章主要讲解两个无监督2020年比较新比较火的论文: 论文名称:"Bootstrap You ...

  7. The Node.js Event Loop, Timers, and process.nextTick()

    The Node.js Event Loop, Timers, and process.nextTick() | Node.js https://nodejs.org/uk/docs/guides/e ...

  8. 选出ip记录表最近的10行数据

    w select * from wip where id>(select (select max(id)from wip)-10) ;

  9. Socket的用法——NIO包下SocketChannel的用法 ———————————————— 版权声明:本文为CSDN博主「茶_小哥」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/ycgslh/article/details/79604074

    服务端代码实现如下,其中包括一个静态内部类Handler来作为处理器,处理不同的操作.注意在遍历选择键集合时,没处理完一个操作,要将该请求在集合中移除./*模拟服务端-nio-Socket实现*/pu ...

  10. springboot项目-声明式事务失效

    1.项目背景 集成了shiro配置 2. 项目分析 由于ShiroFilterFactoryBean实现了FactoryBean接口,所以它会提前被初始化.又因为SecurityManager,Sec ...