hdu 4069 福州赛区网络赛I DLC ***
再遇到一个DLC就刷个专题
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int N = ; //3*3数独
const int MaxN = N*N*N + ;
const int MaxM = N*N* + ;
const int maxnode = MaxN* + MaxM + ;
char g[MaxN];
int cnt;
struct DLX
{
int n,m,size;
int U[maxnode],D[maxnode],R[maxnode],L[maxnode],Row[maxnode],Col[maxnode];
int H[MaxN],S[MaxM];
int ansd,ans[MaxN];
void init(int _n,int _m)
{
n = _n;
m = _m;
for(int i = ;i <= m;i++)
{
S[i] = ;
U[i] = D[i] = i;
L[i] = i-;
R[i] = i+;
}
R[m] = ; L[] = m;
size = m;
for(int i = ;i <= n;i++)H[i] = -;
}
void Link(int r,int c)
{
++S[Col[++size]=c];
Row[size] = r;
D[size] = D[c];
U[D[c]] = size;
U[size] = c;
D[c] = size;
if(H[r] < )H[r] = L[size] = R[size] = size;
else
{
R[size] = R[H[r]];
L[R[H[r]]] = size;
L[size] = H[r];
R[H[r]] = size;
}
}
void remove(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])
{
U[D[j]] = U[j];
D[U[j]] = D[j];
--S[Col[j]];
}
}
void resume(int c)
{
for(int i = U[c];i != c;i = U[i])
for(int j = L[i];j != i;j = L[j])
++S[Col[U[D[j]]=D[U[j]]=j]];
L[R[c]] = R[L[c]] = c;
}
void Dance(int d)
{
if(cnt > )return;
if(R[] == )
{
for(int i = ;i < d;i++)g[(ans[i]-)/] = (ans[i]-)% + '';
cnt++;
return;
}
int c = R[];
for(int i = R[];i != ;i = R[i])
if(S[i] < S[c])
c = i;
remove(c);
for(int i = D[c];i != c;i = D[i])
{
ans[d] = Row[i];
for(int j = R[i];j != i;j = R[j])remove(Col[j]);
Dance(d+);
if(cnt > )return;
for(int j = L[i];j != i;j = L[j])resume(Col[j]);
}
resume(c);
}
}; int id[][];
int a[][];
void bfs(int sx,int sy,int d)
{
queue<pair<int,int> >q;
q.push(make_pair(sx,sy));
id[sx][sy] = d;
while(!q.empty())
{
pair<int,int> tmp = q.front();
int x = tmp.first;
int y = tmp.second;
q.pop();
if(x > && ((a[x][y]%)/) == )
if(id[x-][y] == -)
{
id[x-][y] = d;
q.push(make_pair(x-,y));
}
if(x < N- && ((a[x][y]%)/) == )
if(id[x+][y] == -)
{
id[x+][y] = d;
q.push(make_pair(x+,y));
}
if(y > && ((a[x][y])/) == )
if(id[x][y-] == -)
{
id[x][y-] = d;
q.push(make_pair(x,y-));
}
if(y < N- && ((a[x][y]%)/) == )
if(id[x][y+] == -)
{
id[x][y+] = d;
q.push(make_pair(x,y+));
}
}
}
DLX dlx; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
scanf("%d",&T);
int iCase = ;
while(T--)
{
iCase++;
for(int i = ;i < N;i++)
for(int j = ;j < N;j++)
scanf("%d",&a[i][j]);
memset(id,-,sizeof(id));
int index = ;
for(int i = ;i < N;i++)
for(int j = ;j < N;j++)
if(id[i][j] == -)
bfs(i,j,++index);
dlx.init(N*N*N,N*N*);
for(int i = ;i < N;i++)
for(int j = ;j < N;j++)
for(int k = ;k <= N;k++)
{
if(a[i][j]% != && a[i][j]% != k)continue;
int r = (i*N+j)*N + k;
int c1 = i*N+j+;
int c2 = N*N+i*N+k;
int c3 = N*N*+j*N+k;
int c4 = N*N*+(id[i][j]-)*N+k;
dlx.Link(r,c1);
dlx.Link(r,c2);
dlx.Link(r,c3);
dlx.Link(r,c4);
}
cnt = ;
dlx.Dance();
printf("Case %d:\n",iCase);
if(cnt == )printf("No solution\n");
else if(cnt > )printf("Multiple Solutions\n");
else
{
for(int i = ;i < N*N;i++)
{
printf("%c",g[i]);
if(i % N == N - )
printf("\n");
}
}
}
return ;
}
hdu 4069 福州赛区网络赛I DLC ***的更多相关文章
- hdu 4063 福州赛区网络赛 圆 ****
画几个图后,知道路径点集一定是起点终点加上圆与圆之间的交点,枚举每两个点之间是否能走,能走则连上线,然后求一遍最短路即可 #include<cstdio> #include<cstd ...
- hdu 4061 福州赛区网络赛A 数学 ***
a1/sum #include<cstdio> #include<iostream> #include<algorithm> #include<cstring ...
- hdu 4068 福州赛区网络赛H 排列 ***
拍的太慢了,很不满意 排完序之后,枚举自己和对手状态,若被击败,则再枚举自己下一个策略,直到可以击败对手所有的策略 #include<cstdio> #include<iostrea ...
- hdu 4070 福州赛区网络赛J 贪心 ***
优先发路程最长的 #include<cstdio> #include<iostream> #include<algorithm> #include<cstri ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)
HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others) Memory Limit: ...
- ICPC 2018 徐州赛区网络赛
ACM-ICPC 2018 徐州赛区网络赛 去年博客记录过这场比赛经历:该死的水题 一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进. D. Easy Math 题意: ...
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 M. Frequent Subsets Problem【状态压缩】
2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 M. Frequent Subsets Problem 题意:给定N和α还有M个U={1,2,3,...N}的子集,求子集X个数,X满足:X是U ...
- HDU 5875 Function -2016 ICPC 大连赛区网络赛
题目链接 网络赛的水实在太深,这场居然没出线zzz,差了一点点,看到这道题的的时候就剩半个小时了.上面是官方的题意题解,打完了才知道暴力就可以过,暴力我们当时是想出来了的,如果稍稍再优化一下估计就过了 ...
随机推荐
- EXT Grid celleditor列编辑,动态控制某一单元格只读
listeners : { beforeedit:function(editor, context, eOpts) { if(context.record.data.hasRatio == " ...
- Extjs TabPanel 选项卡延迟加载
Extjs TabPanel 选项卡延迟加载 说明: Ext中用到tabpanel选项卡控件, 选项卡页签默认是延迟加载的, 当用户手工切换到某页签下时该页签才会加载, 在页签没有加载前, 用户对该页 ...
- js原生的url操作函数,及使用方法。(附:下边还有jquery对url里的中文解码函数)
js原生的url操作函数,完善的. /*****************************/ /* 动态修改url */ /*****************************/ var ...
- ulimit命令
原文链接 linux下默认是不产生core文件的,要用ulimit -c unlimited放开 概述 系统性能一直是一个受关注的话题,如何通过最简单的设置来实现最有效的性能调优,如何在有限资源的条件 ...
- fib数列变种题目
对一个正整数作如下操作:如果是偶数则除以2,如果是奇数则加1,如此进行直到1时操作停止,求经过9次操作变为1的数有多少个? 第9次操作:结果1由2产生.1个被操作数8:结果2只能由4产生.1个被操作数 ...
- spring + myBatis 常见错误:@Autowired注解失败
今天配置spring+myBatis的时候,使用注解@Autowired把持久层dao注入service层的时候总是报错. 查了好久才发现,居然是配置文件路径写错了.basepackge的路径一定要正 ...
- hdu3709
枚举+数位dp 注意处理数字为0和1的情况. #include <cstdio> #include <cstring> using namespace std; #define ...
- 全能直播王PC版-0707-full_codecs
全能直播王是一款高清流畅的全平台的电视直播应用,让您随时随地看高清电视直播. [全能特色] 1. 收录全国1400多个直播频道,包括湖南卫视.江苏卫视.浙江卫视等热门频道. 2. 频道多线路自动选择, ...
- 新浪微博授权失败:applications over the unaudited use restrictions
在用新浪微博授权第三方app时,授权失败,log显示 com.sina.weibo.sdk.exception.WeiboHttpException: {,"request":&q ...
- MST:Agri-Net(POJ 1258)
Agri-Net 题目大意:农夫有一片农场,现在他要把这些田地用管子连起来,田地之间有一定距离,铺设每一段管子的长度与这些田地与田地距离是一样的,问你最小的铺设方案. 这一题很裸,Kruskal算法 ...