UVALive - 5843 Furniture Factory
来源:互联网 发布:java中list用法 编辑:程序博客网 时间:2024/06/04 18:34
对每个时间点添加到终点流为工人数量,从起点对每个工作添加流为所需时间,对工作的时间点添加流为1.
网络流
#include<cstdio>#include<iostream>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>#include<string>#include<map>#include<set>#include<vector>#include<queue>#include<stack>using namespace std;#define rep(i, a, b) for (int i = (a); i <= (b); ++i)#define red(i, a, b) for (int i = (a); i >= (b); --i)#define clr( x , y ) memset(x,y,sizeof(x))#define sqr(x) ((x) * (x))#define mp make_pair#define pb push_backtypedef long long lint;int t , n , m , sum , s[110] , d[110] , w[110];bool v[110][510];int a[750] , vh[750] , h[750];struct nodd{ int y , d , n;} b[300000];void add(int x,int y,int d){ b[++t].y = y; b[t].d = d; b[t].n = a[x]; a[x] = t; b[++t].y = x; b[t].d = 0; b[t].n = a[y]; a[y] = t;}int sap(int t,int d){ int minh = 650 , max = d , x , y; if ( t == 610 ) return d; for ( int p = a[t]; p; p = b[p].n ) if ( b[p].d ) { y = b[p].y; if ( h[y] + 1 == h[t] ) { x = sap( y , max > b[p].d ? b[p].d : max ); b[p].d -= x; b[ p ^ 1 ].d += x; max -= x; if ( !max || h[0] > 650 ) return d - max; } if ( h[y] < minh ) minh = h[y]; } if ( max == d ) { if ( !( -- vh[h[t]] ) ) h[0] = 660; vh[ h[t] = minh + 1 ] ++; } return d - max;}void init(){ scanf("%d%d",&n,&m); rep(i,1,m) scanf("%d%d%d",&s[i],&w[i],&d[i]); clr( v , 0 ); clr( a , 0 ); clr( h , 0 ); clr( vh , 0 ); vh[0] = 700; sum = 0; t = 1; rep(i,1,m) sum += w[i]; rep(i,1,m) rep(j,s[i],d[i]-1) add( i + 500 , j , 1 ); rep(i,1,m) add( 0 , i + 500 , w[i] ); rep(i,1,500) add( i , 610 , n );}void work(){ while ( h[0] < 610 ) sum -= sap( 0 , 10000000 ); if ( sum ) { puts("0"); return; } rep(i,1,m) for ( int p = a[i+500]; p ; p = b[p].n ) if ( !b[p].d ) v[i][b[p].y] = 1; vector < int > g[110]; rep(i,1,m) { rep(j,1,500) if ( v[i][j] && !v[i][j-1] ) { int x = j + 1; while ( v[i][x] ) x ++; g[i].pb( j ); g[i].pb( x ); } } rep(i,1,m) { int x = g[i].size(); printf("%d",x/2); rep(j,0,x-1) printf(" %d",g[i][j]); puts(""); }}int main(){ int t; cin >> t; while ( t -- ) { init(); work(); } return 0;}
0 0
- UVALive - 5843 Furniture Factory
- 城市街具 street furniture
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- Android 设置状态栏 显示 或 隐藏 SystemUI flag
- 连接池简介
- Eclipse创建Maven Web工程并实现Tomcat热部署
- 美国旅游签证办理流程
- 推荐程序开发书单
- UVALive - 5843 Furniture Factory
- 好习惯是一种财富
- iOS—字符串显示不同的颜色
- hdu2874-Connections between cities (LCA/离线tarjan)
- 2.Add Two Numbers
- hdu 1877 Java 水题系列
- 没有伞的孩子必须努力奔跑
- 移动app接口编程技术-学习实现之PHP类其他特性
- 八皇后问题-回溯法