Given an array of integers, find two numbers such that they add up to a specific target number.
The function twoSum should return indices of the two numbers such that they add up to the target, whe...
分类:
其他好文 时间:
2014-06-09 23:14:45
阅读次数:
264
【题目】
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.
For example, given the following triangle
[
[2],
[3,4],
[6,5,7],
[4,1,8,3]
]
The minimum path sum from top to...
分类:
其他好文 时间:
2014-06-08 17:52:45
阅读次数:
235
Find the contiguous subarray within an array (containing at least one number) which has the largest sum....
分类:
其他好文 时间:
2014-06-08 15:54:08
阅读次数:
258
本题有两个考点:
1 求逆序数的性质
计算逆序数的公式, 一个数arr[i]从前面放到后面,必然会有n-arr[i]-1个数比这个大,那么就有n-arr[i]-1个逆序数增加,同时因为前面少了个arr[i]数,那么就必然有arr[i]个(加上零)数比起小的数失去一个逆序数,总共失去arr[i]个逆序数,所以新的逆序数为增加了n-arr[i]-1-arr[i]个逆序数(当然有可能是减小了,视ar...
分类:
其他好文 时间:
2014-06-08 15:52:20
阅读次数:
275
题目来源:Light OJ 1278 Sum of Consecutive Integers
题意:N拆分成连续整数和的方案数
思路:奇因数的个数
#include
#include
#include
#include
using namespace std;
//筛素数
const int maxn = 10000010;
bool vis[maxn];
int prime[10...
分类:
其他好文 时间:
2014-06-08 15:34:09
阅读次数:
295
const int maxn = 100010;
int n, m;
vector G[maxn*2];
bool mark[maxn*2];
int S[maxn*2], c;
int a[maxn], b[maxn], sum;
bool dfs(int x)
{
if(mark[x^1])
return false;
if(mark[x])
return true;
mark...
分类:
其他好文 时间:
2014-06-08 10:31:01
阅读次数:
198
点击打开链接
题意:给定牛的关系图,求其中一头牛与其他牛关系路程之和sum最小,然后输出 sum*100/(n-1)
floyd求任意两点间的最短路程
注意: inf不能太大,因为 f[i][k] + f[k][j] 做加法时可能会溢出!
#include
#include
const int maxn = 300 + 5;
const int inf = 1<<29;
int...
分类:
其他好文 时间:
2014-06-08 05:07:03
阅读次数:
181
HDU1002--A + B Problem II...
分类:
其他好文 时间:
2014-06-08 04:56:06
阅读次数:
242
题目 :Input: numbers={2, 7, 11, 15}, target=9
Output: index1=1, index2=2
解题思路:
给出一个数组合一个数,如果两个数的和等于所给的数,求出该两个数所在数组中的位置。
这个题也挺常见的,就是两个指针,从前后两个方向扫描。但是本题有以下几个需要的点:
1. 所给数组不是有序的;
2. 返回的下标是从1开始的,并且是原来无序数组中的下标;
3. 输入数组中可能含有重复的元素。
好了,把以上三点想到的话,做这个题应该不会有啥问题。
具体方法:把原...
分类:
其他好文 时间:
2014-06-08 02:14:06
阅读次数:
250
a题,就不说了吧b题,直接从大到小排序1-limit的所有数的lowbit,再从大到小贪心组成sum就行了 1 #include 2 #include 3
#include 4 #include 5 #define N 200000 6 using namespace std; ...
分类:
其他好文 时间:
2014-06-07 21:49:57
阅读次数:
272