【u033】地震逃生
Time Limit: 1 second
Memory Limit: 64 MB
【问题描述】
汶川地震发生时,四川**中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点
,m条边。1号点为教室,n号点为安全地带,每条边都只能容纳一定量的学生,超过楼就要倒塌,由于人数太多,校长决定让同学们分
成几批逃生,只有第一批学生全部逃生完毕后,第二批学生才能从1号点出发逃生,现在请你帮校长算算,每批最多能运出多少个学生
,x名学生分几批才能运完。
【输入格式】
第一行3个整数n,m,x(x<2^31,n<=200,m<=2000);以下m行,每行三个整数a,b,c(a1,a<>b,0描述一条边,分别代表从a点到b点有一条边,且可容纳c名学生。
【输出格式】
两个整数,分别表示每批最多能运出多少个学生,x名学生分几批才能运完。如果无法到达目的地(n号点)则输出“Orz Ni Jinan Saint Cow!”
【样例解释】
比如有图
1 2 100
2 3 1
100个学生先冲到2号点,然后1个1个慢慢沿2-3边走过去 18神牛规定这样是不可以的…… 也就是说,每批学生必须同时从起点出发,并且同时到达终点
Sample Input1
6 7 7
1 2 1
1 4 2
2 3 1
4 5 1
4 3 1
3 6 2
5 6 1
Sample Output1
3 3
【题目链接】:http://noi.qz5z.com/viewtask.asp?id=u033
【题解】
让你求最大流,然后用总人数除最大流就是分批的批数;
如果最后总流为0则说明没有到达n号节点的路径;
数据中有个坑;输入的时候没有容量;
卡手动输入啊QAQ;
【完整代码】
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
using namespace std;
const int MAXN = 200+10;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {0,0,0,-1,1};
const double pi = acos(-1.0);
const int INF = 2100000000;
int n,m,x;
int flow[MAXN][MAXN];
int pre[MAXN];
bool mark[MAXN];
queue <int> dl;
void rel(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t) && t!='-') t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
}
void rei(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)&&t!='-') t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
}
int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(n);rei(m);rei(x);
for (int i = 1;i <= m;i++)
{
int a,b,c;
rei(a);rei(b);scanf("%d",&c);
flow[a][b]+=c;
}
int f = 0;
while (true)
{
memset(mark,false,sizeof(mark));
memset(pre,0,sizeof(pre));
while (!dl.empty()) dl.pop();
mark[1] = true;
dl.push(1);
while (!dl.empty())
{
int x = dl.front();
if (x==n)
break;
dl.pop();
for (int i = 1;i <= n;i++)
if (flow[x][i] && !mark[i])
{
mark[i] = true;
dl.push(i);
pre[i] = x;
}
}
if (!mark[n])
break;
int i = n,mi = INF;
while (i!=1)
{
mi = min(mi,flow[pre[i]][i]);
i = pre[i];
}
i = n;
while (i!=1)
{
flow[pre[i]][i]-=mi;
flow[i][pre[i]]+=mi;
i = pre[i];
}
f+=mi;
}
if (f==0)
puts("Orz Ni Jinan Saint Cow!");
else
printf("%d %d\n",f,((x%f)==0)?x/f:x/f+1);
return 0;
}
【u033】地震逃生的更多相关文章
- 洛谷 P10P1343 地震逃生 改错
P1343 地震逃生 题目描述 汶川地震发生时,四川**中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有\(n\)个点,\(m\)条边.1号点为教室,\ ...
- 洛谷 P1343 地震逃生
P1343地震逃生 题目描述 汶川地震发生时,四川**中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点,m条边.1号点为教室,n号点为安全地带,每 ...
- 「洛谷P1343」地震逃生 解题报告
P1343 地震逃生 题目描述 汶川地震发生时,四川XX中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点,m条边.1号点为教室,n号点为安全地带, ...
- P1343 地震逃生(最大流板题)
P1343 地震逃生 题目描述 汶川地震发生时,四川**中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点,m条边.1号点为教室,n号点为安全地带, ...
- LG1343 地震逃生
题意 汶川地震发生时,四川**中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点,m条边.1号点为教室,n号点为安全地带,每条边都只能容纳一定量的学 ...
- P1343 地震逃生
题目描述 汶川地震发生时,四川**中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点,m条边.1号点为教室,n号点为安全地带,每条边都只能容纳一定量 ...
- 【luogu P1343 地震逃生】 题解
题目链接:https://www.luogu.org/problemnew/show/P1343 菜 #include <queue> #include <cstdio> #i ...
- 【洛谷P1343】地震逃生
一道傻吊的网络流题,wori我写的读入优化怎么老T? 远离读入优化报平安? #include<bits/stdc++.h> #define N 4005 #define inf 10000 ...
- [Luogu1343]地震逃生 最大流
题目链接:https://www.luogu.org/problem/show?pid=1343 dinic跑最大流. #include<cstdio> #include<cstri ...
随机推荐
- 云数据库RDS存储能力进化解析!
数据库是企业IT系统的核心,其性能表现会直接影响整体业务系统的性能表现,而影响数据库性能因素包括系统架构设计.应用程序业务SQL语句.数据库参数优化配置.数据库运行的资源能力.系统架构设计和应用程序业 ...
- WPF TextBox提示文字设定
WPF TextBox框提示文字,鼠标划入提示文字消失 <TextBox Width=" VerticalContentAlignment="Center" Bor ...
- XPath 获取两个node中间的HTML Nodes
XPath 获取两个node中间的HTML Nodes 2015-06-01 16:42 972人阅读 评论(0) 收藏 举报 //div[@id="Recipe"]//h5[co ...
- LeetCode86 Partition List
题目: Given a linked list and a value x, partition it such that all nodes less than x come before node ...
- VS开发ArcEngine时的一个异常信息——“ArcGIS version not specified. You must call RuntimeManager.Bind before creating any ArcGIS components.”
问题描述:程序报错“ArcGIS version not specified. You must call RuntimeManager.Bind before creating any ArcGIS ...
- mysql 查询当天、昨天、本周、上周、本月、上月、今年、去年数据
mysql查询今天.昨天.7天.近30天.本月.上一月 数据 今天 select * from 表名 where to_days(时间字段名) = to_days(now()); 昨天 SELECT ...
- 2019-7-20-win10-uwp-使用-msbuild-命令行编译-UWP-程序
title author date CreateTime categories win10 uwp 使用 msbuild 命令行编译 UWP 程序 lindexi 2019-07-20 21:56:2 ...
- ASCII代码表
>>ASCII代码表<<
- @noi.ac - 493@ trade
目录 @description@ @solution@ @part - 1@ @part - 2@ @part - 3@ @part - 4@ @accepted code@ @details@ @d ...
- css3鼠标移动图片上移效果
css3的功能真是很强大,学无止境,不多说,直接上代码 css部分: <style> ;;} .text-center{text-align:center} .col_cont{width ...