博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Google Code Jam 2014 Round 1 A:Problem A Charging Chaos
阅读量:6955 次
发布时间:2019-06-27

本文共 3537 字,大约阅读时间需要 11 分钟。

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: 10Outlet 1: 01Outlet 2: 11

Then flipping the second switch will reconfigure the electric flow to:

Outlet 0: 11Outlet 1: 00Outlet 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   
33 201 11 1011 00 102 3101 111010 0012 201 1010 01
Case #1: 1Case #2: NOT POSSIBLECase #3: 0

Explanation

In the first example case, Misaki can flip the second switch once. The electric flow from the outlets becomes:

Outlet 0: 00Outlet 1: 10Outlet 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.

转载于:https://www.cnblogs.com/stonehat/p/3690917.html

你可能感兴趣的文章
pyfa的汉化
查看>>
使用@Transactional(SUPPORTS)和不加@Transactional 有什么区别?
查看>>
JS判断一个页面是否已经打开
查看>>
TPS和QPS的区别
查看>>
设计模式--模板方法模式
查看>>
Removing Nesting By Returning Early
查看>>
Jfinal weixin源码分析---碎碎念(看最后,有福利)
查看>>
[Java]HashMap的两种排序方式
查看>>
C++中const与指针、引用的分析(转自china_unix GP-King)
查看>>
mysql 保存emoji 4字节宽度字符串
查看>>
diff结果分析
查看>>
php UUID &分布式生成用不重复的随机数方法
查看>>
C语言中强制转换问题
查看>>
css标签的使用
查看>>
apache+tomcat,搭建负载均衡服务器
查看>>
Andro - Multipurpose OpenCart 2.X 自适应主题模板 ABC-0651
查看>>
Linux设备模型(总线、设备、驱动程序和类)
查看>>
windows 环境下Eclipse开发MapReduce环境设置
查看>>
python--练习--for i in range(2,101)
查看>>
每天一个linux命令(25):chgrp命令
查看>>