首页 > 代码库 > hdu 4975 A simple Gaussian elimination problem.(网络流,判断矩阵是否存在)
hdu 4975 A simple Gaussian elimination problem.(网络流,判断矩阵是否存在)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4975
Problem Description
Dragon is studying math. One day, he drew a table with several rows and columns, randomly wrote numbers on each elements of the table. Then he counted the sum of each row and column. Since he thought the map will be useless after he got the sums, he destroyed 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?
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?
Input
The first line of input contains only one integer, T(<=30), the number of test cases. Following T blocks, each block describes one test case.
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.
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
Each output should occupy one line. Each line should start with "Case #i: ", with i implying the case number. For each case, if we cannot get the original table, just output: "So naive!", else if we can reconstruct the table by more than one ways, you should output one line contains only: "So young!", otherwise (only one way to reconstruct the table) you should output: "So simple!".
Sample Input
3 1 1 5 5 2 2 0 10 0 10 2 2 2 2 2 2
Sample Output
Case #1: So simple! Case #2: So naive! Case #3: So young!
Source
2014 Multi-University Training Contest 10
题意:
给出每行每列的和,问是否存在这样的表格;每个小格放的数字只能是0--9。
代码如下:(套用别人HDU4888的模板)
#include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> #include<math.h> #include<queue> using namespace std; #define ll __int64 #define eps 1e-8 const ll Mod=(1e9+7); const int maxn = 510; const int maxm = 50100; int n,m,k; int r[maxn],c[maxn]; int ma[maxn][maxn]; const int maxnode = 10000 + 5; const int maxedge = 2000000 + 5; const int oo = 1000000000; int node, src, dest, nedge; int head[maxnode], point[maxedge], next1[maxedge], flow[maxedge], capa[maxedge];//point[x]==y表示第x条边连接y,head,next为邻接表,flow[x]表示x边的动态值,capa[x]表示x边的初始值 int dist[maxnode], Q[maxnode], work[maxnode];//dist[i]表示i点的等级 void init(int _node, int _src, int _dest){//初始化,node表示点的个数,src表示起点,dest表示终点 node = _node; src = http://www.mamicode.com/_src;>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。