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 ...
随机推荐
- eBay 开发流程
1[记录]注册成为eBay开发者(eBay Developers Program)+创建Sanbox Key和Production Key http://www.crifan.com/register ...
- 二叉树-你必须要懂!(二叉树相关算法实现-iOS)
这几天详细了解了下二叉树的相关算法,原因是看了唐boy的一篇博客(你会翻转二叉树吗?),还有一篇关于百度的校园招聘面试经历,深刻体会到二叉树的重要性.于是乎,从网上收集并整理了一些关于二叉树的资料,及 ...
- 分栏控制器和导航栏目tabBarItem,UINavigationController
//// AppDelegate.m// TabBarControllerDemo//// Created by qianfeng on 15/9/22.// Copyright (c) 20 ...
- UI2_UITextField
// // ViewController.h // UI2_UITextField // // Created by zhangxueming on 15/7/2. // Copyright (c) ...
- 银联接口测试——详细(JAVA)
准备材料 1.注册账号 https://open.unionpay.com/ajweb/register?locale=zh_CN 2.▼登录账号 -->帮助中心--> 下载,选择网关支付 ...
- Linux I/O模型
同步阻塞I/O 在此种方式下,用户进程在发起一个I/O操作以后,必须等待I/O操作的完成,只有当真正完成了I/O操作以后,用户进程才能运行.Java传统的I/O模型属于此种方式. 同步非阻塞I/O 在 ...
- VC和VS系列(2005)编译器对双精度浮点溢出的处理
作者:风影残烛 在还原代码的过程中.目前程序是采用VS2005(以上版本)写的. 我使用的是vc6.0,结果.在运算的时候.发现编译器对 // FpuTlxTest.cpp : 定义控制台应用程序的入 ...
- linux系统man查询命令等级与意义
代号 意义 1 可执行程序和一般shell命令 2 系统调用函数 3 库函数 4 设备配置文件,通常在/dev下 5 配置文件,/ec下 6 游戏 7 协议及杂项 8 管理员命令 9 与内核相关
- 《linux文件权限管理大总结》RHEL6
在linux系统下文件的权限通常会以下面的格式显示出来: Chmod文件权限: 权限的管理chmod -a 所有的权限 -u 文件所有者的权限 -g 组权限 -o 其他用户的权限 可以使用运算符来设 ...
- 全面解析SQL SERVER 的左右内连接
SQL SERVER数据库的三种常用连接解析: 这里先给出一个官方的解释: left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右 ...