题目详见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. Python基础语法6-冒泡排序

    用for循环实现冒泡排序(升序): array = [3,2,1]  for i in range(len(array) - 1, 0, -1):  for j in range(0, i):  if ...

  2. buuctf—web—高明的黑客

    打开靶机,看到如下界面 于是打开www.tar.gz 下载后发现是一个放有大量php文件的文件夹 看了大佬的wp后明白了是fuzzing 附上大佬的脚本 import os import re imp ...

  3. [Usaco2008 Mar]River Crossing渡河问题

    题目描述 Farmer John以及他的N(1 <= N <= 2,500)头奶牛打算过一条河,但他们所有的渡河工具,仅仅是一个木筏. 由于奶牛不会划船,在整个渡河过程中,FJ必须始终在木 ...

  4. mastercam2018安装教程

    安装前先关闭杀毒软件和360卫士,注意安装路径不能有中文,安装包路径也不要有中文. [安装环境]:Win7/Win8/Win10 1.选中[Mastercam2018]压缩包,鼠标右击选择[解压到Ma ...

  5. 输入12V,输出12V的限流芯片

    随着手机充电电流的提升,和设备的多样化,USB限流芯片就随着需求的增加而越来越多,同时为了更好的保护电子设备,需要进行一路或者多路的负载进行限流. USB限流芯片,5V输入 1, PW1502,常使用 ...

  6. 核酸检测:让我明白AQS原理

    春节越来越近了,疫情也越来越严重,但挡不住叫练携一家老小回老家(湖北)团聚的冲动.响应国家要求去我们做核酸检测了. 独占锁 早上叫练带着一家三口来到了南京市第一医院做核酸检测,护士小姐姐站在医院门口拦 ...

  7. java.io.IOException: Could not find resource com/xxx/xxxMapper.xml

    java.io.IOException: Could not find resource com/xxx/xxxMapper.xml 报错内容: org.apache.ibatis.exception ...

  8. babel : 无法加载文件 C:\Users\win\AppData\Roaming\npm\babel.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/ go.micros

    babel报错:babel : 无法加载文件 C:\Users\win\AppData\Roaming\npm\babel.ps1,因为在此系统上禁止运行脚本.有关详细信息,请参阅 https:/ g ...

  9. NULL-safe equal null 索引 空字符串

    小结 1. mysql> INSERT INTO my_table (phone) VALUES (NULL); 有手机号但是不知道 mysql> INSERT INTO my_table ...

  10. ts中提示“绑定元素“routes”隐式具有“any”类型”

    思考单独的.ts和typescript框架在vscode层的差异,想想只有launch.json和tsconfig.json,一个个属性过去后,发现是tsconfig.json配置项"noI ...