https://code.google.com/codejam/contest/3264486/dashboard#s=p3

Oversized Pancake Flipper

(1)问题描述:

ProblemLast year, the Infinite House of Pancakes introduced a new kind of pancake. It has a happy face made of chocolate chips on one side (the "happy side"), and nothing on the other side (the "blank side").
You are the head cook on duty. The pancakes are cooked in a single row over a hot surface. As part of its infinite efforts to maximize efficiency, the House has recently given you an oversized pancake flipper that flips exactly K consecutive pancakes. That is, in that range of K pancakes, it changes every happy-side pancake to a blank-side pancake, and vice versa; it does not change the left-to-right order of those pancakes.
You cannot flip fewer than K pancakes at a time with the flipper, even at the ends of the row (since there are raised borders on both sides of the cooking surface). For example, you can flip the first K pancakes, but not the first K - 1 pancakes.
Your apprentice cook, who is still learning the job, just used the old-fashioned single-pancake flipper to flip some individual pancakes and then ran to the restroom with it, right before the time when customers come to visit the kitchen. You only have the oversized pancake flipper left, and you need to use it quickly to leave all the cooking pancakes happy side up, so that the customers leave feeling happy with their visit.
Given the current state of the pancakes, calculate the minimum number of uses of the oversized pancake flipper needed to leave all pancakes happy side up, or state that there is no way to do it.
InputThe first line of the input gives the number of test cases, T. T test cases follow. Each consists of one line with a string S and an integer K. S represents the row of pancakes: each of its characters is either + (which represents a pancake that is initially happy side up) or - (which represents a pancake that is initially blank side up).
OutputFor each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is either IMPOSSIBLE if there is no way to get all the pancakes happy side up, or an integer representing the the minimum number of times you will need to use the oversized pancake flipper to do it.
Limits1 ≤ T ≤ 100.
Every character in S is either + or -.
2 ≤ K ≤ length of S.
Small dataset2 ≤ length of S ≤ 10.
Large dataset2 ≤ length of S ≤ 1000.
SampleInput Output 3
---+-++- 3
+++++ 4
-+-+- 4Case #1: 3
Case #2: 0
Case #3: IMPOSSIBLE
In Case #1, you can get all the pancakes happy side up by first flipping the leftmost 3 pancakes, getting to ++++-++-, then the rightmost 3, getting to ++++---+, and finally the 3 pancakes that remain blank side up. There are other ways to do it with 3 flips or more, but none with fewer than 3 flips.
In Case #2, all of the pancakes are already happy side up, so there is no need to flip any of them.
In Case #3, there is no way to make the second and third pancakes from the left have the same side up, because any flip flips them both. Therefore, there is no way to make all of the pancakes happy side up.

(2)要点:从最左边起,每一个‘-‘’都需要变成'+'

(3)代码:

#include <stdio.h>
#include <string.h>int main()
{static const size_t buff_size = 1000;unsigned int nCases = 0;scanf("%d",&nCases);for(unsigned int iCases = 1;iCases <= nCases;++iCases){char buff[buff_size+1] = { 0 };unsigned int k = 0,ans = 0;scanf("%s%d",buff,&k);for(size_t i = 0,len = strlen(buff);i + k <= len;++i){if(buff[i] == '+') continue;++ ans;for(size_t j = 0;j < k;++j) buff[i+j] = '+' + '-' - buff[i+j];}for(size_t i = 0,len = strlen(buff);i < len;++i){if(buff[i] == '-'){ans = (unsigned int)(-1);break;}}printf("Case #%d: ",iCases);if((unsigned int)(-1) == ans) printf("IMPOSSIBLE\n");else printf("%d\n",ans);}return 0;
}

Tidy Numbers

(1)问题描述:

ProblemTatiana likes to keep things tidy. Her toys are sorted from smallest to largest, her pencils are sorted from shortest to longest and her computers from oldest to newest. One day, when practicing her counting skills, she noticed that some integers, when written in base 10 with no leading zeroes, have their digits sorted in non-decreasing order. Some examples of this are 8, 123, 555, and 224488. She decided to call these numbers tidy. Numbers that do not have this property, like 20, 321, 495 and 999990, are not tidy.
She just finished counting all positive integers in ascending order from 1 to N. What was the last tidy number she counted?
InputThe first line of the input gives the number of test cases, T. T lines follow. Each line describes a test case with a single integer N, the last number counted by Tatiana.
OutputFor each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the last tidy number counted by Tatiana.
Limits1 ≤ T ≤ 100.
Small dataset1 ≤ N ≤ 1000.
Large dataset1 ≤ N ≤ 1018.
SampleInput Output 4
132
1000
7
111111111111111110Case #1: 129
Case #2: 999
Case #3: 7
Case #4: 99999999999999999Note that the last sample case would not appear in the Small dataset.

