• ACdreamoj(1105)模拟题


    题意:射一次激光最多能够攻击到几个敌人(因为激光非常强大,能够在击中敌人后穿过它,而瑶瑶自己的坦克因为有特殊装置,所以不会被激光击中。激光也会直接穿过它)

    . 表示此处为空地

    * 表示此处为障碍(激光不可穿过。激光路径打到障碍时就结束)

    T代表瑶瑶的坦克位置

    E代表敌人

    / 代表按 左下-右上 放置的镜子

     代表按 左上-右下 放置的镜子


    解法:模拟题。因为位置过多。

    所以不能用递归模拟。要注意环的推断。还有射击过的敌人要打上标记。

    wa了n发,最后发现是=写成了==,真的非常不应该。


    代码:

    /******************************************************
    * @author:xiefubao
    *******************************************************/
    #pragma comment(linker, "/STACK:102400000,102400000")
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <queue>
    #include <vector>
    #include <algorithm>
    #include <cmath>
    #include <map>
    #include <set>
    #include <stack>
    #include <string.h>
    //freopen ("in.txt" , "r" , stdin);
    using namespace std;
    
    #define eps 1e-8
    #define zero(_) (abs(_)<=eps)
    const double pi=acos(-1.0);
    typedef unsigned long long LL;
    const int Max=2010;
    const int INF=1e9+7;
    
    char s[Max][Max];
    char s2[Max][Max];
    int n,m;
    int sx,sy;
    int toolx,tooly;
    bool en()
    {
        return !(toolx>=0&&toolx<n&&tooly>=0&&tooly<m&&s[toolx][tooly]!='*');
    }
    int to=0;
    int make(int t)
    {
        int ans=0;
        while(1)
        {
            if(t==1)
            {
                toolx-=1;
                if(en())
                    break;
                if(s[toolx][tooly]=='T'&&t==to)
                    break;
                if(s[toolx][tooly]=='\')
                    t=4;
                if(s[toolx][tooly]=='/')
                    t=2;
                if(s[toolx][tooly]=='.'||s[toolx][tooly]=='T')
                    t=t;
                if(s[toolx][tooly]=='E')
                {
                    s[toolx][tooly]='.';
                    ans++;
                    t=t;
                }
                continue;
            }
            if(t==2)
            {
                tooly+=1;
                if(en())
                    break;
                if(s[toolx][tooly]=='T'&&t==to)
                    break;
                if(s[toolx][tooly]=='\')
                    t=3;
                if(s[toolx][tooly]=='/')
                    t=1;
                if(s[toolx][tooly]=='.'||s[toolx][tooly]=='T')
                    t=t;
                if(s[toolx][tooly]=='E')
                {
                    s[toolx][tooly]='.';
                    ans++;
                    t=t;
                }
                continue;
            }
            if(t==3)
            {
                toolx+=1;
                if(en())
                    break;
                if(s[toolx][tooly]=='T'&&t==to)
                    break;
                if(s[toolx][tooly]=='\')
                    t=2;
                if(s[toolx][tooly]=='/')
                    t=4;
                if(s[toolx][tooly]=='.'||s[toolx][tooly]=='T')
                {
                    t=t;
                }
                if(s[toolx][tooly]=='E')
                {
                    s[toolx][tooly]='.';//cout<<"fd"<<ans<<endl;;
                    ans++;
                    t=t;
                }
                continue;
            }
            if(t==4)
            {
                tooly-=1;
                if(en())
                    break;
                if(s[toolx][tooly]=='T'&&t==to)
                    break;
                if(s[toolx][tooly]=='\')
                    t=1;
                if(s[toolx][tooly]=='/')
                    t=3;
                if(s[toolx][tooly]=='.'||s[toolx][tooly]=='T')
                    t=t;
                if(s[toolx][tooly]=='E')
                {
                    s[toolx][tooly]='.';
                    ans++;
                    t=t;
                }
                continue;
            }
        }
        return ans;
    }
    void init()
    {
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++)
                s[i][j]=s2[i][j];
    }
    int main()
    {
        scanf("%d%d",&n,&m);
        for(int i=0; i<n; i++)
        {
            scanf("%s",s[i]);
            for(int j=0; j<m; j++)
                if(s[i][j]=='T')
                {
                    sx=i,sy=j;
                }
        }
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++)
                s2[i][j]=s[i][j];
        toolx=sx,tooly=sy;
        to=1;
        int ans=make(1);
    
        init();
    
        toolx=sx,tooly=sy;
        to=2;
        int tool=make(2);
        ans=max(ans,tool);
    
        init();
    
        toolx=sx,tooly=sy;
        to=3;
        tool=make(3);
        ans=max(ans,tool);
    
        init();
    
        toolx=sx,tooly=sy;
        to=4;
        tool=make(4);
        ans=max(ans,tool);
    
        cout<<ans<<endl;
        return 0;
    }
    /*
    4 4
    *EE
    T*E*
    E/*
    E/*
    */
    


    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    ti processor sdk linux am335x evm setup.sh hacking
    ti processor sdk linux am335x evm Makefile hacking
    导出Excel数据
    使用dom4j解析XML例子
    java解析xml文件并输出
    java解析xml文件
    java解析XML获取城市代码
    drop.delete.trauncat的区别
    hibernate 中id生成策略
    如何使java中double类型不以科学计数法表示
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/4610162.html
Copyright © 2020-2023  润新知