日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU Redraw Beautiful Drawings 推断最大流是否唯一解

發布時間:2024/9/5 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU Redraw Beautiful Drawings 推断最大流是否唯一解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
點擊打開鏈接

Redraw Beautiful Drawings

Time Limit: 3000/1500 MS (Java/Others)????Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1660????Accepted Submission(s): 357


Problem Description Alice and Bob are playing together. Alice is crazy about art and she has visited many museums around the world. She has a good memory and she can remember all drawings she has seen.

Today Alice designs a game using these drawings in her memory. First, she matches K+1 colors appears in the picture to K+1 different integers(from 0 to K). After that, she slices the drawing into grids and there are N rows and M columns. Each grid has an integer on it(from 0 to K) representing the color on the corresponding position in the original drawing. Alice wants to share the wonderful drawings with Bob and she tells Bob the size of the drawing, the number of different colors, and the sum of integers on each row and each column. Bob has to redraw the drawing with Alice's information. Unfortunately, somtimes, the information Alice offers is wrong because of Alice's poor math. And sometimes, Bob can work out multiple different drawings using the information Alice provides. Bob gets confused and he needs your help. You have to tell Bob if Alice's information is right and if her information is right you should also tell Bob whether he can get a unique drawing.
Input The input contains mutiple testcases.

For each testcase, the first line contains three integers N(1 ≤ N ≤ 400) , M(1 ≤ M ≤ 400) and K(1 ≤ K ≤ 40).
N integers are given in the second line representing the sum of N rows.
M integers are given in the third line representing the sum of M columns.

The input is terminated by EOF.
Output For each testcase, if there is no solution for Bob, output "Impossible" in one line(without the quotation mark); if there is only one solution for Bob, output "Unique" in one line(without the quotation mark) and output an N * M matrix in the following N lines representing Bob's unique solution; if there are many ways for Bob to redraw the drawing, output "Not Unique" in one line(without the quotation mark).
Sample Input 2 2 4 4 2 4 2 4 2 2 2 2 5 0 5 4 1 4 3 9 1 2 3 3
Sample Output Not Unique Impossible Unique 1 2 3 3
Author Fudan University
給你一個n*m的矩陣,然后個格子里面有一個小于k的數,而且告訴你每行和每列的和,讓你求是否存在解,并推斷是否唯一。 建圖:源點和每行連邊,容量為每行的和。每列和匯點連邊,容量為每列的和。每行和每列連邊,容量為k。 推斷是否存在唯一解,在殘留網絡里面是否能找到一個環。 //515MS 7304K #include<stdio.h> #include<string.h> #define M 1007 int s,t,n,m,k,sum1,sum2; int row[M],col[M],vis[M],g[M][M]; const int MAXN=20010;//點數的最大值 const int MAXM=880010;//邊數的最大值 const int INF=0x3f3f3f3f; struct Node {int from,to,next;int cap; }edge[MAXM]; int tol; int head[MAXN]; int dis[MAXN]; int gap[MAXN];//gap[x]=y :說明殘留網絡中dis[i]==x的個數為y void init() {tol=0;memset(head,-1,sizeof(head)); } void addedge(int u,int v,int w) {edge[tol].from=u;edge[tol].to=v;edge[tol].cap=w;edge[tol].next=head[u];head[u]=tol++;edge[tol].from=v;edge[tol].to=u;edge[tol].cap=0;edge[tol].next=head[v];head[v]=tol++; } void BFS(int start,int end) {memset(dis,-1,sizeof(dis));memset(gap,0,sizeof(gap));gap[0]=1;int que[MAXN];int front,rear;front=rear=0;dis[end]=0;que[rear++]=end;while(front!=rear){int u=que[front++];if(front==MAXN)front=0;for(int i=head[u];i!=-1;i=edge[i].next){int v=edge[i].to;if(dis[v]!=-1)continue;que[rear++]=v;if(rear==MAXN)rear=0;dis[v]=dis[u]+1;++gap[dis[v]];}} } int SAP(int start,int end) {int res=0,nn=end+1;BFS(start,end);int cur[MAXN];int S[MAXN];int top=0;memcpy(cur,head,sizeof(head));int u=start;int i;while(dis[start]<nn){if(u==end){int temp=INF;int inser;for(i=0;i<top;i++)if(temp>edge[S[i]].cap){temp=edge[S[i]].cap;inser=i;}for(i=0;i<top;i++){edge[S[i]].cap-=temp;edge[S[i]^1].cap+=temp;}res+=temp;top=inser;u=edge[S[top]].from;}if(u!=end&&gap[dis[u]-1]==0)//出現斷層,無增廣路break;for(i=cur[u];i!=-1;i=edge[i].next)if(edge[i].cap!=0&&dis[u]==dis[edge[i].to]+1)break;if(i!=-1){cur[u]=i;S[top++]=i;u=edge[i].to;}else{int min=nn;for(i=head[u];i!=-1;i=edge[i].next){if(edge[i].cap==0)continue;if(min>dis[edge[i].to]){min=dis[edge[i].to];cur[u]=i;}}--gap[dis[u]];dis[u]=min+1;++gap[dis[u]];if(u!=start)u=edge[S[--top]].from;}}return res; }void build() {sum1=0,sum2=0;for(int i=1;i<=n;i++){scanf("%d",&row[i]);sum1+=row[i];addedge(s,i,row[i]);}for(int i=1;i<=m;i++){scanf("%d",&col[i]);sum2+=col[i];addedge(n+i,t,col[i]);}for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)addedge(i,n+j,k); }bool iscycle(int u,int fa) {for(int i=head[u];i!=-1;i=edge[i].next){if(i==(fa^1))continue;if(edge[i].cap){if(vis[edge[i].to])return true;vis[edge[i].to]=true;if(iscycle(edge[i].to,i))return true;vis[edge[i].to]=false;}}return false; } void solve() {if(sum1!=sum2){printf("Impossible\n");return;}int anss=SAP(s,t);//printf("anss=%d\n",anss);if(anss!=sum1){printf("Impossible\n");return;}memset(vis,false,sizeof(vis));int flag=0;for(int i=1;i<=n;i++)//推斷殘留網絡是否存在環if(iscycle(i,-1)){flag=1;break;}if(flag)printf("Not Unique\n");else{printf("Unique\n");for(int u=1;u<=n;u++)for(int i=head[u];i!=-1;i=edge[i].next){int v=edge[i].to;if(v>n&&v<=n+m)g[u][v-n]=k-edge[i].cap;}for(int i=1;i<=n;i++){for(int j=1;j<m;j++)printf("%d ",g[i][j]);printf("%d\n",g[i][m]);}} } int main() {while(scanf("%d%d%d",&n,&m,&k)!=EOF){s=0,t=n+m+1;init();build();solve();} }