(2)要点:从最低位开始,将其变成v - 1,后面变成9,如果变化后的不满足条件也往前一位尝试

(3)代码:

#include <stdio.h>
#include <string.h>
#include <assert.h>template<class data_t> inline data_t str_to_int(const unsigned int* digit,size_t size)
{data_t num = 0;for(size_t i = size - 1;i != (size_t)(-1);--i){num *= 10;num += digit[i];}return num;
} template<class data_t> inline size_t int_to_str(data_t num,unsigned int* digit,size_t size)
{memset(digit,0,sizeof(unsigned int)*size);size_t pos = 0;if(0 == num) ++ pos;for(;num > 0;num /= 10,++pos) digit[pos] = num%10;  return pos;
}bool is_tidy(const unsigned int* digit,size_t size)
{for(size_t i = 0;i + 1 < size;++i){if(digit[i] < digit[i+1]) return false;}return true;
}int main()
{static const size_t buff_size = 100;unsigned int nCases = 0;scanf("%d",&nCases);for(unsigned int iCases = 1;iCases <= nCases;++iCases){unsigned long long v = 0;scanf("%I64d",&v);unsigned int digit[buff_size] = { 0 },output[buff_size] = { 0 };size_t pos = int_to_str(v,digit,buff_size);unsigned long long ans = 0;if(is_tidy(digit,pos)) ans = v;else{for(size_t i = 0;i < pos;++i){if(0 == digit[i]) continue;output[pos] = 0;for(size_t j = pos - 1;j != i;--j) output[j] = digit[j];output[i] = digit[i] - 1;for(size_t j = i - 1;j != (size_t)(-1);--j) output[j] = 9;if(is_tidy(output,pos)){ans = str_to_int<unsigned long long>(output,pos);break;}}}printf("Case #%u: %I64u\n",iCases,ans);}return 0;
}

Bathroom Stalls

(1)问题描述:

ProblemA certain bathroom has N + 2 stalls in a single row; the stalls on the left and right ends are permanently occupied by the bathroom guards. The other N stalls are for users.
Whenever someone enters the bathroom, they try to choose a stall that is as far from other people as possible. To avoid confusion, they follow deterministic rules: For each empty stall S, they compute two values LS and RS, each of which is the number of empty stalls between S and the closest occupied stall to the left or right, respectively. Then they consider the set of stalls with the farthest closest neighbor, that is, those S for which min(LS, RS) is maximal. If there is only one such stall, they choose it; otherwise, they choose the one among those where max(LS, RS) is maximal. If there are still multiple tied stalls, they choose the leftmost stall among those.
K people are about to enter the bathroom; each one will choose their stall before the next arrives. Nobody will ever leave.
When the last person chooses their stall S, what will be the values of max(LS, RS) and min(LS, RS) be?
Solving this problemThis problem has 2 Small datasets and 1 Large dataset. You must solve the first Small dataset before you can attempt the second Small dataset. You will be able to retry either of the Small datasets (with a time penalty). You will be able to make a single attempt at the Large, as usual, only after solving both Small datasets.
InputThe first line of the input gives the number of test cases, T. T lines follow. Each line describes a test case with two integers N and K, as described above.
OutputFor each test case, output one line containing Case #x: y z, where x is the test case number (starting from 1), y is max(LS, RS), and z is min(LS, RS) as calculated by the last person to enter the bathroom for their chosen stall S.
Limits1 ≤ T ≤ 100.
1 ≤ K ≤ N.
Small dataset 11 ≤ N ≤ 1000.
Small dataset 21 ≤ N ≤ 106.
Large dataset1 ≤ N ≤ 1018.
SampleInput Output 5
4 2
5 2
6 2
1000 1000
1000 1Case #1: 1 0
Case #2: 1 0
Case #3: 1 1
Case #4: 0 0
Case #5: 500 499In Case #1, the first person occupies the leftmost of the middle two stalls, leaving the following configuration (O stands for an occupied stall and . for an empty one): O.O..O. Then, the second and last person occupies the stall immediately to the right, leaving 1 empty stall on one side and none on the other.
In Case #2, the first person occupies the middle stall, getting to O..O..O. Then, the second and last person occupies the leftmost stall.
In Case #3, the first person occupies the leftmost of the two middle stalls, leaving O..O...O. The second person then occupies the middle of the three consecutive empty stalls.
In Case #4, every stall is occupied at the end, no matter what the stall choices are.
In Case #5, the first and only person chooses the leftmost middle stall.

