离奇90分

P3254 圆桌问题

@[fmx0219](/space/show?uid=112219) ~~请不要用超大字体来显示头文件的重要性~~
by xht @ 2019-04-24 21:39:47


@[fmx0219](/space/show?uid=112219) 您为什么要这样发代码
by loceaner @ 2019-04-24 21:43:50


希望更丰富的展现?使用Markdown
by hehezhou @ 2019-04-24 21:43:56


望丰展?使MD
by Koakuma @ 2019-04-24 21:46:17


@[fmx0219](/space/show?uid=112219) t=n+m+1; cin>>n>>m; n,m都没输入就赋t的值了?
by 我不认识你 @ 2019-04-24 22:09:49


数组开小了
by fmx0219 @ 2019-04-25 22:15:00


```cpp include<bits/stdc++.h> using namespace std; int n,m,s,t; int inf=1<<30; struct nod { int x,y; }b[250],a[250]; bool cmp(nod a,nod b) { return a.x>b.x; } struct node { int ver; int val; int next; }e[3000005]; int h[3000005],cnt=1,d[300005]; queue<int> q; void add(int x,int y,int z) { e[++cnt].ver=y; e[cnt].val=z; e[cnt].next=h[x]; h[x]=cnt; e[++cnt].ver=x; e[cnt].val=0; e[cnt].next=h[y]; h[y]=cnt; } bool bfs() { memset(d,0,sizeof(d)); while(q.size()) q.pop(); q.push(s);d[s]=1; while(q.size()) { int x=q.front(); q.pop(); for(int i=h[x];i;i=e[i].next) { int y=e[i].ver; if(e[i].val&&!d[y]) { q.push(y); d[y]=d[x]+1; if(y==t) return 1; } } } return 0; } int dfs(int x,int y) { if(x==t) { return y; } int r=y,k; for(int i=h[x];i&&r;i=e[i].next) { int yy=e[i].ver; if(e[i].val&&d[yy]==d[x]+1) { k=dfs(yy,min(e[i].val,r)); e[i].val-=k; e[i^1].val+=k; r-=k; } } return y-r; } vector<int> l[10005]; int main() { t=n+m+1; cin>>n>>m; int sun=0; for(int i=1;i<=n;i++) { cin>>a[i].x; add(s,i,a[i].x); sun+=a[i].x; a[i].y=i; } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { add(i,j+n,1); } } for(int i=1;i<=m;i++) { cin>>b[i].x; add(i+n,t,b[i].x); b[i].y=i; } int f=0,ans=0; while(bfs()) { while((f=dfs(s,inf))) { ans+=f; } } if(ans!=sun) { cout<<'0'; return 0; } cout<<'1'<<endl; sort(a+1,a+1+n,cmp); for(int i=1;i<=n;i++) { sort(b+1,b+1+m,cmp); for(int j=1;j<=a[i].x;j++) { if(b[j].x==0) continue; b[j].x--; l[a[i].y].push_back(b[j].y); } } for(int i=1;i<=n;i++) { for(int j=0;j<l[i].size();j++) { cout<<l[i][j]<<' '; } cout<<endl; } return 0; } ```
by nth_element @ 2019-08-07 20:49:16


|