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
*E\E
T*E*
E/\*
\E/*
*/


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

转载于:https://www.cnblogs.com/mfrbuaa/p/4610162.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值