(2)要点:归纳法总结规律

(3)代码:

#include <stdio.h>
#include <assert.h>int main()
{static const size_t size = 64;unsigned long long exps[size] = { 1 };for(size_t i = 1;i < size;++i) exps[i] = exps[i-1]*2;unsigned int nCases = 0;scanf("%d",&nCases);for(unsigned int iCases = 1;iCases <= nCases;++iCases){unsigned long long n = 0,p = 0,x = 0;scanf("%I64d%I64d",&n,&p);assert(p <= n && n < exps[size-1] && 0 != p);size_t k = size - 1;for(;p < exps[k];--k);x = p - exps[k];unsigned long long a = n%exps[k] + 1;unsigned long long b = exps[k] - a;unsigned long long ans = 0;if(x < a) ans = n/exps[k];else ans = n/exps[k] - 1;unsigned long long minans = 0,maxns = 0;if(ans&1) minans = ans/2,maxns = ans/2;else minans = ans/2 - 1,maxns = ans/2;printf("Case #%u: %I64u %I64u\n",iCases,maxns,minans);}return 0;
}

Fashion Show

(1)问题描述:

ProblemYou are about to host a fashion show to show off three new styles of clothing. The show will be held on a stage which is in the most fashionable of all shapes: an N-by-N grid of cells.
Each cell in the grid can be empty (which we represent with a . character) or can contain one fashion model. The models come in three types, depending on the clothing style they are wearing: +, x, and the super-trendy o. A cell with a + or x model in it adds 1 style pointto the show. A cell with an o model in it adds 2 style points. Empty cells add no style points.
To achieve the maximum artistic effect, there are rules on how models can be placed relative to each other.
Whenever any two models share a row or column, at least one of the two must be a +.
Whenever any two models share a diagonal of the grid, at least one of the two must be an x.
Formally, a model located in row i0 and column j0 and a model located in row i1 and column j1 share a row if and only if i0 = i1, they share a column if and only if j0 = j1, and they share a diagonal if and only if i0 + j0 = i1 + j1 or i0 - j0 = i1 - j1.
For example, the following grid is not legal:
...
x+o
.+.
The middle row has a pair of models (x and o) that does not include a +. The diagonal starting at the + in the bottom row and running up to the o in the middle row has two models, and neither of them is an x.
However, the following grid is legal. No row, column, or diagonal violates the rules.
+.x
+x+
o..
Your artistic advisor has already placed M models in certain cells, following these rules. You are free to place any number (including zero) of additional models of whichever types you like. You may not remove existing models, but you may upgrade as many existing +and x models into o models as you wish, as long as the above rules are not violated.
Your task is to find a legal way of placing and/or upgrading models that earns the maximum possible number of style points.
InputThe first line of the input gives the number of test cases, T. T test cases follow. Each test case begins with one line with two integers N and M, as described above. Then, Mmore lines follow; the i-th of these lines has a +, x, or o character (the type of the model) and two integers Ri and Ci (the position of the model). The rows of the grid are numbered 1 through N, from top to bottom. The columns of the grid are numbered 1 through N, from left to right.
OutputFor each test case, first output one line containing Case #x: y z, where x is the test case number (starting from 1), y is the number of style points earned in your arrangement, and z is the total number of models you have added and/or substituted in. Then, for each model that you have added or substituted in, output exactly one line in exactly the same format described in the Input section, where the character is the type of the model that you have added or substituted in. These z lines can be in any order.
If there are multiple valid answers, you may output any one of them.
Limits1 ≤ T ≤ 100.
1 ≤ N ≤ 100.
1 ≤ Ci ≤ N, for all i.
0 ≤ M ≤ N2.
No two pre-placed models appear in the same cell.
It is guaranteed that the set of pre-placed models follows the rules.
Small datasetRi = 1, for all i. (Any models that are pre-placed are in the top row. Note that you may add/replace models in that row and/or add models in other rows.)
Large dataset1 ≤ Ri ≤ N, for all i.
SampleInput Output 3
2 0
1 1
o 1 1
3 4
+ 2 3
+ 2 1
x 3 1
+ 2 2Case #1: 4 3
o 2 2
+ 2 1
x 1 1
Case #2: 2 0
Case #3: 6 2
o 2 3
x 1 2The sample output displays one set of answers to the sample cases. Other answers may be possible. Note that the last sample case would not appear in the Small dataset.
In sample case #1, the grid is 2-by-2 and is initially blank. The output corresponds to the following grid. (In these explanations, we will use . to denote a blank cell.)
x.
+o
In sample case #2, the only cell is already occupied by an o model, and it is impossible to add a new model or replace the o model.
In sample case #3, the grid looks like this before you place any models:
...
+++
x..
The output corresponds to this grid:
.x.
++o
x..

