日韩性视频-久久久蜜桃-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 推断最大流是否唯一解的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 亚洲精品999 | 新91在线 | 亚洲精品区 | 亚洲精品免费电影 | 国产免费一区二区三区网站免费 | xxxx日本黄色 | 亚洲 欧美 另类 综合 偷拍 | 无码人妻少妇伦在线电影 | 字幕网在线 | 国产精品乱码一区二区三区 | 51精品国产人成在线观看 | 久久亚洲av午夜福利精品一区 | 国产精品视频1区 | jizz性欧美15| 一级黄色大片在线观看 | 8ppav| 亚洲图片偷拍区 | 天天插天天射 | 亚洲激情中文 | 欧美一级在线观看视频 | avt天堂网| 黄色片亚洲 | jizz一区二区 | 果冻传媒18禁免费视频 | 快色在线 | 伊人伊网| 精品在线免费视频 | www.日本在线视频 | 日韩视频免费在线播放 | 精品久久久久久无码中文野结衣 | 日日干夜 | 无套在线观看 | 黑巨茎大战欧美白妞 | julia中文字幕在线 | 国产精品亚洲lv粉色 | 国产极品视频在线观看 | 久久久久99精品成人片我成大片 | 欧美日韩人妻精品一区二区 | 国产小视频免费在线观看 | 17c国产精品一区二区 | 精品一区二区三区免费毛片爱 | 波多野结衣之潜藏淫欲 | 白浆av| 爱插美女网 | 日韩精品av一区二区三区 | 婷婷午夜精品久久久久久性色av | 国产真人做爰毛片视频直播 | 国产3p精品一区 | 男人天堂2020 | 日本女优在线看 | 国产乱码一区 | 顶臀精品视频www | 一个人在线免费观看www | 欧美肉丝袜videos办公室 | 多毛的亚洲人毛茸茸 | 午夜寂寞福利 | 丁香婷婷一区二区三区 | 一级做a爰片 | 亚洲日本在线观看视频 | 国产伦精品一区二区三 | 91成人午夜 | v片在线看| 精品久久久久一区二区 | 777奇米视频 | 91精品视频免费在线观看 | 中文字幕第22页 | 好吊妞视频在线观看 | 日韩免 | 青草视频在线观看免费 | av一级黄色 | 光棍影院av | 肉嫁高柳在线 | 影音先锋在线播放 | 美女又爽又黄免费 | 欧美与黑人午夜性猛交久久久 | 国产精品视频第一页 | 日韩毛片高清在线播放 | 老司机深夜福利影院 | 丁香啪啪综合成人亚洲 | 国产a久久麻豆入口 | 男生舔女生的屁股 | 国产精品美女毛片真酒店 | 韩日一区 | 国产美女精品视频国产 | 97精品在线视频 | 国产精品一线二线三线 | 精品国产乱码久久久久久蜜臀网站 | 一本色道久久综合亚洲精品酒店 | 91久久爽久久爽爽久久片 | sao浪受的饥渴日常 91免费入口 | 欧美日韩激情 | 久久艹国产 | 成人看片免费 | 国产无码久久精品 | 国产毛片久久久久久国产毛片 | 四虎一国产精品一区二区影院 | 日韩不卡一区二区 | 国产一区影院 | 国产精品99无码一区二区 |