HDOJ 4975 A simple Gaussian elimination problem.
和HDOJ4888是一样的问题,最大流推断多解
1.把ISAP卡的根本出不来结果,仅仅能把全为0或者全为满流的给特判掉......
2.在残量网络中找大于2的圈要用一种类似tarjian的方法从汇点開始找,推断哪些点没有到汇点
A simple Gaussian elimination problem.
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1170 Accepted Submission(s): 377
the table after that.
However Dragon's mom came back and found what he had done. She would give dragon a feast if Dragon could reconstruct the table, otherwise keep Dragon hungry. Dragon is so young and so simple so that the original numbers in the table are one-digit number (e.g.
0-9).
Could you help Dragon to do that?
There are three lines for each block. The first line contains two integers N(<=500) and M(<=500), showing the number of rows and columns.
The second line contains N integer show the sum of each row.
The third line contains M integer show the sum of each column.
output one line contains only: "So young!", otherwise (only one way to reconstruct the table) you should output: "So simple!".
3
1 1
5
5
2 2
0 10
0 10
2 2
2 2
2 2
Case #1: So simple!
Case #2: So naive!
Case #3: So young!
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const int maxn=20000;
const int maxm=500000;
const int INF=0x3f3f3f3f; struct Edge
{
int to,next,cap,flow;
}edge[maxm]; int Size,Adj[maxn];
int gap[maxn],dep[maxn],pre[maxn],cur[maxn]; void init()
{
Size=0; memset(Adj,-1,sizeof(Adj));
} void addedge(int u,int v,int w,int rw=0)
{
edge[Size].to=v; edge[Size].cap=w; edge[Size].next=Adj[u];
edge[Size].flow=0; Adj[u]=Size++;
edge[Size].to=u; edge[Size].cap=rw; edge[Size].next=Adj[v];
edge[Size].flow=0; Adj[v]=Size++;
} int sap(int start,int end,int N)
{
memset(gap,0,sizeof(gap));
memset(dep,0,sizeof(dep));
memcpy(cur,Adj,sizeof(Adj)); int u=start;
pre[u]=-1; gap[0]=N;
int ans=0; while(dep[start]<N)
{
if(u==end)
{
int Min=INF;
for(int i=pre[u];~i;i=pre[edge[i^1].to])
if(Min>edge[i].cap-edge[i].flow)
Min=edge[i].cap-edge[i].flow;
for(int i=pre[u];~i;i=pre[edge[i^1].to])
{
edge[i].flow+=Min;
edge[i^1].flow-=Min;
}
u=start;
ans+=Min;
continue;
}
bool flag=false;
int v;
for(int i=cur[u];~i;i=edge[i].next)
{
v=edge[i].to;
if(edge[i].cap-edge[i].flow&&dep[v]+1==dep[u])
{
flag=true;
cur[u]=pre[v]=i;
break;
}
}
if(flag)
{
u=v;
continue;
}
int Min=N;
for(int i=Adj[u];~i;i=edge[i].next)
if(edge[i].cap-edge[i].flow&&dep[edge[i].to]<Min)
{
Min=dep[edge[i].to];
cur[u]=i;
}
gap[dep[u]]--;
if(!gap[dep[u]]) return ans;
dep[u]=Min+1;
gap[dep[u]]++;
if(u!=start) u=edge[pre[u]^1].to;
}
return ans;
}
int n,m;
int a[maxn],b[maxn]; bool vis[maxn],no[maxn];
int Stack[maxm],stk; bool dfs(int u,int pre,bool flag)
{
vis[u]=true;
Stack[stk++]=u;
for(int i=Adj[u];~i;i=edge[i].next)
{
int v=edge[i].to;
if(v==pre) continue;
if(edge[i].flow>=edge[i].cap) continue;
if(!vis[v])
{
if(dfs(v,u,edge[i^1].cap>edge[i^1].flow)) return true;
}
else if(!no[v]) return true;
}
if(flag==false)
{
while(true)
{
int v=Stack[--stk];
no[v]=true;
if(v==u) break;
}
}
return false;
} int main()
{
int T_T,cas=1;
scanf("%d",&T_T);
while(T_T--)
{
scanf("%d%d",&n,&m);
int sum1=0,sum2=0;
for(int i=1;i<=n;i++)
{
scanf("%d",a+i); sum1+=a[i];
}
for(int i=1;i<=m;i++)
{
scanf("%d",b+i); sum2+=b[i];
}
if(sum1!=sum2)
{
printf("Case #%d: So naive!\n",cas++);
continue;
}
if(sum1==sum2&&((sum1==0)||(sum1==n*m*9)))
{
printf("Case #%d: So simple!\n",cas++);
continue;
} /*************build graph*****************/
init();
for(int i=1;i<=n;i++) addedge(0,i,a[i]);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
addedge(i,n+j,9);
for(int i=1;i<=m;i++) addedge(i+n,n+m+1,b[i]);
/*************build graph*****************/
int MaxFlow=sap(0,n+m+1,n+m+2); if(MaxFlow!=sum1)
{
printf("Case #%d: So naive!\n",cas++);
continue;
}
stk=0;
memset(vis,0,sizeof(vis));
memset(no,0,sizeof(no));
if(dfs(n+m+1,n+m+1,0))
{
printf("Case #%d: So young!\n",cas++);
}
else
{
printf("Case #%d: So simple!\n",cas++);
}
}
return 0;
}
HDOJ 4975 A simple Gaussian elimination problem.的更多相关文章
- HDU 4975 A simple Gaussian elimination problem.
A simple Gaussian elimination problem. Time Limit: 1000ms Memory Limit: 65536KB This problem will be ...
- hdu 4975 A simple Gaussian elimination problem.(网络流,推断矩阵是否存在)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4975 Problem Description Dragon is studying math. One ...
- hdu - 4975 - A simple Gaussian elimination problem.(最大流量)
意甲冠军:要在N好M行和列以及列的数字矩阵和,每个元件的尺寸不超过9,询问是否有这样的矩阵,是独一无二的N(1 ≤ N ≤ 500) , M(1 ≤ M ≤ 500). 主题链接:http://acm ...
- hdu 4975 A simple Gaussian elimination problem 最大流+找环
原题链接 http://acm.hdu.edu.cn/showproblem.php?pid=4975 这是一道很裸的最大流,将每个点(i,j)看作是从Ri向Cj的一条容量为9的边,从源点除法连接每个 ...
- hdu4975 A simple Gaussian elimination problem.(正确解法 最大流+删边判环)(Updated 2014-10-16)
这题标程是错的,网上很多题解也是错的. http://acm.hdu.edu.cn/showproblem.php?pid=4975 2014 Multi-University Training Co ...
- A simple Gaussian elimination problem.(hdu4975)网络流+最大流
A simple Gaussian elimination problem. Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65 ...
- A simple Gaussian elimination problem.
hdu4975:http://acm.hdu.edu.cn/showproblem.php?pid=4975 题意:给你一个n*m的矩阵,矩阵中的元素都是0--9,现在给你这个矩阵的每一行和每一列的和 ...
- hdu4975 A simple Gaussian elimination problem.(最大流+判环)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4975 题意:和hdu4888基本一样( http://www.cnblogs.com/a-clown/ ...
- BNU 4356 ——A Simple But Difficult Problem——————【快速幂、模运算】
A Simple But Difficult Problem Time Limit: 5000ms Memory Limit: 65536KB 64-bit integer IO format: %l ...
随机推荐
- Nutch2 WebPage写入数据库的过程分析
版本: Nutch 2.2.1 本文通过InjectJob来追踪webpage的定义.创建.传递.序列化.写入数据库的整个过程.从源码中摘录了重要的代码行,并标明其所在文件名.行号. 1. 定义 sc ...
- 洛谷——P2822 组合数问题
https://www.luogu.org/problem/show?pid=2822 题目描述 组合数C_n^mCnm表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3) 三 ...
- Apache Tez 0.7、0.83、 0.82 安装、调试笔记
———————————————————— 准备 Tez 编译环境 ———————————————————— 1 需要的支持 tez0.7 需要 Hadoop 2.60 以上 2 需要的 linux 相 ...
- CentOS 安装SVNclient
1.检查是已经安装了svn: # rpm -qa subversion subversion-1.7.14-6.el7.x86_64 卸载旧版本号的svn: # yum remove subversi ...
- 从头认识java-16.4 nio的读与写(ByteBuffer的使用)
这一章节我们来讨论一下nio的读与写. 1.nio的读 package com.ray.ch16; import java.io.IOException; import java.io.RandomA ...
- Android动态载入JAR包的实现方法
有时候我们须要使用动态更新技术,简单来说就是:当我们把开发jar包发送给用户后.假设后期升级了部分代码.这时让用户的jar包自己主动更新,而不是用户主动手动地去更新的技术就是动态更新.这个须要使用的技 ...
- Ubuntu16.04+GTX 1080Ti+CUDA 8.0+cuDNN+Tesnorflow1.0深度学习服务器安装之路
0.安装背景 系统:ubuntu 16.04 内核:4.4.0-140-generic GPU:GTX 1080Ti nvidia驱动版本: 384.111 cuda: CUDA 8.0 深度学习库c ...
- POJ 3178 凸包+DP (巨坑)
题意: 思路: 这题巨坑!!! 这题巨坑!!! 这题巨坑!!! 这题巨坑!!! 这题巨坑!!! (而且没有题解--.5555555--) 只能照着自己想的写了-- 先求出来凸包 求凸包的方法呢:先找出 ...
- jquery/zepto在插件编写上的几点区别
1. 自定义事件的命名空间 jq的时间命名空间是用点“.”,而zepto是用冒号“:” 如 //jquery $(this).trigger('cusevent.pluginname'); //zep ...
- MySQL日期数据类型和时间类型使用总结
转自: http://blog.chinaunix.net/space.php?uid=11327712&do=blog&id=32416 MySQL 日期类型:日期格式.所占存储空间 ...