Lights Against Dudely http://acm.hdu.edu.cn/showproblem.php?pid=4770

15个位置,所以可以暴力枚举那些放,对于放的再暴力枚举哪个转,对于转的,再枚举转哪个方向。选位置放我用了2进制枚举,选出哪个转和枚举4个方向for循环就行。可以加个小剪枝。

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
const int inf=0x3f3f3f3f;
const int M=;
char a[M][M];
struct point{
int x,y;
friend bool operator ==(const point &a,const point &b){
return a.x==b.x&&a.y==b.y;
}
}p[];
bool vis[];
int dx[]={-,,,};
int dy[]={,,,-};
int n,m,len,useid[];
bool isjing(const int &x,const int &y){
if(x>=&&x<n&&y>=&&y<m&&a[x][y]=='#') return true; return false;
}
bool flag(const point &b){
if(isjing(b.x,b.y)) return false;
for(int i=;i<len;i++){
if(b==p[i]){
vis[i]=true;
break;
}
}
return true;
}
void step(point &pp,const int &dir){
pp.x+=dx[dir];
pp.y+=dy[dir];
}
bool cover(const point &pp,const int &dir){
if(!flag(pp)) return false;
point qq=pp;
step(qq,dir);
if(!flag(qq)) return false;
qq=pp;
step(qq,(dir+)%);
if(!flag(qq)) return false;
return true;
}
int main(){
while(~scanf("%d%d",&n,&m),n|m){
for(int i=;i<n;i++){
scanf("%s",a[i]);
}
len=;
for(int i=;i<n;i++){
for(int j=;j<m;j++){
if(a[i][j]=='.'){
p[len].x=i;
p[len].y=j;
len++;
}
}
}
int all=<<len,ans=inf;
for(int i=;i<all;i++){
if(len==) ans=;
int lu=;
for(int j=;j<len;j++){
if((i>>j)&) useid[lu++]=j;
}
if(ans<=lu) continue;
for(int j=;j<lu;j++){
for(int dir=;dir<;dir++){
mt(vis,);
bool ok=true;
for(int k=;k<lu;k++){
if(k!=j){
if(!cover(p[useid[k]],)){
ok=false;
break;
}
}
else{
if(!cover(p[useid[k]],dir)){
ok=false;
break;
}
}
}
if(ok){
bool cc=true;
for(int j=;j<len;j++){
if(!vis[j]){
cc=false;
break;
}
}
if(cc){
ans=min(ans,lu);
}
}
}
}
}
if(ans==inf) ans=-;
printf("%d\n",ans);
}
return ;
}

hdu 4771 http://acm.hdu.edu.cn/showproblem.php?pid=4771

bfs基础,重复状态的判断,二进制表示不同状态。题意有k个物品在图中,问最少几步全部拿到。

 #include<cstdio>
#include<cstring>
#include<queue>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
const int M=;
char a[M][M];
int pp[M][M];
bool vis[M][M][];
int n,m,sx,sy,k;
struct Q{
int x,y,sta,step;
}now,pre;
queue<Q> q;
int dx[]={,,,-};
int dy[]={,-,,};
int bfs(){
now.x=sx;
now.y=sy;
now.sta=pp[sx][sy];
now.step=;
mt(vis,);
vis[sx][sy][now.sta]=true;
while(!q.empty()) q.pop();
q.push(now);
while(!q.empty()){
pre=q.front();
q.pop();
if(pre.sta==(<<k)-) return pre.step;
for(int i=;i<;i++){
int tx=pre.x+dx[i];
int ty=pre.y+dy[i];
if(tx>=&&tx<n&&ty>=&&ty<m&&a[tx][ty]!='#'&&!vis[tx][ty][pre.sta]){
now.x=tx;
now.y=ty;
now.sta=pre.sta|pp[tx][ty];
now.step=pre.step+;
vis[tx][ty][now.sta]=true;
q.push(now);
}
}
}
return -;
}
int main(){
while(~scanf("%d%d",&n,&m),n|m){
for(int i=;i<n;i++){
scanf("%s",a[i]);
for(int j=;j<m;j++){
if(a[i][j]=='@'){
sx=i;
sy=j;
}
}
}
mt(pp,);
scanf("%d",&k);
for(int i=,x,y;i<k;i++){
scanf("%d%d",&x,&y);
pp[x-][y-]|=(<<i);
}
printf("%d\n",bfs());
}
return ;
}

hdu 4772 Zhuge Liang's Password http://acm.hdu.edu.cn/showproblem.php?pid=4772

矩阵转4次,看哪次相等的最多。

 #include<cstdio>
