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 ...
随机推荐
- Linux System Programming 学习笔记(九) 内存管理
1. 进程地址空间 Linux中,进程并不是直接操作物理内存地址,而是每个进程关联一个虚拟地址空间 内存页是memory management unit (MMU) 可以管理的最小地址单元 机器的体系 ...
- TroubleShoot:The context has expired (0×80090317)
网上搜了一下,服务器上的时间不正确,在SharePoint 设置中,可以通过管理中心设置下Time Zone 和服务器的时间上一致.
- WEB学习-兼容问题
css选择器 儿子选择器 (IE7开始兼容,IE6不兼容.) div>p{ color:red; } div的儿子p.和div的后代p的截然不同. 能够选择: <div> <p ...
- 小程序-初次进入小程序的授权问题(授权更新后的完整步骤)button主动授权
在此做个笔记 最开始小程序的开发时,信息授权的问题刚完善,后面腾讯就更新了新的授权方式,真心的感到心累. 后来的button,主动授权问题,时间一久就有些忘记了,最近在新开发一个小程序的拆红包活动,需 ...
- Django中使用表单
使用表单 表单用 user 提交数据,是网站中比较重要的一个内容 GET 和 POST 方法 GET 和 POST 的区别 URL,全称是"统一资源定位符".用于对应互联网上的每一 ...
- js - 锚点-scrollIntoView()
document.getElementById("view").scrollIntoView(false);
- Codeforces Gym101606 D.Deranging Hat (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))
D Deranging Hat 这个题简直了,本来想的是冒泡排序然后逆着输出来的,后来发现不对,因为题目上求的是最优解,而且冒泡的话,输出结果有的超出10000行了,所以就是把一开始的,排好序的字母标 ...
- Django简单粗暴快速发送邮件!
>>尽管Python已经提供了相对易用的邮件发送模块 smtplib ,但Django仍对其做了轻度的封装.封装后的模块不仅发送邮件速度快,而且在开发环境下也很容易对邮件发送进行测试, 并 ...
- 缓存区溢出检测工具BED
缓存区溢出检测工具BED 缓存区溢出(Buffer Overflow)是一类常见的漏洞,广泛存在于各种操作系统和软件中.利用缓存区溢出漏洞进行攻击,会导致程序运行失败.系统崩溃.渗透测试人员利用这 ...
- [UOJ#24]【IOI2014】Rail
#24. [IOI2014]Rail 台湾有一个连接着岛的东.西两岸的庞大的铁路线.这个铁路线包含有 mm 个区段.这些相连的区段以数字 0,…,m−10,…,m−1 为编号,且编号由西端开始.每一个 ...