GCJ Qualification Round 2016 B题
2016-04-09 11:17
435 查看
经典的翻饼问题,直接做:从下往上看,已翻好的饼忽略掉;从上往下,连续的已翻好的一起翻过来;整个翻过来。
/* * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostream> #include <algorithm> #include <queue> #include <set> #include <map> #include <stack> #include <string> #include <vector> #include <deque> #include <list> #include <functional> #include <numeric> #include <cctype> using namespace std; typedef long long LL; char pancakes[110]; bool pan[110]; int pannum; void inline flippan(int n) { bool *first = pan; bool *last = first + n; while ((first != last) && (first != --last)) { bool tmp = !(*last); *last = !(*first); *first = tmp; ++first; } if (n % 2 == 1) { pan[n / 2] = !pan[n / 2]; } } int work() { int ans = 0; while (pannum > 0) { while (pannum > 0 && pan[pannum - 1]) { pannum--; } if (pannum <= 0) { break; } int I = 0; while (pan[I]) { I++; } if (I > 0) { flippan(I); ans++; } flippan(pannum); ans++; } return ans; } int main() { // freopen("b.small.in", "r", stdin); int T; scanf("%d", &T); for (int t = 1; t <= T; t++) { scanf(" %s", pancakes); pannum = strlen(pancakes); for (int i = 0; i < pannum; i++) { if (pancakes[i] == '-') { pan[i] = 0; } else { pan[i] = 1; } } printf("Case #%d: %d\n", t, work()); } return 0; }
相关文章推荐
- gnuplot_i 文件的说明,翻译成的中文
- Java ThreadManager(线程池管理类)-网络频繁访问处理机制
- 2016年3月14日作业-项目管理一般知识+立项管理
- CCHTTPRequestAndroid() 与 curl处理方式不同的问题
- android 在应用中切换语言
- SpringMvc 3.2配置指南
- Android代码中设置TextView的字体
- Android 三种常用多线程实现方式解析
- 1.javascript基础
- linux 64位机编译32位程序
- 3D touch功能的封装
- Android MultiDex实践:如何绕过那些坑?
- k-means聚类JAVA实例
- Delphi2010怎样获取程序内部自身版本?
- response、request的使用
- Hadoop ClassPath
- Linux命令行:pwd命令
- PSR-1 基本编码规范
- 周期字串
- 蓝桥杯-基础练习-杨辉三角形