天天看点

2014北京邀请赛(部分题解) H. Happy Reversal B. Beautiful Garden

马上要去比赛了。

今天做了一下2014北京邀请赛,出了两道题目,感觉很水啊、、、

首先H题:

Time Limit: 1000ms

Case Time Limit: 1000ms

Memory Limit: 65536KB

64-bit integer IO format: %lld      Java class name: Main

Font Size: 

+

-

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?

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.

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.

题意:给出n个二进制串,可以把其中的一些0和1反转(即0变1,1变0),找出转化后n个串中的最大值和最小值的差值。

分析:思路就是把所有的串和反转的存在一个数组中,然后排序,找最大值和最小值的差,(如果是同一个串反转的就找第二大的和最小的或第二小和最大的中的最大值)。注意假如只有一个串的话结果为0

代码:

B题:

Time Limit: 15000ms

Case Time Limit: 8000ms

There are n trees planted in lxhgww‘s garden. You can assume that these trees are planted along the X-axis, and the coordinate

of ith tree is xi.

But in recent days, lxhgww wants to move some of the trees to make them look more beautiful. lxhgww will

recognize the trees as beautiful if and only if the distance between any adjacent trees is the same.

Now, lxhgww wants to know what is the minimum number of trees he need to move.

Just to be clear, after moving, there should still be n trees in the X-axis.

The first line of the input contains a single integer T, which is the number of test cases.

For each case,

The first line contains an integers number n (1 ≤ n ≤ 40), representing the number of trees lxhgww planted;

The second line contains n integers numbers, the ith number represents xi. (-1000000000 ≤ xi ≤

1000000000)

For each case, first output the case number as "Case #x: ", and x is the case number. Then output a single number, representing the minimum number of trees lxhgww needs

to move.

题意:给出一些数,表示数轴上的位置,让你移动最少的点让所有相邻点的差值均相等!求移动次数

分析:思路就是暴力,因为点只有40个,所以我们可以枚举相邻点的差值,因为我最少也能够保证两个点是不动的,那么我枚举这两个点作为所有的差值,然后找一个落在枚举的方案的最大点的方案。

此题目坑点很多!首先有可能两个点落在同一位置,其次枚举的话数据范围会超int。算是一个坑题。