zoj 3829 Known Notation 贪心
来源:互联网 发布:精乌胶囊知乎 编辑:程序博客网 时间:2024/05/21 16:58
为何自己做的时候没做出来。。。
题意:
略
思路:
由于一个 * 能消除2个数字,然后生成一个数字。因此首先要保证数字个数大于等于 ‘*’ 个数+1。
如果数字个数不够,就在最前面添加。
然后开始从头开始遍历,遇到*就看当前的数字个数是否有两个或以上.不够的话,从最后面开始找第一个不是‘*’的进行交换;够则直接消掉。
code:
/* **********************************************Created Time: 2014-10-14 14:48:16File Name : zoj3829.cpp*********************************************** *///#pragma comment(linker, "/STACK:102400000,102400000")#include <iostream>#include <fstream>#include <cstring>#include <climits>#include <deque>#include <cmath>#include <queue>#include <stack>#include <list>#include <map>#include <set>#include <utility>#include <sstream>#include <complex>#include <string>#include <vector>#include <cstdio>#include <bitset>#include <functional>#include <algorithm>using namespace std;typedef long long LL;const int MAXN = 1005;string str;int main(){ ios::sync_with_stdio(false); int T; cin>>T; while(T--) { int res = 0; cin>>str; int n = str.length(); int cots = 0, cotn = 0; for(int i = 0 ;i < n; i++) { if(str[i] >= '0' && str[i] <= '9') cotn++; else cots++; } int sta = 0; if(cotn < cots+1) { res += cots+1 - cotn; sta = res; } // for(int i = 0;i < n ;i++) { if(str[i] == '*') { if(sta >= 2) sta--; else { for(int j = n-1;j > i; j--) { if(str[j] != '*') { swap(str[j], str[i]); res++; sta++; break; } } } } else sta++; } cout<<res<<endl; } return 0;}
0 0
- zoj 3829 Known Notation(贪心)
- zoj 3829 Known Notation 贪心
- ZOJ 3829 Known Notation 贪心
- zoj 3829 Known Notation (贪心)
- [贪心+模拟] zoj 3829 Known Notation
- ZOJ 3829 Known Notation --贪心+找规律
- ZOJ 3829 Known Notation(贪心)
- ZOJ 3829 Known Notation【贪心】【好题】
- ZOJ - 3829 Known Notation
- ZOJ 3829 Known Notation
- zoj 3829 Known Notation
- zoj 3829 Known Notation
- ZOJ - 3829 Known Notation
- ZOJ 3829 Known Notation
- ZOJ-3829-Known Notation
- ZOJ 3829 Known Notation
- Zoj 3829 Known Notation
- ZOJ Problem Set - 3829Known Notation(贪心)
- 51-nod -1284 2 3 5 7的倍数
- 关于开发板不断eth0: link up, 100Mbps, full-duplex, lpa 0x45E1 eth0: link down的问题
- Linux 内核中的 Device Mapper 机制
- ssh无法连接到远端Ubuntu的解决方法
- SpringMVC学习道路上的点滴---开发流程
- zoj 3829 Known Notation 贪心
- Java Web开发之详解JSP
- Prototype模式
- spring中操作mysql数据库
- Android中Application类用法
- php使用事务 转载
- 使用cocos compile -p android时总是报错误 错误如下。。。但是使用eclipse生成apk包时不收影响。。
- 实验:基于cancel的不完全恢复
- 运维的开始