Google Code Jam 2014 Round 1 A:Problem A Charging Chaos
Problem
Shota the farmer has a problem. He has just moved into his newly built farmhouse, but it turns out that the outlets haven't been configured correctly for all of his devices. Being a modern farmer, Shota owns a large number of smartphones and laptops, and even owns a tablet for his favorite cow Wagyu to use. In total, he owns N different devices.
As these devices have different specifications and are made by a variety of companies, they each require a different electric flow to charge. Similarly, each outlet in the house outputs a specific electric flow. An electric flow can be represented by a string of 0s and 1s of length L.
Shota would like to be able to charge all N of his devices at the same time. Coincidentally, there are exactly N outlets in his new house. In order to configure the electric flow from the outlets, there is a master control panel with L switches. The ithswitch flips the ith bit of the electric flow from each outlet in the house. For example, if the electric flow from the outlets is:
Outlet 0: 10
Outlet 1: 01
Outlet 2: 11
Then flipping the second switch will reconfigure the electric flow to:
Outlet 0: 11
Outlet 1: 00
Outlet 2: 10
If Shota has a smartphone that needs flow "11" to charge, a tablet that needs flow "10" to charge, and a laptop that needs flow "00" to charge, then flipping the second switch will make him very happy!
Misaki has been hired by Shota to help him solve this problem. She has measured the electric flows from the outlets in the house, and noticed that they are all different. Decide if it is possible for Shota to charge all of his devices at the same time, and if it is possible, figure out the minimum number of switches that needs to be flipped, because the switches are big and heavy and Misaki doesn't want to flip more than what she needs to.
Input
The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of three lines. The first line contains two space-separated integers Nand L. The second line contains N space-separated strings of length L, representing the initial electric flow from the outlets. The third line also contains N space-separated strings of length L, representing the electric flow required by Shota's devices.
Output
For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the minimum number of switches to be flipped in order for Shota to charge all his devices. If it is impossible, y should be the string "NOT POSSIBLE" (without the quotes). Please note that our judge is not case-sensitive, but it is strict in other ways: so although "not possible" will be judged correct, any misspelling will be judged wrong. We suggest copying/pasting the string NOT POSSIBLE into your code.
Limits
1 ≤ T ≤ 100. No two outlets will be producing the same electric flow, initially. No two devices will require the same electric flow.
Small dataset
1 ≤ N ≤ 10. 2 ≤ L ≤ 10.
Large dataset
1 ≤ N ≤ 150. 10 ≤ L ≤ 40.
Sample
Input | Output |
3 |
Case #1: 1 |
Explanation
In the first example case, Misaki can flip the second switch once. The electric flow from the outlets becomes:
Outlet 0: 00
Outlet 1: 10
Outlet 2: 11
Then Shota can use the outlet 0 to charge device 1, the outlet 1 to charge device 2, outlet 2 to charge device 0. This is also a solution that requires the minimum amount number of switches to be flipped.
Google Code Jam 2014 Round 1 A:Problem A Charging Chaos的更多相关文章
- Google Code Jam 2014 Round 1 A:Problem C. Proper Shuffle
Problem A permutation of size N is a sequence of N numbers, each between 0 and N-1, where each numbe ...
- Google Code Jam 2014 Round 1 A:Problem B. Full Binary Tree
Problem A tree is a connected graph with no cycles. A rooted tree is a tree in which one special ver ...
- Google Code Jam 2014 Round 1B Problem B
二进制数位DP,涉及到数字的按位与操作. 查看官方解题报告 #include <cstdio> #include <cstdlib> #include <cstring& ...
- [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 ...
- Google Code Jam 2010 Round 1C Problem A. Rope Intranet
Google Code Jam 2010 Round 1C Problem A. Rope Intranet https://code.google.com/codejam/contest/61910 ...
- [Google Code Jam (Qualification Round 2014) ] B. Cookie Clicker Alpha
Problem B. Cookie Clicker Alpha Introduction Cookie Clicker is a Javascript game by Orteil, where ...
- [Google Code Jam (Qualification Round 2014) ] A. Magic Trick
Problem A. Magic Trick Small input6 points You have solved this input set. Note: To advance to the ...
- Google Code Jam 2014 资格赛:Problem B. Cookie Clicker Alpha
Introduction Cookie Clicker is a Javascript game by Orteil, where players click on a picture of a gi ...
- [C++]Saving the Universe——Google Code Jam Qualification Round 2008
Google Code Jam 2008 资格赛的第一题:Saving the Universe. 问题描述如下: Problem The urban legend goes that if you ...
随机推荐
- [BZOJ 1412] 狼与羊的故事
Link: BZOJ 1412 传送门 Solution: 非常明显的最小割模型: 将所有点分成两个互不相邻的点集,且要求代价最小 建图: $<S,sheep,INF>$ $<wol ...
- POJ 2686 Traveling by Stagecoach(状压DP)
[题目链接] http://poj.org/problem?id=2686 [题目大意] 给出一张无向图,你有n张马车票每张车票可以租用ti匹马, 用一张马车票从一个城市到另一个城市所用的时间为这两个 ...
- POJ 3264 Balanced Lineup(zkw线段树)
[题目链接] http://poj.org/problem?id=3264 [题目大意] 求区间最大值和最小值的差值 [题解] 线段树维护区间极值即可 [代码] #include <cstdio ...
- JDBC完整版实现
package songyan.jdbc.test; import java.sql.Connection; import java.sql.DriverManager; import java.sq ...
- sql server 性能调优 资源等待之内存瓶颈的三种等待类型
原文:sql server 性能调优 资源等待之内存瓶颈的三种等待类型 一.概述 这篇介绍Stolen内存相关的主要三种等待类型以及对应的waittype编号,CMEMTHREAD(0x00B9),S ...
- 如何快速搜索SQL数据库数据和对象
原文 如何快速搜索SQL数据库数据和对象 Frequently, developers and DBAs need to search databases for objects or data. I ...
- SimpleDateFormat关于时间类的一些常用处理
项目中经常会出现对时间类的一些处理,记录一下: 实例一:/** * 获取当前时间是星期几? * * @param args */ public static void main(String[] ar ...
- 【Todo】【转载】Java中的锁机制2 - Lock
参考这篇文章 http://blog.csdn.net/chen77716/article/details/6641477 上一篇 (http://www.cnblogs.com/charlesblc ...
- 使用echarts简单制作中国地图,echarts中国地图
网站需要一张中国地图,并且鼠标经过某个省份,该省份的省份名字显示,而且该省份的地区会变色显示. 第一种方法: 将每个省份的图片定位(先隐藏),拼合成一张中国地图,然后再定位省份名称,鼠标经过省份名字, ...
- ASP.NET MVC学习---(三)EF简单增删改查
那么现在我们已经大概从本质上了解了ef 巴拉巴拉说了一大堆之后 总算要进入ef的正题了 总在口头说也太不行了是吧~ 没错,现在要用ef进行一些实际的操作 做什么呢? 就做一个入门级的增删改查操作吧 废 ...