Power Stations

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2164    Accepted Submission(s): 626
Special Judge

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.

 
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).

 
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.

 
Sample Input
3 3 5
1 2
2 3
3 1
1 5
1 5
1 5

4 4 5
1 2
2 3
3 4
4 1
1 5
1 5
1 5
1 5
 
Sample Output
 
1 5
0 0
0 0

 
No solution
 
  就是没看题导致WA1发。
 #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=;
const int maxnode=;
int s[maxn],t[maxn],belong[maxn],ans[maxn];
struct DLX{
int L[maxnode],R[maxnode],U[maxnode],D[maxnode];
int cnt,Row[maxnode],Col[maxnode],C[maxn],H[maxn];
void Init(int n,int m){
for(int i=;i<=m;i++){
L[i]=i-;R[i]=i+;
U[i]=D[i]=i;C[i]=;
}
cnt=m;L[]=m;R[m]=;
for(int i=;i<=n;i++)H[i]=;
} void Link(int r,int c){
Row[++cnt]=r;C[Col[cnt]=c]+=; U[cnt]=c;D[cnt]=D[c];U[D[c]]=cnt;D[c]=cnt; if(!H[r])H[r]=L[cnt]=R[cnt]=cnt;
else R[cnt]=R[H[r]],L[cnt]=H[r],L[R[cnt]]=cnt,R[L[cnt]]=cnt;
} void Delete(int c){
L[R[c]]=L[c];R[L[c]]=R[c];
for(int i=D[c];i!=c;i=D[i])
for(int j=R[i];j!=i;j=R[j])
--C[Col[j]],U[D[j]]=U[j],D[U[j]]=D[j];
} void Resume(int c){
L[R[c]]=c;R[L[c]]=c;
for(int i=U[c];i!=c;i=U[i])
for(int j=L[i];j!=i;j=L[j])
++C[Col[j]],U[D[j]]=j,D[U[j]]=j;
} bool Solve(){
if(!R[])return true;
int p=R[];
for(int i=R[p];i;i=R[i])
if(C[p]>C[i])
p=i; Delete(p);
for(int i=D[p];i!=p;i=D[i]){
if(ans[belong[Row[i]]])continue;
for(int j=R[i];j!=i;j=R[j])
Delete(Col[j]); ans[belong[Row[i]]]=Row[i];
if(Solve())
return true;
ans[belong[Row[i]]]=;
for(int j=L[i];j!=i;j=L[j])
Resume(Col[j]);
}
Resume(p);
return false;
}
}dlx; int L[maxn],R[maxn];
bool G[maxn][maxn]; int main(){
int a,b,N,M,D,tot;
while(scanf("%d%d%d",&N,&M,&D)!=EOF){
memset(G,,sizeof(G));
while(M--){
scanf("%d%d",&a,&b);
G[a][b]=true;
G[b][a]=true;
} tot=;
for(int i=;i<=N;i++){
scanf("%d%d",&s[i],&t[i]);
tot+=(t[i]-s[i]+)*(t[i]-s[i]+)/;
G[i][i]=true;
} dlx.Init(tot,N*D);
memset(ans,,sizeof(ans));
for(int x=,p=;x<=N;x++)
for(int l=s[x];l<=t[x];l++)
for(int r=l;r<=t[x];r++){
++p;L[p]=l;R[p]=r;belong[p]=x;
for(int j=l;j<=r;j++)
for(int y=;y<=N;y++)
if(G[x][y])dlx.Link(p,N*(j-)+y);
}
if(dlx.Solve()){
for(int i=;i<=N;i++)
printf("%d %d\n",L[ans[i]],R[ans[i]]);
}
else
printf("No solution\n");
printf("\n");
}
return ;
}

