程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> hdu1107武林(模擬題)

hdu1107武林(模擬題)

編輯:C++入門知識

Problem Description 在一個有12行12列的方形的武林世界裡,少林、武當和峨嵋三派的弟子們在為獨霸武林而互相厮殺。武林世界的第一行的一列格子的坐標是(1, 1),第一行第二列坐標是(1, 2)……右下角的坐標為(12, 12)。如圖:

vc231PLT1s35z8LX36Gtoa2xyMjno6woMSwgMSkgLT4gKDIsIDEpIC0+ICgzLCAxKaGjPGJyPgrO5LWxxcm13NfT19zKx9TazazSu9DQwLS72LK7zaO12NDQ19+ho8/IzfnT0tffo6zX37W9zbeyu8Tc1NnX38qxvs3N+dfz19+jrNTZtb3Nt9Ty09bN+dPS19+hraGtscjI56OsKDIsIDEpIC0+ICgyLCAyKSAtPiAoMiwgMymhozxicj4Ktuvh0sXJtdzX09fcysfU2tPSz8It1/PJz7e9z/LAtLvYsrvNo9ffo6zPyM3509LPwre919+jrNfftb3Nt7K7xNzU2dffyrG+zc351/PJz7e919+jrNTZtb3Nt9Ty09bN+dPSz8K3vdffoa2hrbHIyOejrCgxLCAxKSAtPiAoMiwgMikgLT4gKDMsIDMpoaO26+HStdzX08jnufvOu9PaKDEsMTIpu/IoMTIsMSmjrMTHtbHIu9a7xNzTwNS2sru2r6GjPGJyPgo8YnI+CsO/tM7X37avo6zDv7j2tdzX07HY0OujrLb4x9LWu8Tc0sa2r9K7uPYmIzI2Njg0O9fToaM8YnI+CsO/w/u13NfT09DE2sGmoaLO5NLVoaK6zcn6w/zBpsj91tbK9NDUoaPV4sj91tbK9NDUtcTIoSYjMjA1NDA7t7bOp7a8yse089PatcjT2jCjrNCh09q1yNPaMTAwoaM8YnI+Cjxicj4KtbHT0MG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8YnI+CqGuU6GvILT6se3J2cHWxcm13NfTPGJyPgqhrlehryC0+rHtzuS1scXJtdzX0zxicj4Koa5Foa8gtPqx7bbr4dLFybXc19M8YnI+Cjxicj4KscjI56O6PGJyPgpXIDEwIDIgMTAgMyAxMDxicj4Kse3KvrXaMTDQ0LXaMsHQ09DSu8P7zuS1scXJtdzX06Osy/u1xMTawabKxyAxMKOszuTS1crHM6OsyfrD/MGmyscxMKGjPGJyPgo8YnI+CsO/1+my4srUyv2+3dLU0ru49r3hyvix6ta+0NC94c6yoaO94cr4serWvtDQ1ru6rNPQ0ru49tfWt/uhrzChr6GjPGJyPgoKCjxicj4KT3V0cHV0CtXrttTDv9fpsuLK1Mr9vt2jrMT6tcTK5LP206a4w8rHNNDQo6zHsDPQ0MO/0NDKx9PDv9UmIzI2Njg0O7fWuPS1xMG9uPbV+8r9o6zHsNK7uPbKx8Szxcm13NfT19zK/aOsuvPSu7j2ysexvsXJy/nT0LXc19PJ+sP8wabWrrrNoaO55raotdox0NC0+rHtydnB1sXJo6y12jLQ0LT6se3O5LWxxcmjrLXaM9DQtPqx7bbr4dLFyaGjtdo00NDKxyChsCoqKqGxse3Kvr3hyvihozxicj4KCgo8YnI+ClNhbXBsZSBJbnB1dAoKPHByZSBjbGFzcz0="brush:java;">2 1 S 1 2 20 20 20 W 2 1 20 20 20 0 2 S 1 2 20 20 20 W 2 1 20 20 20 E 12 12 20 20 100 0
Sample Output
1 20
1 20
0 0
***
1 14
1 14
1 100
***
#include
#include
#include
#include
using namespace std;

typedef struct nn
{
    int y,x;
}node;
typedef struct nnn
{
    char ID;
    int nenli,cofu,life;
    int fite,dir;
}people;