#include<algorithm>
using namespace std;
const int M=;
int a[M][M],b[M][M],c[M][M],n;
int solve(){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
c[n-j+][i]=a[i][j];
}
}
int res=;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
a[i][j]=c[i][j];
if(a[i][j]==b[i][j]) res++;
}
}
return res;
}
int main(){
while(~scanf("%d",&n),n){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
scanf("%d",&a[i][j]);
}
}
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
scanf("%d",&b[i][j]);
}
}
int ans=;
for(int i=;i<;i++){
ans=max(ans,solve());
}
printf("%d\n",ans);
}
return ;
}

end

2013 Asia Hangzhou Regional Contest的更多相关文章

  1. HDU4771(2013 Asia Hangzhou Regional Contest )

    http://acm.hdu.edu.cn/showproblem.php?pid=4771 题目大意: 给你一幅图(N*M)“@”是起点,"#"是墙,“.”是路,然后图上有K个珠 ...

  2. 2013 Asia Hangzhou Regional Contest hdu4780 Candy Factory

    参考:https://blog.csdn.net/sd_invol/article/details/15813671 要点 每个任务的结束时间是固定的,不受任何因素影响 机器只在最一开始有用,在那之后 ...

  3. HDU 3685 Rotational Painting(多边形质心+凸包)(2010 Asia Hangzhou Regional Contest)

    Problem Description Josh Lyman is a gifted painter. One of his great works is a glass painting. He c ...

  4. HDU 3686 Traffic Real Time Query System(双连通分量缩点+LCA)(2010 Asia Hangzhou Regional Contest)

    Problem Description City C is really a nightmare of all drivers for its traffic jams. To solve the t ...

  5. 2012 Asia Hangzhou Regional Contest

    Friend Chains http://acm.hdu.edu.cn/showproblem.php?pid=4460 图的最远两点距离,任意选个点bfs,如果有不能到的点直接-1.然后对于所有距离 ...

  6. 2013 Asia Chengdu Regional Contest

    hdu 4786 Fibonacci Tree http://acm.hdu.edu.cn/showproblem.php?pid=4786 copyright@ts 算法源于ts,用最小生成树可以求 ...

  7. HDU 3689 Infinite monkey theorem(DP+trie+自动机)(2010 Asia Hangzhou Regional Contest)

    Description Could you imaging a monkey writing computer programs? Surely monkeys are smart among ani ...

  8. 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...

  9. zoj 3659 Conquer a New Region The 2012 ACM-ICPC Asia Changchun Regional Contest

    Conquer a New Region Time Limit: 5 Seconds      Memory Limit: 32768 KB The wheel of the history roll ...

随机推荐

  1. 【学习笔记】【C语言】赋值运算

    将某一数值赋给某个变量的过程,称为赋值. 1. 简单赋值 C语言规定,变量要先定义才能使用,也可以将定义和赋值在同一个语句中进行 int a = 10 + 5;的运算过程 a = b = 10;的运算 ...

  2. php_1

    简介:(“PHP: Hypertext Preprocessor”,超文本预处理器的字母缩写)是一种被广泛应用的开放源代码的多用途脚本语言,它可嵌入到 HTML中,尤其适合 web 开发,语言的风格有 ...

  3. COM包装(COM Wrappers)

    为了实现传统的COM程序与.NET程序之间的相互调用,.NET提供了两个包装类:运行时可调用包装(runtime callable wrapper,RCW)和COM可调用包装(COM callable ...

  4. 10+ powerful debugging tricks with Visual Studio

    10+ powerful debugging tricks with Visual Studio Original link : http://www.codeproject.com/Articles ...

  5. select的onChange事件问题解决

    一.onChange事件只有在值改变时才可触发,所以必须在每一次选择时(尤其第一次)保证选择的值是改变的! 所以<select name="inv_payee" id=&qu ...

  6. stanford moss

    A System for Detecting Software Plagiarism UPDATES May 18, 2014 Community contributions (incuding a ...

  7. 通信协议之HTTP,UDP,TCP协议

    1.UDP,TCP,HTTP之间的关系 tcp/ip是个协议组,它可以分为4个层次,即网路接口层,网络层,传输层,以及应用层, 在网络层有IP协议.ICMP协议.ARP协议.RARP协议和BOOTP协 ...

  8. js中的数组

    上网查了一下,js中的数组包含的内容还真不少.先给出两个学习的链接: w3school链接:http://www.w3school.com.cn/js/js_obj_array.asp 博客园链接:h ...

  9. XAML 概述二

    通过上一节我们已经对XAML有了一定的了解,这一节我们来系统的学习一下XAML. 一. 简单属性与类型转换器,属性元素: 我们已经知道 XAML是一种声明性的语言,并且XAML解析器会为每个标签创建一 ...

  10. Azure IaaS for IT Pros Online Event 总结

    微软一个为期4天的一个有关于Azure的介绍,主要总结了些Azure现有的技术以及将会推出东西 主题链接 http://channel9.msdn.com/Events/Microsoft-Azure ...