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 ...
随机推荐
- Js判断CSS文件加载完毕的实例教程
要判断这个 CSS 文件是否加载完毕,各个浏览器的做法差异比较大,这次要说IE浏览器做的不错,我们可以直接通过onload方法来处理CSS加载完成以后的处理: 代码如下 复制代码 // 代码节选至se ...
- C#判断奇偶数的函數
// 现代流行的"程序员" public static bool IsOdd(int n) { while (true) { switch (n) { : return true; ...
- C#中多线程的简单应用
下面是C#中使用多线程的一个简单用法介绍: //主线程: Thread thread = new Thread(new ThreadStart(ReadExportData));//创建分支线程thr ...
- 10款免费CSS编辑器应对于Linux和Ubuntu
您是否在使用Linux和Ubuntu的,不知道在哪里可以找到一些优秀且免费的CSS编辑器用于Linux和Ubuntu的?如果你的答案是肯定的,然后停止幻想,开始浏览这个帖子里,我们展示了前10名,并免 ...
- C++ Stacks(堆栈)
C++ Stack(堆栈) 是一个容器类的改编,为程序员提供了堆栈的全部功能,——也就是说实现了一个先进后出(FILO)的数据结构. 操作 比较和分配堆栈 empty() 堆栈为空则返回真 pop() ...
- OpenGL第12-14讲小结
首先要为自己为什么没有写第10讲的控制3D场景和第11讲的红旗飘飘呢?因为没看啊~哈哈哈,而且我尝试着运行红旗飘飘的时候电脑蓝屏了(可能不是它的锅),暂时跳过了. 恩,12到14主要了解了这么些东西, ...
- IOS,发短信,发邮件,打电话
今天把APP里常用小功能 例如发短信.发邮件.打电话.全部拿出来简单说说它们的实现思路. 1.发短信实现打电话的功能,主要二种方法,下面我就分别说说它们的优缺点.1.1.发短信(1)——URL // ...
- 【风马一族_Android】让app上传到Android市场的网站介绍
豌豆荚 开发者中心 http://open.wandoujia.com/account/info China app http://www.chinaapp.org
- [转]init.d解析
本文为转载,放在这里以备忘. init.d指的是/etc/rc.d/init.d目录.本文包括3部分内容1. Linux的引导过程2. 运行级别3. /etc/rc.d/ 与/etc/rc.d/ini ...
- flex 监听网络连接情况
NativeApplication.nativeApplication.addEventListener(Event.NETWORK_CHANGE, onNetworkChange); private ...