随笔-72  评论-126  文章-0  trackbacks-0
http://acm.hdu.edu.cn/showproblem.php?pid=2678     Dota打怪
http://acm.hdu.edu.cn/showproblem.php?pid=1107     模拟RPG打战
http://acm.hdu.edu.cn/showproblem.php?pid=2414     棋盘棋子移动
http://acm.hdu.edu.cn/showproblem.php?pid=2258     连连游戏
http://acm.hdu.edu.cn/showproblem.php?pid=2240     飞行棋


http://acm.hdu.edu.cn/showproblem.php?pid=1691
   下象棋
要考虑好多好多东西阿

#include<stdio.h>
#include
<stdlib.h>

int map[11][11];
int kingx,kingy;


bool see()//能见到对方的王
{
    
int i;
    
for(i=kingx-1;i>=0;i--)
        
if(map[i][kingy])
            
break;
    
if(i==-1 || map[i][kingy]!=8)
        
return false;
    
return true;
}


bool King(int a,int b,int c,int d)
{
    
int dis;
    dis 
= abs(a-c) + abs(b-d);
    
if(dis!=1)
        
return false;//只能一动一格


    
if(map[a][b]==8 && (d<4 || d>6 || c<1 || c>3))
        
return false;
    
if(map[a][b]==1 && (d<4 || d>6 || c<8 || c>10))
        
return false;//不能移出九宫格


    map[c][d] 
= map[a][b];
    map[a][b] 
= 0;
    
if(map[c][d]==1)
    {
        kingx 
= c;
        kingy 
= d;
    }
    
if(see())
        
return false;
    
return true;
}


bool Mandarin(int a,int b,int c,int d)
{
    
int disa,disb;
    disa 
= abs(a-c);
    disb 
= abs(b-d);
    
if(disa!=1 || disb!=1)//只能斜向移动一个
        return false;
    
if(map[a][b]==9 && (d<4 || d>6 || c<1 || c>3))
        
return false;
    
if(map[a][b]==2 && (d<4 || d>6 || c<8 || c>10))//只能在九宫格
        return false;
    map[c][d] 
= map[a][b];
    map[a][b] 
= 0;
    
if(see())
        
return false;
    
return true;
}


bool Elephant(int a,int b,int c,int d)
{
    
int disa,disb,x,y;
    disa 
= abs(a-c);
    disb 
= abs(b-d);
    
if(disa!=2 || disb!=2)//只能斜向移动两个
        return false;
    
if(map[a][b]==10 && !(((c==1 || c==5)&& (d==3 || d==7)) || (c==3 && (d==1 || d==5 || d==9))))
        
return false;
    
if(map[a][b]==3 && !(((c==6 || c==10)&& (d==3 || d==7)) || (c==8 && (d==1 || d==5 || d==9))))//只能在这几个位子
        return false;
    x 
= (a+c)/2;
    y 
= (b+d)/2;
    
if(map[x][y])
        
return false;//象脚
    map[c][d] = map[a][b];
    map[a][b] 
= 0;
    
if(see())
        
return false;
    
return true;
}


bool Knight(int a,int b,int c,int d)
{
    
int dir[][2]={{1,2},{1,-2},{-1,2},{-1,-2},{2,1},{2,-1},{-2,1},{-2,-1}};
    
int majiao[][2]={{0,1},{0,-1},{0,1},{0,-1},{1,0},{1,0},{-1,0},{-1,0}};
    
int i;
    
for(i=0;i<8;i++)
    {
        
if(a+dir[i][0]==&& b+dir[i][1]==d)
        {
            
if(map[ a+majiao[i][0] ][ b+majiao[i][1] ])//马脚
                return false;
            
break;
        }
    }
    
if(i==8)
        
return false;
    map[c][d] 
= map[a][b];
    map[a][b] 
= 0;
    
if(see())
        
return false;
    
return true;
}


bool Rook(int a,int b,int c,int d)
{
    
int i;
    map[c][d] 
= map[a][b];
    map[a][b] 
= 0;
    
if(a==c)//横向移动
    {
        
if(b>d)
            b
^=d^=b^=d;
        
for(i=b+1;i<d;i++)
            
if(map[a][i])//中间不能有其他棋子
                break;
        
if(i!=d)
            
return false;
        
if(see())
            
return false;
        
return true;
    }
    
else if(b==d)
    {
        
if(a>c)
            a
^=c^=a^=c;
        
for(i=a+1;i<c;i++)
            
if(map[i][b])
                
break;
        
if(i!=c)
            
return false;
        
if(see())
            
return false;
        
return true;
    }
    
else
        
return false;
}