轉載于:https://www.cnblogs.com/mengfanrong/p/4295453.html

總結

以上是生活随笔為你收集整理的HDU Redraw Beautiful Drawings 推断最大流是否唯一解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产ts在线播放 | 91不卡在线 | 波多野一区 | 免费一区二区三区视频在线 | 亚洲视频区 | 精品国产av色一区二区深夜久久 | av国产网站 | 骚视频在线观看 | 黄网站免费观看 | 69人妻精品久久无人专区 | 日韩av不卡一区 | 四虎影视国产精品 | 亚洲中文字幕97久久精品少妇 | 日韩每日更新 | 国产精品香蕉在线观看 | 午夜激情视频在线播放 | 久久精品三级视频 | 波多野结衣 久久 | 艳妇乳肉豪妇荡乳av | 久久国产精品亚洲 | 91操人视频| 免费久久av | 欧美在线视频一区二区 | 国产一区二区四区 | 免费黄色入口 | 五月深爱婷婷 | 韩国主播青草55部完整 | 亚洲一区二区三区欧美 | 麻豆一区二区三区精品视频 | 亚洲精品 日韩无码 | 国产毛片毛片毛片毛片毛片 | 小嫩女直喷白浆 | 91久久综合亚洲鲁鲁五月天 | 欧美黄色激情 | 2020狠狠干 | 欧美精品亚洲精品 | 国产三级中文字幕 | 色视频一区二区 | 日韩资源站 | 一区二区三区四区视频在线观看 | 免费观看亚洲视频 | 在线免费观看黄视频 | 国产高清免费av | 久久99精品久久久久久园产越南 | wwwxxx日本 | 日本一区二区三区免费看 | 热久久最新 | 99网站 | www.五月婷| 久久青草免费视频 | 亚洲高清久久 | jzjzz成人免费视频 | 久久久久一区二区精码av少妇 | 亚洲av毛片基地 | 国产免费观看久久黄av片 | 日韩欧美中文字幕一区二区三区 | 久久久精品影院 | 国产成人免费在线 | 日韩三级中文字幕 | 日本肉体xxxx裸体xxx免费 | 不卡一区二区在线观看 | 国产一区二区黑人欧美xxxx | 东方欧美色图 | 神马午夜国产 | 中文在线观看免费网站 | 巨茎人妖videos另类 | 中国女人特级毛片 | 韩国主播青草55部完整 | 亚洲图片欧美视频 | 欧洲精品视频在线观看 | 一级成人黄色片 | 欧美性猛交 xxxx | 啊灬啊灬啊灬秀婷 | 欧美jizzhd精品欧美18 | 久久久欧美精品 | 国产精品15p | 高h乱l高辣h文短篇h | 国产视频一区二区在线 | 香蕉久久网站 | 精品国产网 | 91视频成人 | 成熟的女同志hd | 久久久极品 | 天天影视色| 国模小黎自慰gogo人体 | 国产一级影片 | 2020自拍偷拍| 僵尸叔叔在线观看国语高清免费观看 | 国产99久久九九精品无码 | 成年人黄色录像 | 久久婷婷成人综合色 | 欧美专区在线观看 | 天堂在线观看 | 欧美一区二区三区久久综合 | 天天艹天天操 | 久久国产片 | 五月天色丁香 | 国产成人av一区二区三区在线观看 | 丰满的女邻居 |