题目链接:http://codeforces.com/contest/469/problem/D 题目的意思就是把n个不同的数分成2个集合。。 If number x belongs to set A, then number a - x must also belong to setA. If number x belongs to set B, then number b -
题目: This is a follow up of Shortest Word Distance. The only difference is now you are given the list of words and your method will be calledrepeatedly many times with different parameters. How wou
Given an array containing n distinct numbers taken from >0, 1, 2, …, n, find the one that is missing from the array. For example, Given nums = [0, 1, 3] return 2. 思路:这道题和求数组中唯一的一个数类似,遍历对数组下标和值异或,
A. 24 Game 题意:n个数(1~n),每次取两个数,进行+,-,*运算中的一个,然后放回数列中,问是否能最后剩下一个24,输出每一步运算。 思路:稍微分析一下就知道,n>3时才有可能。其实所有n>3的情况都可以,只需要先乘出一个24,然后不断造1乘上去就可以了。分奇偶两种情况,具体见代码。 #include <iostream>
B. Two Sets 题意:n个不相同的数p1~pn,把它们划分为两个集合。必须满足如果pi在集合0中,a-pi也在集合0中;如果pi在集合1中,b-pi也在集合1中。 思路:先排序,然后贪心从两边开始构造。两个指针l和r,指向未构造区间的左边和右边。如果pl和pr能放在一个集合中,就把它们放到一个集合。如果不行,就为pl找一个合适的(用二分查找),必
###Date : 2017/11/3 问题: error: #268: declaration may not appear after executable statement in block 分析: 在编译多线程部分代码过程中,提示这个是因为把变量的声明放在了可执行语句的后面 如下面这几行代码: if(index>
LeetCode 268.Missing Number Description: Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array. Example 1: Input: [3,0,1] Output: