题目

原题:http://hihocoder.com/problemset/problem/1137?sid=476594

大意是:

有N个应聘者,分别知道他们的价值V,期望薪水S,以及性别。招聘要求是:男X名,女Y名,总预算B(即期望薪水之和不能超过B),如何使总价值最大?

阅读全文 »

题目

看完了《背包九讲》,找个OJ练练手。

原题参考: http://poj.org/problem?id=1276

大意是:一个取款机有N种钞票,每种钞票有n[k]张,面额为D[k],给定一个取款金额cash,可行的、不超过该金额的吐钞方案是多少钱?

阅读全文 »

前几天Google onsite面试,已挂。今天仔细思考了面试中一道没写出来的题,发现也并不难。诶,只能怪当时脑抽了。

题目大意

给定一个巨大的无序数组,输出数组中出现次数最多的K个数。

阅读全文 »

函数说明

参数都是一样的:

make_heap(first ,last)
make_heap(first ,last, cmpObject)

[first, last)范围进行堆排序,默认使用less<int>, 即最大元素放在第一个。

pop_heap(first ,last)
pop_heap(first ,last, cmpObject)
阅读全文 »

C99 inline semantics are often misunderstood. The inline specifier serves two purposes:

First, as a compiler hint in case of static inline and extern inline declarations. Semantics remain unchanged if you remove the specifier.

Second, in case of raw inline (ie without static or extern) to provide an inline definition as an alternative to an external one, which has to be present in a different translation unit. Not providing the external one is undefined behaviour, which will normally manifest as linking failure.

阅读全文 »

写过C程序都知道,malloc了新的struct之后,经常跟着一大串的赋值。其实这些可以用一行漂亮的代码搞定。

先上代码:

1
2
3
4
#define new(type, ...) ({\
type* __t = (type*) malloc(sizeof(type));\
*__t = (type){__VA_ARGS__};\
__t; })
阅读全文 »
0%