2014 ACM-ICPC Beijing Invitational Programming Contest
点击打开链接
Happy Reversal
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 Statuspid=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
Discusspid=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
+
-
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!
after operation "NOT A", A will be 0110010).
Input
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;
}
最新文章
- 微信小程序的机会在于重新理解群组与二维码
- 如何在tomcat中如何部署java EE项目
- java中IO流相关知识点
- HDU 5071 Chat(2014鞍山赛区现场赛B题)
- Visual Studio提示Bonjour backend初始化失败
- POJ 1743 Musical Theme (后缀数组,求最长不重叠重复子串)(转)
- scan的filter使用
- devi into python 笔记(六)正则表达式 原始字符串
- C#:占位符的例子
- thinkphp 删除该表的最后一行
- Intent的概念及应用(一)
- CSS-蜂窝状展示区域(多个六边形)的一种实现方式
- LeetCode题解 | 215. 数组中的第K个最大元素
- 虚拟机配置nginx无法访问80端口
- 《深入理解Oracle 12c数据库管理(第二版)》PDF
- Python3使用AES加密的库函数PyCrypto、PyCryptodome
- sh脚本学习之:变量
- 泊松分布E(X^2)
- metaq架构原理
- C# 小球100米自由落下