2013 Asia Hangzhou Regional Contest
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的更多相关文章
- HDU4771(2013 Asia Hangzhou Regional Contest )
http://acm.hdu.edu.cn/showproblem.php?pid=4771 题目大意: 给你一幅图(N*M)“@”是起点,"#"是墙,“.”是路,然后图上有K个珠 ...
- 2013 Asia Hangzhou Regional Contest hdu4780 Candy Factory
参考:https://blog.csdn.net/sd_invol/article/details/15813671 要点 每个任务的结束时间是固定的,不受任何因素影响 机器只在最一开始有用,在那之后 ...
- 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 ...
- 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 ...
- 2012 Asia Hangzhou Regional Contest
Friend Chains http://acm.hdu.edu.cn/showproblem.php?pid=4460 图的最远两点距离,任意选个点bfs,如果有不能到的点直接-1.然后对于所有距离 ...
- 2013 Asia Chengdu Regional Contest
hdu 4786 Fibonacci Tree http://acm.hdu.edu.cn/showproblem.php?pid=4786 copyright@ts 算法源于ts,用最小生成树可以求 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Row_Number实现分页(适用SQL)
1:首先是 select ROW_NUMBER() over(order by id asc) as 'rowNumber', * from table1 生成带序号的集合 2:再查询该集合的 第 1 ...
- 20150309—bs的保存状态
http:保存状态方式,传值方式 session:(会话) 默认过期时间20分钟(20分内无任何操作自动销毁),针对用户独立,一般用来存储少量信息的 存值:session[“name”]=data;( ...
- 记录一次会话CRT
记录一次会话CRT --------------------- su -oracle sqlplus / as sysdba sqlplus username/password 如:普通用户登录 ...
- POJ 1459(EK)
这题是学着小媛学姐写的.. #include<cstdio> #include<cstring> #include<iostream> #include<qu ...
- 如何查找在CDN下的真实ip
今天去找了一下www.bilibili.tv的IP(为什么要这样子做见),发现www.bilibili.tv使用了CDN服务直接ping找不到其真实IP(实际上不用找也可以但就是想找一下). 那我们应 ...
- CentOS学习笔记--基本命令--目录的相关操作
Linux基本命令--目录的相关操作 常见的处理目录的命令吧: cd:变换目录 pwd:显示目前的目录 mkdir:创建一个新的目录 rmdir:删除一个空的目录 cd (变换目录) cd是Chang ...
- 如何在Mac下使用TF/SD 卡制作Exynos 4412 u-boot启动盘
/** ****************************************************************************** * @author Maox ...
- 转 XMLHttpRequest().readyState的五种状态详解
转 http://javathinker.blog.ccidnet.com/blog-htm-itemid-1262479-do-showone-type-blog-uid-36384.html 在& ...
- javascript Date 函数的坑
Javascrip中对日期的解析.格式化简直是混乱不堪,各种的坑,攻城狮们多小心. 1. 不要用 Date("yyyy-mm-dd") 构造函数解析字符串. IE.firefo ...
- winform:无法引用其他类库,dll,using等个人看法【图】
在项目类库中已经引用了相关了类库,生成解决方案也没问题,但是到了后置代码,通过using引用其他类库的时候,再生成解决方案或者生成单个类库,就会报“未能找到类型或命名空间“xxx"(是否缺少 ...