(2)要点:

(3)代码:

Google Code Jam 2017 资格赛相关推荐

  1. 入职顶级互联网公司,竞争性编程是必须的吗?Google code jam King赛前采访(附有视频)

    主持人:你能告诉我一些关于你自己的事吗 受访者:就像我决定从事的竞争性编程一样,竞争性编程我不仅参加了那些比赛,高中时我在美国参加Google Code Jam,因为我进入了决赛,这是我生命中的一部分 ...

  2. Google Code Jam程序设计大赛中国人获冠亚军

    来自 Google的官方消息,今年的Google Code Jam程序设计大赛,冠亚军都被中国人获得. 冠军是楼天城(Tiancheng Lou,来自清华大学计算机系),奖金$10,000.亚军朱泽园 ...

  3. 【Google Code Jam】Millionaire

    题目描述 Google Code Jam 2008APAC local onsites C 最开始你有X元钱,要进行M轮赌博.每一轮赢的概率为P,你可以选择赌与不赌,如果赌也可以将所持的任意一部分钱作 ...

  4. Google Code Jam Round 1A 2015 解题报告

    题目链接:https://code.google.com/codejam/contest/4224486/ Problem A. Mushroom Monster 这题题意就是,有N个时间点,每个时间 ...

  5. [Google Code Jam] 2013-1A-C Good Luck 解法

    问题的陈述在:https://code.google.com/codejam/contest/2418487/dashboard#s=p2&a=1, 官方的分析在:https://code.g ...

  6. dp - Google Code jam Qualification Round 2015 --- Problem B. Infinite House of Pancakes

    Problem B. Infinite House of Pancakes Problem's Link:   https://code.google.com/codejam/contest/6224 ...

  7. Google Code Jam 2014 -- C

    题目链接:https://code.google.com/codejam/contest/2974486/dashboard#s=p2 比赛的时候想出了小数据的处理办法, 位压缩然后枚举+BFS, 但 ...

  8. Google Code jam Qualification Round 2015 --- Problem A. Standing Ovation

    Problem A. Standing Ovation Problem's Link:   https://code.google.com/codejam/contest/6224486/dashbo ...

  9. Google Code Jam 2014 总结

    第一次参加ACM竞赛,对自己取得的成绩还满意. Round1A: Rank: 2446 Score: 9 (没有进前1000名,只能拼下次了) Round1B: Rank: 944 Score: 42 ...

最新文章

  1. 你只使用到了 VS Code 20% 的功能?听听 VS Code 首著作者怎么说
  2. 集合框架源码分析三(实现类篇ArrayList,LinkedList,HashMap)
  3. spring boot / cloud (十七) 快速搭建注册中心和配置中心
  4. 基于RadeonRays的光线追踪全局光照实现方案
  5. 后缀的形容词_构词法(18)构成形容词的常见后缀 3
  6. 小程序swiper-item内容过多显示不全的解决方案
  7. 聊聊eureka的preferSameZoneEureka参数
  8. 多渠道打包之动态修改App名称,图标,applicationId,版本号,添加资源
  9. Java开发人员2021年的职位描述和职责
  10. 调用登录接口返回“参数错误”
  11. PPT学习整理(五)编辑顶点
  12. AUTOSAR OTA升级
  13. 实例讲解spark在京东智能供应链预测系统的应用
  14. process monitor解决网络问题一则
  15. tkinter可视化天气查询
  16. Mysql Unique Key 报错 Duplicate
  17. spicy之evt接口定义文件
  18. Windows-给Administrator设置指纹登陆
  19. 弘辽科技跨境电商创业,你了解多少?看老司机怎么说
  20. 【建站篇】如何将本地搭建的织梦站点上传到服务器空间?

热门文章

  1. 百度违规屏蔽关键词判定标准查询工具
  2. html游戏寻宝源码,阅途方法丨No.8: Compare and Contrast,来一次原版阅读的'寻宝游戏'!...
  3. Spider数据集arxiv1809.08887论文研读
  4. android 视频特效,安卓特效相机(四) 视频录制
  5. 动态壁纸,视频特效- Android
  6. 【ESP32DEVKITV1学习笔记】点亮一盏LED灯
  7. Linux 常用命令实践
  8. 微型计算机的典型结构式,试卷正文1新.doc
  9. MDK537添加ARMCC编译器(Missing: Compiler Version 5的解决办法)
  10. 操作系统 ucore lab1 练习2-6