跳到正文

剪贴板

剪贴板 kaot514i

原文
剪贴板信息

剪贴板信息

收录
更新

第二题没有什么其他思路:

C++
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char g[1005][1005];
bool cnt[1005][1005];
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
int main()
{
    freopen("explore.in","r",stdin);
    freopen("explore.out","w",stdout);
    int t,n,m,k,x,y,d,i,j,tx,ty,ans;
    cin >>t;
    while(t--)
    {
        cin >> n >> m >> k;
        cin >> x >> y >> d;
        ans = 0;
        memset(cnt,0,sizeof(cnt));
        memset(g,0,sizeof(g));
        cnt[x][y] = 1;
        for(i = 1; i <= n; i++)
        {
            for(j = 1; j <= m; j++)
            {
                cin >> g[i][j];
            }
        }
        while(k--)
        {
            tx = x + dx[d];
            ty = y + dy[d];
            if(tx >= 1 && tx <= n && ty >= 1 && ty <= m && g[tx][ty] == '.')
            {
            	x = tx;
            	y = ty;
            	cnt[tx][ty] = 1;
			}
			else
			{
				d = (d + 1) % 4;
			}
        }
        for(i = 1; i <= n; i++)
	        for(j = 1; j <= m; j++)
	        	if(cnt[i][j])
	        		ans++;
	    cout << ans << endl;
    }

    return 0;
}