poj1214(链表
来源:互联网 发布:sql 最后一行显示合计 编辑:程序博客网 时间:2024/05/20 12:48
uva的感觉好卡。。去看看poj发现有一样的题目,就在poj上测了,还有错误反馈QAQ不过感觉也是挺卡的,还是zoj流畅。
此题目- -纯练习链表。。。
好吧,,,在poj运行16ms。。为什么在uva就是超了3s- -。。。
#include <iostream>#include <stack>#include <string>using namespace std;struct lnode{ stack<string> poke; lnode* fron; lnode* next;};bool test(string a,string b){ if(a[0] == b[0] || a[1] == b[1]) return true; else return false;}bool Find_left3(lnode* top,string po,int m){ lnode* go = top; for(int m = 0;m < 2;m++) { if(go->fron != NULL) go = go->fron; else break; if(m == 1 && test(go->poke.top(),po)) { go->poke.push(po); return true; } } return false;}bool Find_left3_1(lnode* a,int& num,lnode* &top,int m){ lnode* go = a; lnode* left = a; for(;m < 3;m++) { if(left->fron != NULL) left = left->fron; else break; if(m == 2 && test(go->poke.top(),left->poke.top())) { left->poke.push(go->poke.top()); go->poke.pop(); if(go->poke.empty()) { if(top == go) top = top->fron; go->fron->next = go->next; if(go->next != NULL) go->next->fron = go->fron; go->fron = go->next = NULL; num--; } return true; } } return false;}int main(){ string po; while(cin >> po && po != "#") { lnode pokes[52]; lnode* top = &pokes[0]; int num = 1; pokes[0].poke.push(po); pokes[0].next = &pokes[1]; pokes[0].fron = NULL; for(int m = 1;m<52;m++) { cin >> po; if(Find_left3(top,po,0)); else if(Find_left3(top,po,1)); else { num++; pokes[m].poke.push(po); top->next = &pokes[m]; pokes[m].fron = top; pokes[m].next = NULL; top = &pokes[m]; } lnode* go = &pokes[0]; while(go != NULL) { if(Find_left3_1(go,num,top,0)) {go = &pokes[0];continue;} else if(Find_left3_1(go,num,top,2)) {go = &pokes[0];continue;} else go = go->next; } } lnode* go = &pokes[0]; cout << num << " piles remaining:"; while(go != NULL) { cout << ' ' << go->poke.size(); go = go->next; } cout << endl; } return 0;}
0 0
- poj1214(链表
- POJ1214--"Accordian" Patience
- poj1214 "Accordian" Patience (栈)
- uva127 "Accordian" Patience poj1214 模拟
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 【华为oj】字符串最后一个字符的长度
- JAVA 面向对象和集合知识点总结
- linux vpnc
- Android studio gradle
- 关于操作符和函数的区别
- poj1214(链表
- SpringMVC与Struts2的对比
- oracle中执行计划中的cardinality
- 使用JavaMail发送邮件
- 自定义控件-ViewPagerIndicator
- 11个免费的Web安全测试工具
- 每个程序员和设计师可做的10项运动
- 2015-7-30 我的博客
- 离散事件模拟-银行管理