A - Promotions
来源:互联网 发布:华为视频会议软件 编辑:程序博客网 时间:2024/05/02 14:11
题目详见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 1000000007struct 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;}
0 0
- A - Promotions
- GYM 101128 A.Promotions(dfs)
- GYM 101128 A.Promotions(dfs)
- 组队赛 A Promotions 深搜+逆向思维
- GYM 101128 A.Promotions【思维+暴力】
- Promotions Gym
- Promotions Gym
- 14.2.6 Numeric promotions
- 关于Integral Promotions
- 整型提升(integral promotions)
- LA 7324 Promotions(bitset)
- UVALive 7272 Promotions
- 14.2.6.1 Unary numeric promotions
- 14.2.6.2 Binary numeric promotions
- UVALive 7272 Promotions(拓扑排序)
- Sample Bowser promotions at MSDN main page
- UVALive 7272 Promotions【拓扑排序】【bitset】
- UVA Live 7272 Promotions 拓扑排序
- android的消息处理机制
- 用sqlmap验证是否存在sql注入
- 如何用最恰当的方式做出正确的选择和最优地解决问题
- LibGDX_6.3: 常用系统控件: 按钮(Button)
- iOS开发中的小问题,不断更新
- A - Promotions
- android 监听上下左右键的功能实现
- 关于博客系统用户关注功能的实现
- How to Increase Your Professional Reputation
- A. Two Bases
- view事件解析(上)
- Hibernate学习
- JDBC连接MYSQL数据库示例
- 深度学习(二十)基于Overfeat的图片分类、定位、检测