zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    octotree神器 For Github and GitLab 火狐插件
    实用篇如何使用github(本地、远程)满足基本需求
    PPA(Personal Package Archives)简介、兴起、使用
    Sourse Insight使用过程中的常使用功能简介
    Sourse Insight使用教程及常见的问题解决办法
    github 遇到Permanently added the RSA host key for IP address '192.30.252.128' to the list of known hosts问题解决
    二叉查找树的C语言实现(一)
    初识内核链表
    container_of 和 offsetof 宏详解
    用双向链表实现一个栈
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5804574.html
Copyright © 2011-2022 走看看