Hdu 1571 下沙小面的(1) [模拟]
来源:互联网 发布:社区巡展 知乎 编辑:程序博客网 时间:2024/06/05 22:02
题目链接: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;}
0 0
- Hdu 1571 下沙小面的(1) [模拟]
- HDU-下沙小面的(1)- 模拟
- hdu 1571 模拟
- hdu 1571(模拟)
- YT15-HDU-字符串的模拟
- hdu 1035很简单的一个模拟
- HDU 2816 有趣的恶心模拟
- HDU 4121(非常纠结的模拟)
- hdu 2565 放大的X (模拟)
- hdu 3688 蛮巧的模拟
- HDU 1022 栈 栈的模拟
- hdu 4858 容器的简单模拟
- hdu 2206 IP的计算 模拟
- HDU 1387 Team Queue 队列的模拟
- HDU 1057 模拟细菌的变化
- HDU-Help him-字符串的模拟
- HDU 4041 Eliminate Witches! (栈的模拟)
- hdu 1870 愚人节的礼物(栈模拟)
- nyoj66分数拆分
- 文件上传功能
- 操作系统知识要点
- VC6.0 MFC 串口通信 AT命令
- LeetCode OJ - Flatten Binary Tree to Linked List
- Hdu 1571 下沙小面的(1) [模拟]
- 操作系统的主要功能
- 大数加法(瑕疵)
- STL algorithm算法find_if_not(20)
- Oracle创建之路->创建表空间、创建临时表空间、创建用户、授权
- 交互式shell和非交互式shell、登录shell和非登录shell的区别
- PHP开发环境及开发环境搭建
- KMP算法初步
- 堆内存