HDU 3663 Power Stations
来源:互联网 发布:腾讯软件管家下载 编辑:程序博客网 时间:2024/05/29 10:01
Problem Description
There are N towns in our country, and some of them are connected by electricity cables. It is known that every town owns a power station. When a town’s power station begins to work, it will provide electric power for this town and the neighboring towns which are connected by cables directly to this town. However, there are some strange bugs in the electric system –One town can only receive electric power from no more than one power station, otherwise the cables will be burned out for overload.
The power stations cannot work all the time. For each station there is an available time range. For example, the power station located on Town 1 may be available from the third day to the fifth day, while the power station on Town 2 may be available from the first day to the forth day. You can choose a sub-range of the available range as the working time for each station. Note that you can only choose one sub-range for each available range, that is, once the station stops working, you cannot restart it again. Of course, it is possible not to use any of them.
Now you are given all the information about the cable connection between the towns, and all the power stations’ available time. You need to find out a schedule that every town will get the electricity supply for next D days, one and only one supplier for one town at any time.
The power stations cannot work all the time. For each station there is an available time range. For example, the power station located on Town 1 may be available from the third day to the fifth day, while the power station on Town 2 may be available from the first day to the forth day. You can choose a sub-range of the available range as the working time for each station. Note that you can only choose one sub-range for each available range, that is, once the station stops working, you cannot restart it again. Of course, it is possible not to use any of them.
Now you are given all the information about the cable connection between the towns, and all the power stations’ available time. You need to find out a schedule that every town will get the electricity supply for next D days, one and only one supplier for one town at any time.
Input
There are several test cases. The first line of each test case contains three integers, N, M and D (1 <= N <= 60, 1 <= M <= 150, 1 <= D <= 5), indicating the number of towns is N, the number of cables is M, and you should plan for the next D days.
Each of the next M lines contains two integers a, b (1 <= a, b <= N), which means that Town a and Town b are connected directly. Then N lines followed, each contains two numbers si and ei, (1 <= si <= ei <= D) indicating that the available time of Town i’s power station is from the si-th day to the ei-th day (inclusive).
Each of the next M lines contains two integers a, b (1 <= a, b <= N), which means that Town a and Town b are connected directly. Then N lines followed, each contains two numbers si and ei, (1 <= si <= ei <= D) indicating that the available time of Town i’s power station is from the si-th day to the ei-th day (inclusive).
Output
For each test case, if the plan exists, output N lines. The i-th line should contain two integers ui and vi, indicating that Town i’s power station should work from the ui-th day to vi-day (inclusive). If you didn’t use this power station at all, set ui = vi = 0.
If the plan doesn’t exist, output one line contains “No solution” instead.
Note that the answer may not be unique. Any correct answers will be OK.
Output a blank line after each case.
If the plan doesn’t exist, output one line contains “No solution” instead.
Note that the answer may not be unique. Any correct answers will be OK.
Output a blank line after each case.
Sample Input
3 3 51 22 33 11 51 51 54 4 51 22 33 44 11 51 51 51 5
Sample Output
1 50 00 0No solution建个图跑dlx精确覆盖#include<cstdio>#include<vector>#include<cmath>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;const ll maxn = 1005;int T, n, m, x, y, t, X, Y,mp[maxn][maxn],tot,u[maxn],v[maxn],p[maxn][3];inline void read(int &ret){char c;do {c = getchar();} while (c < '0' || c > '9');ret = c - '0';while ((c = getchar()) >= '0' && c <= '9')ret = ret * 10 + (c - '0');}struct DLX{#define maxn 500005#define F(i,A,s) for (int i=A[s];i!=s;i=A[i])int L[maxn], R[maxn], U[maxn], D[maxn];int row[maxn], col[maxn], ans[maxn], cnt[maxn];int n, m, num, sz;void add(int now, int l, int r, int u, int d, int x, int y){L[now] = l;R[now] = r;U[now] = u;D[now] = d; row[now] = x; col[now] = y;}void reset(int n, int m){num = 0x7FFFFFFF;this->n = n;this->m = m;for (int i = 0; i <= m; i++){add(i, i - 1, i + 1, i, i, 0, i);cnt[i] = 0;}L[0] = m; R[m] = 0; sz = m + 1;}void insert(int x, int y){int ft = sz - 1;if (row[ft] != x){add(sz, sz, sz, U[y], y, x, y);U[D[sz]] = sz; D[U[sz]] = sz;}else{add(sz, ft, R[ft], U[y], y, x, y);R[L[sz]] = sz; L[R[sz]] = sz;U[D[sz]] = sz; D[U[sz]] = sz;}++cnt[y];++sz;}//精确覆盖void remove(int now){R[L[now]] = R[now];L[R[now]] = L[now];F(i, D, now) F(j, R, i){D[U[j]] = D[j];U[D[j]] = U[j];--cnt[col[j]];}}void resume(int now){F(i, U, now)F(j, L, i){D[U[j]] = j;U[D[j]] = j;++cnt[col[j]];}R[L[now]] = now;L[R[now]] = now;}bool dfs(int x){//if (x + A() >= num) return;if (!R[0]) { num = min(num, x); return true; }int now = R[0];F(i, R, 0) if (cnt[now]>cnt[i]) now = i;remove(now);F(i, D, now){ans[x] = row[i];F(j, R, i) remove(col[j]);if (dfs(x + 1)) return true;F(j, L, i) resume(col[j]);}resume(now);return false;}//精确覆盖//重复覆盖void Remove(int now){F(i, D, now){L[R[i]] = L[i];R[L[i]] = R[i];}}void Resume(int now){F(i, U, now) L[R[i]] = R[L[i]] = i;}int vis[maxn];int flag[maxn];int A(){int dis = 0;F(i, R, 0) vis[i] = 0;F(i, R, 0) if (!vis[i]){dis++;vis[i] = 1;F(j, D, i) F(k, R, j) vis[col[k]] = 1;}return dis;}void Dfs(int x){if (!R[0]) num = min(num, x);else if (x + A()<num){int now = R[0];F(i, R, 0) if (cnt[now]>cnt[i]) now = i;F(i, D, now){Remove(i); F(j, R, i) Remove(j);Dfs(x + 1);F(j, L, i) Resume(j); Resume(i);}}}//重复覆盖void display(int x){for (int i=0;i<num;i++){u[p[ans[i]][0]]=p[ans[i]][1];v[p[ans[i]][0]]=p[ans[i]][2];}for (int i=1;i<=x;i++){printf("%d %d\n",u[i],v[i]);}}}dlx;int main(){//read(T);while (~scanf("%d%d%d", &n, &m, &t)){dlx.reset(n * ((t+1)*t/2+1), n * t + n);memset(mp,0,sizeof(mp));while (m--){scanf("%d%d",&x,&y);mp[x][y]=mp[y][x]=1;}tot=0;for (int i=1;i<=n;i++){scanf("%d%d",&x,&y);dlx.insert(++tot,i);p[tot][0]=i;p[tot][1]=p[tot][2]=0;for (int j=1;j<=t;j++)for (int k=j;k<=t;k++){++tot;if (x<=j&&y>=k) {dlx.insert(tot,i);p[tot][0]=i;p[tot][1]=j;p[tot][2]=k;for (int two=1;two<=n;two++)if (mp[i][two]||i==two)for (int one=j;one<=k;one++){dlx.insert(tot,one*n+two);}}}}if (dlx.dfs(0)) dlx.display(n);else printf("No solution\n");putchar(10);}return 0;}
0 0
- HDU 3663 Power Stations
- hdu 3663 Power Stations【DLX】
- 【HDU】3663 Power Stations 精确覆盖
- [DLX精确覆盖] hdu 3663 Power Stations
- 【HDU 3663】 Power Stations 【精确覆盖】
- HDU 3663 Power Stations DLX精确覆盖
- DLX(精确覆盖) HDU 3663 Power Stations
- HDU 3663 Power Stations 解题报告(Dancing Link)
- hdu 3663 Power Stations(精确覆盖 Dancing Links 模版)
- HDU 3663 Power Stations(Dancing_Links精确覆盖)
- HDU3663-Power Stations
- HDU3663--Power Stations(Dancing Links)
- HDOJ3663-Power Stations,DLX精确覆盖
- HDU 2485 Destroying the bus stations
- hdu 2485 Destroying the bus stations
- hdu 2485 Destroying the bus stations (dfs+bfs)
- HDU 2485 Destroying the bus stations (IDA*+ BFS)
- HDU 2485 Destroying the bus stations(费用流)
- AtomicBoolean介绍与使用
- Java 中对日期Date的操作 及 类型转换
- iOS 内存管理机制
- 深搜简单题
- 报错:[Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
- HDU 3663 Power Stations
- ftp服務器
- 检验数据库表是否正常
- VS 工程只生成dll不生成lib的解决方案
- iOS-UI-05 导航控制器的使用 UINavigationController
- Android使用Fragment来实现TabHost的功能(解决切换Fragment状态不保存)
- 开发日记(5) 我们如何让EditText的光标消失呢?
- 构建最小的docker registry镜像
- 报错:错误 '800a0e7a' 未找到提供程序