经典的翻饼问题,直接做:从下往上看,已翻好的饼忽略掉;从上往下,连续的已翻好的一起翻过来;整个翻过来。

/*
* 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[];
bool pan[];
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 % == ) {
pan[n / ] = !pan[n / ];
}
} int work() {
int ans = ;
while (pannum > ) {
while (pannum > && pan[pannum - ]) {
pannum--;
}
if (pannum <= ) {
break;
}
int I = ;
while (pan[I]) {
I++;
}
if (I > ) {
flippan(I);
ans++;
}
flippan(pannum);
ans++;
}
return ans;
} int main() {
// freopen("b.small.in", "r", stdin);
int T;
scanf("%d", &T);
for (int t = ; t <= T; t++) {
scanf(" %s", pancakes);
pannum = strlen(pancakes);
for (int i = ; i < pannum; i++) {
if (pancakes[i] == '-') {
pan[i] = ;
} else {
pan[i] = ;
}
}
printf("Case #%d: %d\n", t, work());
}
return ;
}

GCJ Qualification Round 2016 B题的更多相关文章

  1. GCJ Qualification Round 2016 D题

    这题就是找规律.小数据还是挺容易想的.大数据得再深入分析一下. 题意挺绕的. 其实就是字符串转换.字符串只能有两种字母,L或G.给定K和C,就能通过规则生成目标字符串. 那么,如果知道了K和C,以及目 ...

  2. GCJ Qualification Round 2016 C题

    题意是给定了一个叫“jamcoin”的定义,让你生成足够数量满足条件的jamcoin. jamcoin其实就可以理解成一个二进制整数,题目要求的要么长度为16位,要么为32位,一头一尾两个位必须是1, ...

  3. Facebook Hacker Cup 2014 Qualification Round 竞赛试题 Square Detector 解题报告

    Facebook Hacker Cup 2014 Qualification Round比赛Square Detector题的解题报告.单击这里打开题目链接(国内访问需要那个,你懂的). 原题如下: ...

  4. Facebook Hacker Cup 2014 Qualification Round

    2014 Qualification Round Solutions 2013年11月25日下午 1:34 ...最简单的一题又有bug...自以为是真是很厉害! 1. Square Detector ...

  5. [C++]Store Credit——Google Code Jam Qualification Round Africa 2010

    Google Code Jam Qualification Round Africa 2010 的第一题,很简单. Problem You receive a credit C at a local ...

  6. DP VK Cup 2012 Qualification Round D. Palindrome pairs

    题目地址:http://blog.csdn.net/shiyuankongbu/article/details/10004443 /* 题意:在i前面找回文子串,在i后面找回文子串相互配对,问有几对 ...

  7. Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words

    Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words https://code.google.com/cod ...

  8. Google Code Jam Africa 2010 Qualification Round Problem A. Store Credit

    Google Code Jam Qualification Round Africa 2010 Problem A. Store Credit https://code.google.com/code ...

  9. VK Cup 2016 - Qualification Round 2 A. Home Numbers 水题

    A. Home Numbers 题目连接: http://www.codeforces.com/contest/638/problem/A Description The main street of ...

随机推荐

  1. 快速沃尔什变换 FWT

    FWT 是处理位运算卷积的有效工具…… 原理……不懂,但背板子很简单,在这贴博客是为了放个模板,免得到时候忘记. 其中0为或卷积,1为与卷积,2为异或卷积…… void FWT(long long a ...

  2. 高阶函数之函数柯里化function currying

    var cost = (function(){    var args = [];    return function(){        if(arguments.length === 0){   ...

  3. 下拉菜单的option的value属性值问题

    下拉菜单的所有option都必须有value值,如果没有value会将标签中间的值传上去: 比如: <span class="el_spans">试卷级别:</s ...

  4. hdu 1250(大整数)

    Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  5. js-触屏滑动判断滑动方向(移动版)

    var startx, starty; //获得角度 function getAngle(angx, angy) {     return Math.atan2(angy, angx) * 180 / ...

  6. (1)JavaScript基础1

    一.javaScript 由三部分组成 1.核心(ECMAScript) 2.文档对象模型(DOM) 3.浏览器对象模型(BOM) 二.在html中使用javascript HTML5模板 <! ...

  7. python安装numpy和matplotlib

    1.从该链接下载对应的whl文件 2.按照下面的方式从whl文件安装即可 windows7 python2.7 1.用管理员方式打开cmd 2.首先通过pip命令安装wheel 如果提示’pip’不是 ...

  8. codevs——1700 施工方案第二季

    1700 施工方案第二季 2012年市队选拔赛北京  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description c国边防 ...

  9. Xamarin XAML语言教程基础语法篇大学霸

    Xamarin XAML语言教程基础语法篇大学霸 前  言 Xamarin是一个跨平台开发框架.它可以用来开发iOS.Android.Windows Phone和Mac的应用程序.使用Xamarin框 ...

  10. 把Execl表格中的数据获取出来保存到数据库中

    比如我们遇到一些需要把execl表格中的数据保存到数据库中,一条一条保存效率底下而且容易出错,数据量少还好,一旦遇到数据量大的时候就会累死个人啊,下面我们就来把execl表格中数据保存到对应的数据库中 ...