hdu2209
来源:互联网 发布:日本振袖和服价格知乎 编辑:程序博客网 时间:2024/06/05 23:05
是贪心,但是直接做不对。
直接贪心过去会出问题。
比如001
我们可以先改变第一个变为111,再改变第二个变为000.也就是说即使第一个是正确的我们可以改变第一个和第二个来使得第一个相当于没变化但是同时改变了第三个。
所以我们枚举第一个变或者不变。
然后贪心过去就可以了。
其实这题本意应该是枚举吧。2^20.
#include <iostream>#include <cmath>#include <algorithm>#include <string>#include <deque>#include <cstring>#include <cstdio>#include <vector>#include <set>#include <map>#include <queue>#include <cstdlib>#include <iomanip>using namespace std;#define rep(i, a, b) for( i = (a); i <= (b); i++)#define reps(i, a, b) for( i = (a); i < (b); i++)#define pb push_back#define ps push#define mp make_pair#define CLR(x,t) memset(x,t,sizeof x)#define LEN(X) strlen(X)#define F first#define S second#define Debug(x) cout<<#x<<"="<<x<<endl;const double euler_r = 0.57721566490153286060651209;const double pi = 3.141592653589793238462643383279;const double E = 2.7182818284590452353602874713526;const int inf=~0U>>1;const int MOD = int(1e9) + 7;const double EPS=1e-6;typedef long long LL;//001int main(){ char s[30]; int a[30], i, b[30]; while(~scanf("%s",s)) { int l = LEN(s); int ans1 = 0, ans2 = 1, f = 0;//cout << l << endl; if(l == 1) { if(s[0] == '0') cout << "0" << endl; else cout << "1" << endl; continue; } reps(i, 0, l) a[i] = s[i] - '0',b[i] = a[i]; // for(i = 1; i < l - 1; i++) { if(a[i-1] == 1) {ans1++;a[i-1] ^= 1;a[i] ^= 1;a[i+1] ^= 1;} } if(a[l-2] == 1) {ans1++;a[l-2] ^= 1;a[l-1]^=1;} if(a[l-1] == 1) { ans1 = inf; } else f++; b[0] ^= 1;b[1] ^= 1; for(i = 1; i < l - 1; i++) { if(b[i-1] == 1) {ans2++;b[i-1] ^= 1;b[i] ^= 1;b[i+1] ^= 1;} } if(b[l-2] == 1) {ans2++;b[l-2] ^= 1;b[l-1]^=1;} if(b[l-1] == 1) { ans2 = inf; } else f++; if(!f) cout << "NO" << endl; else cout << min(ans1, ans2) << endl; } return 0;}
0 0
- hdu2209
- hdu2209
- hdu2209
- HDU2209--翻纸牌游戏
- Hdu2209 翻纸牌游戏
- hdu2209翻纸牌游戏
- 翻纸牌游戏 hdu2209
- HDU2209+POJ3279 枚举+dfs
- HDU2209-翻纸牌游戏
- HDU2209 翻纸牌游戏
- HDU2209:翻纸牌游戏(DFS)
- HDU2209:翻纸牌游戏(DFS)
- HDU2209 翻纸牌游戏【技巧】
- dfs hdu2209 翻纸牌游戏
- hdu2209 翻纸牌游戏-位运算bfs
- POJ1753--HDU2209--深搜翻牌类游戏
- hdu2209翻纸牌游戏(双向bfs)
- hdu2209翻纸牌游戏(bfs+状态压缩)
- 使用Tcl脚本分配FPGA管脚
- 黑马程序员--NSPredicate
- Markdown中插入数学公式的方法
- 金庸武侠小说之我的见解
- 实例学习gcc+gdb+make
- hdu2209
- 改变世界的17个等式
- 滤波器设计指标
- 数字信号处理中各种频率关系
- 学习FPGA的网站推荐
- 常见算法在实际项目中的应用
- dnw下载文件以及开发板硬件出错
- 配置ssh公钥访问oschina
- 使用接插件需要注意的问题