搜索(DLX):HDU 3663 Power Stations的更多相关文章

  1. [DLX精确覆盖] hdu 3663 Power Stations

    题意: 给你n.m.d,代表有n个城市.m条城市之间的关系,每一个城市要在日后d天内都有电. 对于每一个城市,都有一个发电站,每一个发电站能够在[a,b]的每一个连续子区间内发电. x城市发电了.他相 ...

  2. Power Stations HDU - 3663

    我为什么T了.... Power Stations Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  3. 【HDU 3663】 Power Stations

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3663 [算法] 先建图,然后用Dancing Links求解精确覆盖,即可 [代码] #inclu ...

  4. HDU 6034---Balala Power!(搜索+贪心)

    题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He ...

  5. hdu 3663 DLX

    思路:把每个点拆成(d+1)*n列,行数为可拆分区间数.对所有的有i号点拆分出来的行都要建一条该行到i列的边,那么就能确保有i号点拆出来的行只能选择一行. #include<set> #i ...

  6. 【HDOJ】Power Stations

    DLX.针对每个城市,每个城市可充电的区间构成一个plan.每个决策由N*D个时间及N个精确覆盖构成. /* 3663 */ #include <iostream> #include &l ...

  7. 搜索(DLX): POJ 3074 3076 Sudoku

    POJ 3074 : Description In the game of Sudoku, you are given a large 9 × 9 grid divided into smaller ...

  8. 搜索(DLX):HOJ 1017 - Exact cover

    1017 - Exact cover Time Limit: 15s Memory Limit: 128MB Special Judge Submissions: 6751 Solved: 3519 ...

  9. HDU 4318 Power transmission(最短路)

    http://acm.hdu.edu.cn/showproblem.php?pid=4318 题意: 给出运输路线,每条路线运输时都会损失一定百分比的量,给定起点.终点和初始运输量,问最后到达终点时最 ...

随机推荐

  1. svn 设置钩子将代码同步到web目录下面

    首先:确定思路: 要在SVN服务中,找到仓库文件夹的位置,在相应的项目中找到hooks文件夹.在该文件中添加一个post-commit文件: 当有commit动作发生时(提交到SVN服务是就会执行这个 ...

  2. 布局重用 include merge ViewStub

    在布局优化中,Androi的官方提到了这三种布局<include />.<merge />.<ViewStub />,并介绍了这三种布局各有的优势,下面也是简单说一 ...

  3. JavaScript正则验证数字、英文、电话号、身份证号、邮箱地址、链接地址等

    验证是否为数字:/^[0-9]*$/验证是否为汉字:/^[\u4e00-\u9fa5],{0,}$/验证x-y位的数字:/^\d{x,y}$/验证由26个英文字母组成的字符串:/^[A-Za-z]+$ ...

  4. U3D 实现地面碰撞效果

    前面讲了如何让两个刚体碰撞: 现在来细细讲解一下, 首先,精灵刚体后就好比物理世界的物体,是受到重力所用的, 然后两个物体要添加碰撞系数才能实现碰撞, 这种情况下,碰撞后会使得另一个刚体也会随之运动, ...

  5. jquery ui 插件------------------------->sortable

    <!doctype html><html lang="en"><head>  <meta charset="utf-8" ...

  6. 浅谈html5某些新元素的用途

    大家都知道html是一种前端网页语言,从出现到现在已经经历了很多的版本了,但是随着html的不断发展,现在的html5已经不再是单一的前端页面语言了,html,javascript,css不再单纯的只 ...

  7. 在Xcode4中给程序提供命令行参数(转)

    网上xcode4的资料实在是不多,再加上xcode4相对3的改动还那么大,并且还只有英文版.我为了这个问题头痛了很久.后来终于找到了...方法如下 xcode菜单的Product->EditSc ...

  8. java获取数据库数据表的元数据

    Connction conn; DatabaseMetaData dmd=conn.getMetaData();//获取数据库元数据 PreparedStatment ps; ps.getParame ...

  9. 搭建BCE本地开发环境

    1. 在官网下载VirtualBox & 虚拟机 http://bce.baidu.com/doc/BAE/GUIGettingStarted.html#.E4.B8.8B.E8.BD.BD. ...

  10. cloudera目录位置

    http://www.aboutyun.com/thread-9189-1-1.html 这里来的嘿嘿. 1. 相关目录/var/log/cloudera-scm-installer : 安装日志目录 ...