Google Code Jam 2010
Qualification Round 资格赛

Problem A. Snapper Chain 问题A.按扣链条

Problem
The Snapper is a clever little device that, on one side, plugs its input plug into an output socket, and, on the other side, exposes an output socket for plugging in a light or other device.
问题
按扣是一个聪明的小设备,一方面把它的输入插头插到一个输出插口上,另一方面,露出一个输出插口可以用来插入一个灯泡或者其他的设备。

When a Snapper is in the ON state and is receiving power from its input plug, then the device connected to its output socket is receiving power as well. When you snap your fingers -- making a clicking sound -- any Snapper receiving power at the time of the snap toggles between the ON and OFF states.
当一个按扣处于ON状态并且从它的输入插头接收到能量的时候,连接到这个按扣的输出插口的设备也会同样的接收到能量。当你敲击你的手指——制造出一个敲击的响声——任何按扣在ON和OFF之间切换状态的时候都会接收到能量。

In hopes of destroying the universe by means of a singularity, I have purchased N Snapper devices and chained them together by plugging the first one into a power socket, the second one into the first one, and so on. The light is plugged into the Nth Snapper.
希望依靠奇点摧毁宇宙,我购买了N个按扣设备并且把它们串联起来,把第一个按扣插到电源接口上,第二个插到第一个上面,以此类推。把灯泡插到第N个按扣上。

Initially, all the Snappers are in the OFF state, so only the first one is receiving power from the socket, and the light is off. I snap my fingers once, which toggles the first Snapper into the ON state and gives power to the second one. I snap my fingers again, which toggles both Snappers and then promptly cuts power off from the second one, leaving it in the ON state, but with no power. I snap my fingers the third time, which toggles the first Snapper again and gives power to the second one. Now both Snappers are in the ON state, and if my light is plugged into the second Snapper it will be on.
最开始的时候,所有的按扣都在OFF状态,所以只有第一个按扣从插头上接受能量,并且灯是熄灭的。我敲了一个手指头,触发了第一个按扣到ON状态,把能量传给了第二个按扣。我再敲击了一次,触发了这两个按扣,然后立即切断了第二个的能量,它停留在ON状态上,但是没有能量。我第三次敲击手指头,触发了第一个按扣,然后能量传递给第二个按扣,现在这两个按扣都在ON状态上,如果我的灯泡插在第二个按扣上,它现在将会被点亮。

I keep doing this for hours. Will the light be on or off after I have snapped my fingers K times? The light is on if and only if it's receiving power from the Snapper it's plugged into.
我一直重复这个动作几个小时。当我敲击手指头K次之后,灯是亮的还是灭的?灯处于亮的状态仅当它从连接它的按扣处接受到能量。

Input 输入
The first line of the input gives the number of test cases, T. T lines follow. Each one contains two integers, N and K.
输入的第一行给出了测试用例的数量,T。下面跟着T行。每一行包含两个整数,N和K。

Output 输出
For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is either "ON" or "OFF", indicating the state of the light bulb.
对于每一个测试用例,输出一行,包含“Case #x: y",x是用例号码,从一开始,y是ON或者OFF,表示灯的亮灭状态。

Limits 限制
1 ≤ T ≤ 10,000.

Small dataset 小数据集
1 ≤ N ≤ 10;
0 ≤ K ≤ 100;

Large dataset 大数据集
1 ≤ N ≤ 30;
0 ≤ K ≤ 108;

Sample 例子

Input Output
  
4    
1 0   Case #1: OFF
1 1   Case #2: ON
4 0   Case #3: OFF
4 47  Case #4: ON

分析:
整个过程如同一个二进制的加1操作,从0x0开始加K次1。而N可以作为预定的位数。
比如一个8位的二进制数,每一位上都有权值的,128,64,32,16,8,4,2,1.
因此存在一个2^(N-1)和K之间的关系。
对于小数据集来说,N=10的时候2^9=512比K的100大多了,而灯亮的时候只有N位上全为1的情况下才会亮。
因此把K作为十进制数,判断低N位,看看是不是都是1,如果是,则灯是亮的,如果不是,则灯是灭的。
进而,问题转换为一个进制转换的问题。
比如K=47,转换为二进制K=0010 1111,而N=4,满足条件,灯是亮的,因此状态为ON。
进一步,不管K=100还是K=108,K都小于128这个数,要把N每一位的权值加起来。
N   K
1   1
2   3
3   7
4   15
5   31
6   63
7   127
8   255
因此,N有效的最大值为6,当N大于6的时候,只要K在限定范围内,都没法形成足够长度的连续的1序列。因此,进一步限制了数据的取值。
D100-->B0110 0100
D108-->B0110 1100