bool Cannons(int a,int b,int c,int d)
{
    
int i,cnt=0;
    
int k = map[c][d];
    map[c][d] 
= map[a][b];
    map[a][b] 
= 0;
    
if(a==c)
    {
        
if(b>d)
            b
^=d^=b^=d;
        
for(i=b+1;i<d;i++)
            
if(map[a][i])
                cnt 
++;
        
if(k==0 && cnt || k && cnt!=1)//吃子中间要有一个,移动的话中间没有
            return false;
        
if(see())
            
return false;
        
return true;
    }
    
else if(b==d)
    {
        
if(a>c)
            a
^=c^=a^=c;
        
for(i=a+1;i<c;i++)
            
if(map[i][b])
                cnt 
++;
        
if(k==0 &&cnt || k && cnt!=1)
            
return false;
        
if(see())
            
return false;
        
return true;
    }
    
else
        
return false;
}


bool Pawns(int a,int b,int c,int d)
{
    
int dis;
    dis 
= abs(a-c) + abs(b-d);
    
if(dis!=1)
        
return false;
    
int k = map[a][b];
    map[c][d] 
= map[a][b];
    map[a][b] 
= 0;
    
if(k==14)
    {
        
if(a<6 && (a>|| d!=b) || a>c)//过河前不能左右移动,且不能退后
            return false;
    }
    
else
    {
        
if(a>5 && (a<|| b!=d) || a<c)
            
return false;
    }
    
if(see())
        
return false;
    
return true;
}


bool move(int a,int b,int c,int d,int turn)
{
    
if(map[a][b]<=turn*7 || map[a][b]>turn*7+7)
        
return false;
    
if(map[a][b]==1 || map[a][b]==8)
        
return King(a,b,c,d);
    
else if(map[a][b]==2 || map[a][b]==9)
        
return Mandarin(a,b,c,d);
    
else if(map[a][b]==3 || map[a][b]==10)
        
return Elephant(a,b,c,d);
    
else if(map[a][b]==4 || map[a][b]==11)
        
return Knight(a,b,c,d);
    
else if(map[a][b]==5 || map[a][b]==12)
        
return Rook(a,b,c,d);
    
else if(map[a][b]==6 || map[a][b]==13)
        
return Cannons(a,b,c,d);
    
else
        
return Pawns(a,b,c,d);
}


bool same(int x,int y)//吃到自己的棋子
{
    
if(x==0)
        
return false;
    
if(y==0)
        
return true;
    
if(0<x&&x<8&&0<y&&y<8 || 7<x&&x<15&&7<y&&y<15)
        
return false;
    
return true;
}


int main()
{
    
int T,n,i,j,turn,ill,K=1;
    scanf(
"%d",&T);
    
while(T--)
    {
        
for(i=1;i<=10;i++)
            
for(j=1;j<=9;j++)
            {
                scanf(
"%d",&map[i][j]);
                
if(map[i][j]==1)
                {
                    kingx 
= i;
                    kingy 
= j;
                }
            }
        scanf(
"%d%d",&n,&turn);//1 big      0 small
        ill = 0;
        
for(i=1;i<=n;i++)
        {
            
int a,b,c,d;
            scanf(
"%d%d%d%d",&a,&b,&c,&d);
            
if(!ill)
            {
                
if(a<=0 || a>10 || c<=0 || c>10 || b<=0 || b>9 || d<=0 || d>9)//出界
                    ill = i;
                
if(i!=&& (map[c][d]==1 || map[c][d]==8))//吃王
                    ill = i+1;
                
if(!same(map[a][b],map[c][d]) || !move(a,b,c,d,turn))//吃到自己棋子        非法移动
                    ill = i;
                turn 
^= 1;
            }
        }
        printf(
"Case %d: ",K++);
        
if(ill)
            printf(
"Illegal move on step %d\n",ill);
        
else
            puts(
"Legal move");
    }
    
return 0;
}



http://acm.hdu.edu.cn/showproblem.php?pid=2678     Dota打怪
http://acm.hdu.edu.cn/showproblem.php?pid=1107     模拟RPG打战
http://acm.hdu.edu.cn/showproblem.php?pid=2414     棋盘棋子移动
http://acm.hdu.edu.cn/showproblem.php?pid=2258     连连游戏
http://acm.hdu.edu.cn/showproblem.php?pid=2240     飞行棋
posted on 2009-03-19 14:18 shǎ崽 阅读(432) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理