Hdu 1571 下沙小面的(1) [模拟]

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1571

题目的意思很是简单,就是模拟一个面的的情况。直接链表模拟就可以了。。。

表示最近写了一些模拟,才发现自己的代码能力的羸弱。。。。

写了一些个链表的模拟,一直各种Bug,RE,WA。。反正是各种错误的有。。。

反正,还是多写吧。。自己的代码能力还是很弱。。。。

这只能用多写才能够解决的问题。。。

Code:

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;

const int N = 33;

struct Node
{
    int num;
    Node *next;
    Node(){
        next = NULL;
    }
    Node(int x) {
        num = x;
        next = NULL;
    }
} *root, *tail;

int size()
{
    Node *p = root;
    int ans = 0;
    while(p -> next != tail){
        p = p -> next;
        ans ++;
    }
    return ans;
}

int Delete(int x)
{
    int ans = x;
    root = root ->next;
    root -> num = -1;
    Node *p = root;
    while(p -> next != NULL){
        if(p -> next -> num == ans){
            p ->next = p ->next ->next;
        }
        p = p -> next;
    }
    return ans;
}

int main()
{
//    freopen("1.txt", "r", stdin);
    int n;
    while(scanf("%d", &n) && n){
        int map[N][N];
        for(int i = 0; i < n; i ++){
            for(int j = 0; j < n; j ++)
            scanf("%d", &map[i][j]);
        }
        int m, now = 0, x, ans = 0;
        char order[5];
        root = new Node(-1);// define the root and tail.. and tail is the next node of root.
        tail = new Node(-1);
        root -> next = tail;
        scanf("%d", &m);
        while(m --){
            scanf("%s", order);
            if(order[0] == 'U'){
                scanf("%d", &x);
                if(size() == 7 || now == x){
                    continue;
                }
                else {
                    tail -> num = x;
                    tail -> next = new Node(-1);
                    tail = tail -> next;
                }
            }
            else {
                if(root -> next== tail) continue;
                int to = Delete(root -> next -> num);
                ans += map[now][to];
                now = to;
            }
        }
        printf("%d\n", ans);
        delete root;
        delete tail;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值