可以定义函数char D2B(K),一个char类型的,按位存取1或者0,8位长度足够了。
然后需要一个函数来知道char里面有多少个低位连续的1。
int GetLen(D2B(K)) 返回一个整数.然后与N比较一下就可以了。
比较char的时候,可以按位比,用与或之类的,从长到短比较1111 1111~ 0000 0001。

Google Code Jam 2010 Qualification Round 资格赛 Problem A. Snapper Chain 问题A.按扣链条相关推荐

  1. Google Code Jam 2015 Qualification Round: Problem A. Standing Ovation

    昨天被虐的太惨,剩下的题过几天慢慢看.>< 我开始以为只要把每个是0的地方换成1就行了,后来发现之前的level如果人数多的话,后面的level是可以出现0的.== 用pre[]记录之前出 ...

  2. Google code jam 2008, Qualification Round:Save the Universe, 翻译

    英文地址:here 本文仅作学习之用,题目的测试用例下载及答案的上传请到上面的英文地址,有不专业或者错误还请指正. 拯救宇宙 问题 都市里传说如果你去Googl的主页并且搜索"Google& ...

  3. [C++]Standing Ovation——Google Code Jam 2015 Qualification Round

    Problem It's opening night at the opera, and your friend is the prima donna (the lead female singer) ...

  4. Code Jam 2017 Qualification Round Problem A. Oversized Pancake Flipper

    题目 给定字符串 S 由+或-组成和 K ,现有一种操作:能将串 S 中连续 K 个字符进行反转( + 变成-以及 -变成+ ).问最少进行多少次上述操作,可以把串 S 变成全由 + 组成.当然也可能 ...

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

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

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

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

  7. 【Google Code Jam】Millionaire

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

  8. 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 ...

  9. 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 ...

  10. 2015 Google code jam Qualification Round A 水

    题意:给你一个序列 从 0-n  初始位置为0 ,只能从 i 走到 i+1  你必要有的人数 >= i+1  ,每个位置有a[i]个人,问你走到 n 还需要多少个人. 解题思路:暴力 解题代码: ...

最新文章

  1. VM Depot 分布式计算框架主题应用精选
  2. 学习java的一些笔记(8)
  3. 【Android 逆向】修改运行中的 Android 进程的内存数据 ( 运行环境搭建 Android 模拟器安装 | 拷贝 Android 平台可执行文件和动态库到 /data/system )
  4. python windows窗口开发_Windows 平台做 Python 开发的最佳组合
  5. java代码轻量级锁_Java轻量级锁原理详解(Lightweight Locking)
  6. 自动化测试之--参数化
  7. linux svn 设置propertise
  8. 营业收费系统 建立报表库服务器,浅谈计算机在自来水收费系统的重要应用
  9. 安卓系统添加字体库和修改系统默认的字体
  10. 西南大学计算机学院导师,西南大学计算机与信息科学学院研究生导师简介-胡小方...
  11. 2023年美业市场五大消费趋势
  12. 一线城市房价集体下跌暗藏啥玄机?
  13. Wamp80端口被占用
  14. Eclipse RCP入门
  15. TI DLP4500EVM轻度使用——Pattern创建、烧录、投影
  16. [Python]tabulate可如此优雅地创建表格
  17. 谭浩强C语言(第三版)习题10.4
  18. 软件开发-BS与CS架构
  19. 《Android源码设计模式解析与实战》读书笔记(二十一)
  20. MZ深度解读SAP常见财务问题-02-账套在哪里?

热门文章

  1. Typora图片云存储
  2. 全网域名已注册、未注册批量查询工具
  3. android系统蓝牙音箱功能吗,Android蓝牙开发系列文章-其实你的手机可以变成一个蓝牙音箱...
  4. Linux 管道 管道命令 命名管道
  5. dhcp服务器不显示mac地址,利用MAC地址解决无法获得DHCP动态地址分配问题
  6. STL——标准模板库
  7. 关于数据库、数据治理、AIOps的这些痛点,你需要知道! | DAMS 2020
  8. 数据分析——两种求解R平方的方法
  9. 用python实现微信定时发送图片
  10. 在传统软件公司十年深恶痛绝的感受(转)