HDU3368+枚举
题意看不懂的直接看百度百科对黑白棋的解释。。。
做法:分情况讨论,一共8个方向。
/*
搜索
*/
#include<stdio.h>
#include<string.h>
const int maxn = ;
char mat[ maxn ][ maxn ];
const int dx[]={-,,-,};
const int dy[]={,-,-,}; int max( int a,int b ){
return a>b?a:b;
} bool in( int x,int y ){
if( x>=&&x<=&&y>=&&y<= ) return true;
else return false;
} int solve( int x,int y ){
int ans = ;
int pos; pos = -;
for( int i=y+;i<=;i++ ){
if( mat[x][i]=='D' ){
pos = i;
break;
}
}
if( pos!=- ){
for( int i=y+;i<=pos;i++ ){
if( mat[x][i]=='*' ){
pos = -;
break;
}
}
}
if( pos!=- ){
for( int i=y+;i<=pos;i++ ){
if( mat[x][i]=='L' )
ans++;
}
}
//right
pos = -;
for( int i=y-;i>=;i-- ){
if( mat[x][i]=='D' ){
pos = i;
break;
}
}
if( pos!=- ){
for( int i=y-;i>=pos;i-- ){
if( mat[x][i]=='*' ){
pos = -;
break;
}
}
}
if( pos!=- ){
for( int i=y-;i>=pos;i-- ){
if( mat[x][i]=='L' )
ans++;
}
}
//left
pos = -;
for( int i=x+;i<=;i++ ){
if( mat[i][y]=='D' ){
pos = i;
break;
}
}
if( pos!=- ){
for( int i=x+;i<=pos;i++ ){
if( mat[i][y]=='*' ){
pos = -;
break;
}
}
}
if( pos!=- ){
for( int i=x+;i<=pos;i++ ){
if( mat[i][y]=='L' )
ans++;
}
}
//down
pos = -;
for( int i=x-;i>=;i-- ){
if( mat[i][y]=='D' ){
pos = i;
break;
}
}
if( pos!=- ){
for( int i=x-;i>=pos;i-- ){
if( mat[i][y]=='*' ){
pos = -;
break;
}
}
}
if( pos!=- ){
for( int i=x-;i>=pos;i-- ){
if( mat[i][y]=='L' )
ans++;
}
}
//up
int posx,posy;
int K;
posx = -;
for( int k=;k<=;k++ ){
int tx = x+k*dx[];
int ty = y+k*dy[];
if( in(tx,ty)==false ) break;
if( mat[tx][ty]=='D' ){
posx = tx;
posy = ty;
K = k;
break;
}
}
if( posx!=- ){
for( int k=;k<=K;k++ ){
int tx = x+k*dx[];
int ty = y+k*dy[];
if( in(tx,ty)==false ) break;
if( mat[tx][ty]=='*' ){
posx = -;
break;
}
}
}
if( posx!=- ){
for( int k=;k<=K;k++ ){
int tx = x+k*dx[];
int ty = y+k*dy[];
if( in(tx,ty)==false ) break;
if( mat[tx][ty]=='L' )
ans++;
}
}
//right && up
posx = -;
for( int k=;k<=;k++ ){
int tx = x+k*dx[];
int ty = y+k*dy[];
if( in(tx,ty)==false ) break;
if( mat[tx][ty]=='D' ){
posx = tx;
posy = ty;
K = k;
break;
}
}
if( posx!=- ){
for( int k=;k<=K;k++ ){
int tx = x+k*dx[];
int ty = y+k*dy[];
if( in(tx,ty)==false ) break;
if( mat[tx][ty]=='*' ){
posx = -;
break;
}
}
}
if( posx!=- ){
for( int k=;k<=K;k++ ){
int tx = x+k*dx[];
int ty = y+k*dy[];
if( in(tx,ty)==false ) break;
if( mat[tx][ty]=='L' )
ans++;
}
}
//left && down
posx = -;
for( int k=;k<=;k++ ){
int tx = x+k*dx[];
int ty = y+k*dy[];
if( in(tx,ty)==false ) break;
if( mat[tx][ty]=='D' ){
posx = tx;
posy = ty;
K = k;
break;
}
}
if( posx!=- ){
for( int k=;k<=K;k++ ){
int tx = x+k*dx[];
int ty = y+k*dy[];
if( in(tx,ty)==false ) break;
if( mat[tx][ty]=='*' ){
posx = -;
break;
}
}
}
if( posx!=- ){
for( int k=;k<=K;k++ ){
int tx = x+k*dx[];
int ty = y+k*dy[];
if( in(tx,ty)==false ) break;
if( mat[tx][ty]=='L' )
ans++;
}
}
//left &&up
posx = -;
for( int k=;k<=;k++ ){
int tx = x+k*dx[];
int ty = y+k*dy[];
if( in(tx,ty)==false ) break;
if( mat[tx][ty]=='D' ){
posx = tx;
posy = ty;
K = k;
break;
}
}
if( posx!=- ){
for( int k=;k<=K;k++ ){
int tx = x+k*dx[];
int ty = y+k*dy[];
if( in(tx,ty)==false ) break;
if( mat[tx][ty]=='*' ){
posx = -;
break;
}
}
}
if( posx!=- ){
for( int k=;k<=K;k++ ){
int tx = x+k*dx[];
int ty = y+k*dy[];
if( in(tx,ty)==false ) break;
if( mat[tx][ty]=='L' )
ans++;
}
}
//right && down return ans;
} int main(){
int T;
scanf("%d",&T);
int ca = ;
while( T-- ){
for( int i=;i<=;i++ ){
scanf("%s",mat[i]+);
}
//memset( vis,false,sizeof( vis ) );
int ans = ;
for( int i=;i<=;i++ ){
for( int j=;j<=;j++ ){
if( mat[i][j]=='*' ){
ans = max( ans,solve( i,j ) );
//if( ans>0 ) printf("attention:%d %d \n",i,j);
}
}
}
printf("Case %d: %d\n",ca++,ans);
}
return ;
}
HDU3368+枚举的更多相关文章
- Swift enum(枚举)使用范例
//: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...
- 编写高质量代码:改善Java程序的151个建议(第6章:枚举和注解___建议88~92)
建议88:用枚举实现工厂方法模式更简洁 工厂方法模式(Factory Method Pattern)是" 创建对象的接口,让子类决定实例化哪一个类,并使一个类的实例化延迟到其它子类" ...
- Objective-C枚举的几种定义方式与使用
假设我们需要表示网络连接状态,可以用下列枚举表示: enum CSConnectionState { CSConnectionStateDisconnected, CSConnectionStateC ...
- Help Hanzo (素数筛+区间枚举)
Help Hanzo 题意:求a~b间素数个数(1 ≤ a ≤ b < 231, b - a ≤ 100000). (全题在文末) 题解: a~b枚举必定TLE,普通打表MLE,真是头疼 ...
- 枚举:enum
枚举 所谓枚举就是指定好取值范围,所有内容只能从指定范围取得. 例如,想定义一个color类,他只能有RED,GREEN,BLUE三种植. 使用简单类完成颜色固定取值问题. 1,就是说,一个类只能完成 ...
- .NET 基础一步步一幕幕[方法、结构、枚举]
方法.结构.枚举 方法: 将一堆代码进行重用的一种机制. 语法: [访问修饰符] 返回类型 <方法名>(参数列表){ 方法主体: } 返回值类型:如果不需要写返回值,写void 方法名:P ...
- Asp.Net 将枚举类型(enum)绑定到ListControl(DropDownList)控件
在开发过程中一些状态的表示使用到枚举类型,那么如何将枚举类型直接绑定到ListControl(DropDownList)是本次的主题,废话不多说了,直接代码: 首先看工具类代码: /// <su ...
- 用枚举enum替代int常量
枚举的好处: 1. 类型安全性 2.使用方便性 public class EnumDemo { enum Color{ RED(3),BLUE(5),BLACK(8),YELLOW(13),GREEN ...
- c#编程基础之枚举
枚举的意义就在于限制变量取值范围. 当可以确定的几种取值时才可以用. 如果输入一个字符串需要进行判断是否是我们需要的字符串时,则一般需要这样写: using System; using System. ...
随机推荐
- C# string类型遇到的两个问题
最近在维护一位离职的同事写的WPF代码,偶然发现他使用C# string类型的两个问题,在这里记录一下. 1. 使用Trim函数移除字串中的空格.换行符等字符串. csRet.Trim(new cha ...
- 盒模型Box Model(浮动)
一.标准盒模型的大小:border+padding+content(width) 怪异盒模型大小:padding+border 二.display inline 默认,且变为行由内 ...
- Fragment的数据传递
开发之中用到的Fragment的次数越来越多,很多小的项目都已经直接在使用Fragment作为Activity的载体来切换页面.而在开发之中页面的切换我们最关心的问题就是数据的传递了.今天我们主要来研 ...
- 转载--- SQL Server XML基础学习之<4>--XPath
T-SQL 支持用于查询 XML 数据类型的 XQuery 语言. XQuery 基于现有的 XPath 查询语言,并支持更好的迭代.更好的排序结果以及构造必需的 XML 的功能. 所以我们本章先 ...
- Sql Server Profiler保存与重演跟踪
重演跟踪的作用 可以将一个跟踪当做测试工具,当按照正确的顺序调用某些存储过程是肯能会重新生成特定的故障. 跟踪模板
- 九度OJ 1480 最大上升子序列和 -- 动态规划
题目地址:http://ac.jobdu.com/problem.php?pid=1480 题目描述: 一个数的序列bi,当b1 < b2 < ... < bS的时候,我们称这个序列 ...
- centos 6.4 samba 权限 selinux权限配置
http://www.cnblogs.com/xiaoluo501395377/archive/2013/05/26/3100444.html(参考) SELINUX 策略 配置好samba后, 输入 ...
- ASP.NET MVC5 PagedList分页示例
ASP.NET MVC是目前ASP.NET开发当中轻量级的Web开发解决方案,在ASP.NET MVC概述这篇译文当中,已经详细的介绍了ASP.NET MVC与Web Forms的区别以及各自的适用场 ...
- css写圆角效果
.introTips i{ position: absolute; display: block; top: 8px; right: 8px; width:; height:; font-size:; ...
- python模块之os和os.path模块
1.os模块os.listdir(dirname) 列出dirname下的目录和文件os.getcwd()函数得到当前工作目录,即当前Python脚本工作的目录路径.os.getenv()和os.pu ...