GCJ Qualification Round 2016 B题
经典的翻饼问题,直接做:从下往上看,已翻好的饼忽略掉;从上往下,连续的已翻好的一起翻过来;整个翻过来。
/*
* 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题的更多相关文章
- GCJ Qualification Round 2016 D题
这题就是找规律.小数据还是挺容易想的.大数据得再深入分析一下. 题意挺绕的. 其实就是字符串转换.字符串只能有两种字母,L或G.给定K和C,就能通过规则生成目标字符串. 那么,如果知道了K和C,以及目 ...
- GCJ Qualification Round 2016 C题
题意是给定了一个叫“jamcoin”的定义,让你生成足够数量满足条件的jamcoin. jamcoin其实就可以理解成一个二进制整数,题目要求的要么长度为16位,要么为32位,一头一尾两个位必须是1, ...
- Facebook Hacker Cup 2014 Qualification Round 竞赛试题 Square Detector 解题报告
Facebook Hacker Cup 2014 Qualification Round比赛Square Detector题的解题报告.单击这里打开题目链接(国内访问需要那个,你懂的). 原题如下: ...
- Facebook Hacker Cup 2014 Qualification Round
2014 Qualification Round Solutions 2013年11月25日下午 1:34 ...最简单的一题又有bug...自以为是真是很厉害! 1. Square Detector ...
- [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 ...
- DP VK Cup 2012 Qualification Round D. Palindrome pairs
题目地址:http://blog.csdn.net/shiyuankongbu/article/details/10004443 /* 题意:在i前面找回文子串,在i后面找回文子串相互配对,问有几对 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Road(bzoj 2750)
Description C国有n座城市,城市之间通过m条单向道路连接.一条路径被称为最短路,当且仅当不存在从它的起点到终点的另外一条路径总长度比它小.两条最短路不同,当且仅当它们包含的道路序列不同.我 ...
- SharePoint 2013 Custom MasterPage
<%@Master language="C#"%> <%@ Register Tagprefix="SharePoint" Namespace ...
- 【Visual Studio】The project appears to be under source control, but the associated source control plug-in is not installed on this computer
[问题描述]用 Visual Studio 2013打开一个项目时,出现下面错误: [问题原因]参考 http://codeverge.com/asp.net.web-forms/the-projec ...
- 标准C程序设计七---104
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- 浅谈MVP设计模式
最近公司在做一个医疗项目,使用WinForm界面作为客户端交互界面.在整个客户端解决方案中.使用了MVP模式实现.由于之前没有接触过该设计模式,所以在项目完成到某个阶段时,将使用MVP的体会写在博客里 ...
- 微信小程序踩坑之一[wx.request]请求模式
最近在做小程序时,使用wx.request()方法请求时, 当使传输string类型时,一定要声明method请求模式为post,否则会一直报错,而不声明时默认为get, 已填坑 =,= wx.req ...
- VUE2.0 【v-html】标签使用技巧
<div class="active-rules"> <div class="weui-weixin-content" id="ru ...
- Codeforces 919 B. Perfect Number
B. Perfect Number time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 继承LIst 的类JSON序列化,无法序列化属性的问题
/// <summary> /// Paged list /// </summary> /// <typeparam name="T">T< ...
- 为什么BT网络中迅雷的速度会这么快,比其它BT软件快
先看迅雷加速通道的几个概论,参考:http://www.cnblogs.com/EasonJim/p/6608544.html 我个人理解,在传统BT软件中,基于P2P的网络是不具备以上条件去加速的, ...