UVA 11111 一般XX
来源:互联网 发布:淘宝链接跳转淘宝app 编辑:程序博客网 时间:2024/04/30 04:32
这个思路很好
http://www.cppblog.com/wuxu/archive/2011/11/23/160794.aspx
类似于上一个题目,但有所不同
设计一个struct保存原始值和叠加以后的值(检验是否超出)
每碰到一个正数,便对于栈中数据进行处理,这个时候用到struct中记录的数据比较是否超出大小范围
#include <iostream>#include <sstream>#include <cstdio>#include <cstring>#include <cmath>#include <string>#include <vector>#include <set>#include <cctype>#include <algorithm>#include <cmath>#include <deque>#include <queue>#include <map>#include <stack>#include <iomanip>using namespace std;///#define INF 0xffffff7#define maxn 300///struct MyNum {int Original;int AfterAdd;};vector<int> num;stack<MyNum> stk;int main(){///int positive, negetive;string line;while (getline(cin, line)){num.clear();while (!stk.empty())stk.pop();istringstream stream(line);int temp;positive = negetive = 0;bool Isok = true;while(stream >> temp){num.push_back(temp);if (temp > 0){positive++;}elsenegetive++;if (positive > negetive){Isok = false;break;}}if (!Isok || (num.size() % 2 != 0)){cout << ":-( Try again." << endl;continue;}vector<int>::iterator it = num.begin();MyNum tempNum;while (it != num.end()){int test;test = *it;if (test < 0){tempNum.Original = tempNum.AfterAdd = test;stk.push(tempNum);it++;continue;}else{if (!stk.empty() && (stk.top().Original + test == 0)){stk.pop();if (!stk.empty()){tempNum = stk.top();stk.pop();tempNum.AfterAdd += test;if (tempNum.AfterAdd >= 0){Isok = false;break;}stk.push(tempNum);}else if ((it + 1) != num.end()){Isok = false;break;}}else {Isok = false;break;}it++;}}if (Isok){cout << ":-) Matrioshka!" << endl;}elsecout << ":-( Try again." << endl;} /// return 0;}
- UVA 11111 一般XX
- Chopsticks+uva+一般dp
- UVa 11111 一般Matrioshka 及 scanf 处理一行
- Weights and Measures+uva+一般dp
- XX
- xx
- xx
- xx
- XX
- xx
- xx
- xx
- XX
- xx
- xx
- xx
- xx
- xx
- xcode中用静态成员函数来代替全局变量
- C++中的explicit关键字
- Unity3D 与udk 3D游戏动漫引擎的开发特点
- oracle top n
- 摄像头休眠后预览图像出现撕裂现象
- UVA 11111 一般XX
- [android]9 patch 图片 (.9.png 格式图片) 的特点和制作
- Dithering-视觉的奇特现象
- 写给自己的 自考北大计算机与应用专业
- 自己对Java中==与equals比较的理解
- linux kill命令参数及用法详解--linux终止进程命令
- Dither
- ALSA之snd_kcontrol探究
- Top K算法详细解析—百度面试