• UVaLive 6802 Turtle Graphics (水题,模拟)


    题意:给定一个坐标,和一行命令,按照命令走,问你有多少点会被访问超过一次。

    析:很简单么,按命令模拟就好,注意有的点可能走了多次,只能记作一次。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #include <sstream>
    #define frer freopen("in.txt", "r", stdin)
    #define frew freopen("out.txt", "w", stdout)
    using namespace std;
    
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 1e2 + 5;
    const int mod = 1e9 + 7;
    const char *mark = "+-*";
    const int dr[] = {1, 0, -1, 0};
    const int dc[] = {0, 1, 0, -1};
    const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline int Min(int a, int b){ return a < b ? a : b; }
    inline int Max(int a, int b){ return a > b ? a : b; }
    inline LL Min(LL a, LL b){ return a < b ? a : b; }
    inline LL Max(LL a, LL b){ return a > b ? a : b; }
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    int a[maxn][maxn];
    char s[maxn];
    
    int main(){
        int T;  cin >> T;
        int x, y;
        for(int kase = 1; kase <= T; ++kase){
            scanf("%d %d", &y, &x);
            scanf("%s", s);
            n = strlen(s);
            int i = 0, j = 0;
            memset(a, 0, sizeof a);
            a[x][y] = 1;
            int ans = 0;
    
            while(i < n){
                if(s[i] == 'F'){
                    x += dr[j];
                    y += dc[j];
                    if(a[x][y] == 1)  ++ans, a[x][y] = 2;
                    else if(!a[x][y]) a[x][y] = 1;
                }
                else if(s[i] == 'L')  j = (j+3) % 4;
                else j = (j+1) % 4;
                ++i;
            }
            printf("Case #%d: %d %d %d
    ", kase, y, x, ans);
    
        }
        return 0;
    }
    

      

  • 相关阅读:
    在 Linux 下搭建 Git 服务器***
    使用 SVN Hook 实现服务器端代码自动更新
    git服务器的建立
    Oracle 11gR2 RAC集群服务启动与关闭总结
    Cluster的日记体系
    DB time VS. DB CPU
    oracle 内存分配和调优 总结
    利用logminer恢复delete误删除操作的数据
    大话RAC介质恢复---联机日志损坏
    ORACLE联机日志文件丢失或损坏的处理方法(转)
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5804574.html
Copyright © 2020-2023  润新知