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#中Messagebox.Show()常用参数用法详解

    声明:IWin32Window owner   ,  HelpNavigator navigator ,    string keyword 上面的三个参数类型不是很了解.没有做讨论. 等以后了解多了 ...

  2. 【原创】Tomcat集群环境下对session进行外部缓存的方法(1)

    BJJC网改版, 计划将应用部署在tomcat集群上,集群的部署方案为Apache+Tomcat6,连接件为mod_jk,其中开启了session复制和粘性session.计划节点数为3个. 到这,或 ...

  3. DFS入门之二---DFS求连通块

    用DFS求连通块也是比较典型的问题, 求多维数组连通块的过程也称为--“种子填充”. 我们给每次遍历过的连通块加上编号, 这样就可以避免一个格子访问多次.比较典型的问题是”八连块问题“.即任意两格子所 ...

  4. 杭电ACM2058--The sum problem

    http://acm.hdu.edu.cn/showproblem.php?pid=2058 以为简单的穷举就完了,结果是一直Time Limit Exceeded.. 这是代码: #include ...

  5. 济南学习 Day 3 T1 pm

    巧克力棒(chocolate)Time Limit:1000ms Memory Limit:64MB题目描述LYK 找到了一根巧克力棒,但是这根巧克力棒太长了,LYK 无法一口吞进去.具体地,这根巧克 ...

  6. VHDL基本常识

    std_logic_vector和integer需要通过signed或unsigned进行间接转换(强制转换) a_std <= std_logic_vector(to_unsigned(a_i ...

  7. Vivado HLS与System Generator:联系与区别

    在很多年以前的ISE套件里面,有个功能强大的AccelDSP,它可以可自动地进行浮点到定点转换,并把算法生成可综合的HDL,还可以创建用于验证的测试平台,但是在4年前左右的时候销声匿迹了,当时的说法是 ...

  8. css解决IE6、Chrome、ff 浏览器position:fixed;和闪动问题

    首先说下开发模式,刚刚开始接触,基本沿用web端开发方式,目前开发模式上没有找到的适合的,现在基本这样:1,电脑nginx配置服务器3,电脑和手机连同一个局域网,2,android root 和 ip ...

  9. NodeJs菜鸟初始

    我们先来了解下什么是nodejs 一.nodejs具有事件驱动.异步编程的特点. 事件驱动这个词并不陌生,在某些传统语言的网络编程中,我们会用到回调函数,比如当socket资源达到某种状态时,注册的回 ...

  10. Eclipse使用ButterKnife前,需要的配置步骤

    ButterKnife下载地址(7.0.1版本):http://files.cnblogs.com/files/zzw1994/butterknife-7.0.1.zip 官方下载地址(7.0.1版本 ...