int inList[2][13][13],peopNumb[2][13][13],step;
people p[2][13][13][1005];
queue head[2];
void setFite(people &pp)
{
    double f;
    if(pp.ID=='S')
         f=(0.5*pp.nenli+0.5*pp.cofu)*(pp.life+10)/100.0;
    else if(pp.ID=='W')
         f=(0.8*pp.nenli+0.2*pp.cofu)*(pp.life+10)/100.0;
    else f=(0.2*pp.nenli+0.8*pp.cofu)*(pp.life+10)/100.0;
    pp.fite= (int)f;
}
void moveTo(people pp,int flog,int y,int x)
{
    int n=peopNumb[flog][y][x];
    p[flog][y][x][++n]=pp;
    peopNumb[flog][y][x]++;
}
void countLoct(people &pp,int &y,int &x)
{
    if(pp.ID=='S'){
        if(pp.dir==0){
            if(y==12)pp.dir=1,y=11;
            else y+=1;
        }
        else {
            if(y==1)pp.dir=0,y=2;
            else y-=1;
        }
    }
    else if(pp.ID=='W'){
        if(pp.dir==0){
            if(x==12)pp.dir=1,x=11;
            else x+=1;
        }
        else {
            if(x==1)pp.dir=0,x=2;
            else x-=1;
        }
    }
    else if(pp.ID=='E')
    {
        if(pp.dir==0)
        {
            if(y==12&&x>1||x==12&&y>1)
                pp.dir=1,y-=1,x-=1;
            else if(y<12&&x<12) y+=1,x+=1;
        }
        else
        {
            if(y==1&&x<12||x==1&&y<12)
                pp.dir=0,y+=1,x+=1;
            else if(y>1&&x>1) y-=1,x-=1;
        }
    }
}
void GoFite(int flog)
{
    int ty,tx,i,j;
    node q,qq;
    for( i=1; i<=12; i++)
    for( j=1; j<=12; j++)
    inList[!flog][i][j]=0;
    while(!head[flog].empty())
    {
        q=head[flog].front(); head[flog].pop();
        int &n=peopNumb[flog][q.y][q.x];
        people &pp1=p[flog][q.y][q.x][1];
        people &pp2=p[flog][q.y][q.x][2];
        if(n==2&&pp1.ID!=pp2.ID)
        {
            pp1.life-=pp2.fite; pp2.life-=pp1.fite;
            if(pp1.life<=0&&pp2.life>0)
                  pp1=pp2, n--;
            else if(pp1.life>0&&pp2.life<=0)
                  n--;
            else if(pp1.life<=0&&pp2.life<=0)
                  n=0;
        }

        for( ; n>0; n--)
        {
            ty=q.y; tx=q.x;
            countLoct(p[flog][q.y][q.x][n],ty,tx);
            setFite(p[flog][q.y][q.x][n]);
            moveTo(p[flog][q.y][q.x][n],!flog,ty,tx);
            if(inList[!flog][ty][tx]==0)
            {
                qq.y=ty; qq.x=tx;
                head[!flog].push(qq);
                inList[!flog][ty][tx]=1;
            }
        }
    }
    step--;
    if(step)
    GoFite(!flog);
}
int main()
{
    int t,x,y,flog;
    char str[5];
    people s;
    node q;

    scanf("%d",&t);
    while(t--)
    {
        memset(inList,0,sizeof(inList));
        memset(peopNumb,0,sizeof(peopNumb));
        scanf("%d",&step);
        while(scanf("%s",str)>0&&str[0]!='0')
        {
            s.ID=str[0]; s.dir=0;
            scanf("%d%d%d%d%d",&y,&x,&s.nenli,&s.cofu,&s.life);
            int &n=peopNumb[0][y][x];
            p[0][y][x][++n]=s;
            setFite(p[0][y][x][n]);
            if(!inList[0][y][x])
            {
                 q.y=y; q.x=x; inList[0][y][x]=1;
                head[0].push(q);
            }
        }
        flog=step%2;
        GoFite(0);
        int m[3]={0},sum[3]={0};
        while(!head[flog].empty())
        {
            q=head[flog].front(); head[flog].pop();
            y=q.y; x=q.x;
            int n=peopNumb[flog][y][x];
            for( ; n>0; n--)
            {
                if(p[flog][y][x][n].ID=='S')m[0]++,sum[0]+=p[flog][y][x][n].life;
                if(p[flog][y][x][n].ID=='W')m[1]++,sum[1]+=p[flog][y][x][n].life;
                if(p[flog][y][x][n].ID=='E')m[2]++,sum[2]+=p[flog][y][x][n].life;
            }
        }
        printf("%d %d\n%d %d\n%d %d\n",m[0],sum[0],m[1],sum[1],m[2],sum[2]);
        printf("***\n");
    }
}


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved