点击打开链接

Happy Reversal

Time Limit: 1000ms
Memory Limit: 65536KB
64-bit integer IO format: %lld      Java class name: Main

pid=34987" rel="nofollow" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="text-decoration:none;font-family:'Trebuchet MS', Helvetica, Arial, sans-serif;font-size:1.1em;border:1px solid rgb(204,204,204);background-color:rgb(238,238,238);font-weight:bold;color:rgb(68,68,68);display:inline-block;overflow:visible;">Prev Submit Status 

pid=34988" rel="nofollow" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="text-decoration:none;font-family:'Trebuchet MS', Helvetica, Arial, sans-serif;font-size:1.1em;border:1px solid rgb(204,204,204);background-color:rgb(238,238,238);font-weight:bold;color:rgb(68,68,68);display:inline-block;overflow:visible;">Statistics Discuss 

pid=34989" rel="nofollow" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="text-decoration:none;font-family:'Trebuchet MS', Helvetica, Arial, sans-serif;font-size:1.1em;border:1px solid rgb(204,204,204);background-color:rgb(238,238,238);font-weight:bold;color:rgb(68,68,68);display:inline-block;overflow:visible;">Next

Font Size: 
+
 
-
Type: 
NoneGraph Theory
    2-SAT    Articulation/Bridge/Biconnected Component
    Cycles/Topological Sorting/Strongly Connected Component
    Shortest Path
        Bellman Ford        Dijkstra/Floyd Warshall
    Euler Trail/Circuit
    Heavy-Light Decomposition
    Minimum Spanning Tree
    Stable Marriage Problem
    Trees
    Directed Minimum Spanning Tree
    Flow/Matching        Graph Matching
            Bipartite Matching
            Hopcroft–Karp Bipartite Matching
            Weighted Bipartite Matching/Hungarian Algorithm
        Flow
            Max Flow/Min Cut
            Min Cost Max Flow
DFS-like    Backtracking with Pruning/Branch and Bound
    Basic Recursion
    IDA* Search    Parsing/Grammar
    Breadth First Search/Depth First Search
    Advanced Search Techniques
        Binary Search/Bisection
        Ternary Search
Geometry
    Basic Geometry    Computational Geometry
    Convex Hull
    Pick's TheoremGame Theory
    Green Hackenbush/Colon Principle/Fusion Principle
    Nim
    Sprague-Grundy Number
Matrix    Gaussian Elimination
    Matrix Exponentiation
Data Structures
    Basic Data Structures
    Binary Indexed Tree
    Binary Search Tree
    Hashing    Orthogonal Range Search
    Range Minimum Query/Lowest Common Ancestor
    Segment Tree/Interval Tree
    Trie Tree
    Sorting    Disjoint Set
String
    Aho Corasick    Knuth-Morris-Pratt
    Suffix Array/Suffix Tree
Math
    Basic Math    Big Integer Arithmetic
    Number Theory
        Chinese Remainder Theorem
        Extended Euclid
        Inclusion/Exclusion
        Modular Arithmetic
    Combinatorics        Group Theory/Burnside's lemma
        Counting
    Probability/Expected Value
Others    Tricky
    Hardest    Unusual
    Brute Force
    Implementation    Constructive Algorithms
    Two Pointer
    Bitmask    Beginner
    Discrete Logarithm/Shank's Baby-step Giant-step Algorithm
    Greedy
    Divide and Conquer
Dynamic Programming
 
 
Tag it!

Elfness is studying in an operation "NOT".
For a binary number A, if we do operation "NOT A", after that, all digits of A will be reversed. (e.g. A=1001101,
after operation "NOT A", A will be 0110010).
Now Elfness has N binary numbers of length K, now he can do operations "NOT" for some of his numbers. 
Let's assume after his operations, the maximum number is M, the minimum number is P. He wants to know what's the maximum M - P he can get. Can you help him?

 

Input

The first line of input is an integer T (T ≤ 60), indicating the number of cases.
For each case, the first line contains 2 integers N (1 ≤ N ≤ 10000) and K (1 ≤ K ≤ 60), the next N lines contains N binary numbers, one number per line, indicating the numbers that Elfness has.
The length of each binary number is K.
 

Output

For each case, first output the case number as "Case #x: ", and x is the case number. Then you should output an integer, indicating the maximum result that Elfness can get.

Sample Input

2
5 6
100100
001100
010001
010001
111111
5 7
0001101
0001011
0010011
0111000
1001011

Sample Output

Case #1: 51
Case #2: 103

Source

给你n组由k个0或者1组成的二进制数。每一个数能够翻转。求两个数的最大差值。

//152 ms 1788 KB
#include<stdio.h>
#include<algorithm>
using namespace std;
char s[107];
long long ans[20007];
int n,m;
long long getnum()
{
long long res=0,j=1;
for(int i=m-1;i>=0;i--,j*=2)
if(s[i]=='1')res+=j;
return res;
}
int main()
{
int t,cas=1;
scanf("%d",&t);
while(t--)
{
int k=0;
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
scanf("%s",s);
ans[k++]=getnum();
for(int j=0;j<m;j++)
if(s[j]=='1')s[j]='0';
else s[j]='1';
ans[k++]=getnum();
}
sort(ans,ans+k);
long long ans1=ans[k-1]-ans[1];
long long ans2=ans[k-2]-ans[0];
long long p=ans[0],q=ans[k-1];
long long e=1<<(m-1);
if((p^q)&e==e)
printf("Case #%d: %lld\n",cas++,max(ans1,ans2));
else printf("Case #%d: %lld\n",q-p);
}
return 0;
}

2014 ACM-ICPC Beijing Invitational Programming Contest的更多相关文章

  1. BNU 34990 Justice String 2014 ACM-ICPC Beijing Invitational Programming Contest

    题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34990 DEBUG了非常久,还是legal的推断函数写错了... 此题做法.枚举Stri ...

  2. ACM ICPC, JUST Collegiate Programming Contest (2018) Solution

    A:Zero Array 题意:两种操作, 1 p v  将第p个位置的值改成v  2  查询最少的操作数使得所有数都变为0  操作为可以从原序列中选一个非0的数使得所有非0的数减去它,并且所有数不能 ...

  3. ACM ICPC, Amman Collegiate Programming Contest (2018) Solution

    Solution A:Careful Thief 题意:给出n个区间,每个区间的每个位置的权值都是v,然后找长度为k的区间,使得这个区间的所有位置的权值加起来最大,输出最大权值, 所有区间不重叠 思路 ...

  4. 2014 ACM/ICPC 北京邀请赛 部分 题解

    题目链接:http://acm.bnu.edu.cn/bnuoj/problem.php?search=2014+ACM-ICPC+Beijing+Invitational+Programming+C ...

  5. hdu 5016 点分治(2014 ACM/ICPC Asia Regional Xi'an Online)

    Mart Master II Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  6. The North American Invitational Programming Contest 2017 题目

    NAIPC 2017 Yin and Yang Stones 75.39% 1000ms 262144K   A mysterious circular arrangement of black st ...

  7. ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków

    ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...

  8. The North American Invitational Programming Contest 2018 D. Missing Gnomes

    A family of nn gnomes likes to line up for a group picture. Each gnome can be uniquely identified by ...

  9. The North American Invitational Programming Contest 2018 H. Recovery

    Consider an n \times mn×m matrix of ones and zeros. For example, this 4 \times 44×4: \displaystyle \ ...

随机推荐

  1. jiffies溢出与时间先后比较-time_after,time_before

    参考地址: http://blog.csdn.net/jk110333/article/details/8177285 http://blog.chinaunix.net/uid-23629988-i ...

  2. 备份MySQL数据库的方法

    前言 我们试着想一想, 在生产环境中什么最重要?如果我们服务器的硬件坏了可以维修或者换新, 软件问题可以修复或重新安装, 但是如果数据没了呢?这可能是最恐怖的事情了吧, 我感觉在生产环境中应该没有什么 ...

  3. Intellij从无到有创建项目

    Intellij虽然提供了很多模板可以创建maven web javaee等等各种项目,但是你知道项目从无到有到底怎么来的,各个配置分别是做什么的?现在就来一步步说明. 1.idea打开一个空文件夹: ...

  4. OceanBase分区表有什么不同?

    概述 分区表是ORACLE从8.0开始引入的功能,也是第一个支持物理分区的数据库,随后其他数据库纷纷跟进.分区表是一种“分而治之”的思想,通过将大表.索引分成可以独立管理的.小的片段(Segment) ...

  5. 在路上:安全公司“跨界”SD-WAN

    编者按:本文是SDNLAB“企业+”特别报道之一.“企业+”是SDNLAB重点打造的栏目,汇聚信息行业运营商.设备商.互联网公司.软件公司.集成公司.融创投资公司.科研院所等企业,重新定义IT行业撮合 ...

  6. 洛谷——P1767 家族_NOI导刊2010普及(10)

    P1767 家族_NOI导刊2010普及(10) 题目描述 在一个与世隔绝的岛屿上,有一个有趣的现象:同一个家族的人家总是相邻的(这里的相邻是指东南西北四个方向),不同的家族之间总会有河流或是山丘隔绝 ...

  7. iOS应用崩溃日志揭秘

    这篇文章还可以在这里找到 英语 Learn how to make sense of crash logs! 本文作者是 Soheil Moayedi Azarpour, 他是一名独立iOS开发者. ...

  8. Linux中的热键[Tab] [Ctrl]-c [Ctrl]-d

    Tab键:命令或者文件补全.可以避免很多的输入错误 1. 按一次,文件或命令补全 2. 按两次,会列举出以按键前的字母为首的所有命令或者文件 Ctrl+C:中断目前程序 Ctrl+D:键盘输入结束.可 ...

  9. GDB调试多线程程序

    gdb有thread相关命令,如info thread(简写成info th)显示线程消息,b xx thread yy可以针对某个thread设置断点,thread xx(简写成thr xx)切换到 ...

  10. UNIX&Linux发展图谱

    来自为知笔记(Wiz)