无序数组返回两个元素和为给定值的下标。
tricks:无序、返回下标增序、返回的是原始数组的下标。
vector*pa;
bool cmp(int x,int y){
return (*pa)[x]<(*pa)[y];
}
class Solution {
public:
vector twoSum(vector &a, int t) {
int n=a...
分类:
其他好文 时间:
2014-11-04 22:53:47
阅读次数:
173
贪心对所有物品排序,然后从大头拿一个,检测如果加上此时最小的是否满足#include #include #include #define maxn 100000+10using namespace std;int a[maxn];int cmp(int a,int b){ return a>...
分类:
其他好文 时间:
2014-11-04 16:56:46
阅读次数:
138
反正每一个岛都要有雷达覆盖,放雷达的时候尽可能多覆盖岛......
#include
#include
#include
#include
#include
using namespace std;
struct node
{
double x,y;
};
bool cmp(node a,node b)
{
return a.x<b.x;
}
int main()
{
...
分类:
其他好文 时间:
2014-10-26 22:59:46
阅读次数:
308
這是vector中對string類型排序。
用寫比較函數的方法
#include
#include
#include
#include
#include
#include
using namespace std;
//比較函數,升序排序
bool cmp(const string &x,const string &y) //&符號不能少
{
return x>y...
分类:
编程语言 时间:
2014-10-26 10:25:15
阅读次数:
195
1、110201/10038 Jolly Jumpers (快乐的跳跃者)即从某个数字开始的N个连续数字#include#include#include#include#includeusing namespace std;int arr[3005];bool cmp(int a,int b){ ....
分类:
其他好文 时间:
2014-10-25 17:09:53
阅读次数:
185
题目大意:给定一张图,和每个点的油价,知道每条路的耗油量,给定一些询问,求从起点到终点用指定油箱容量的车所得到的最小耗费。
解题思路:BFS+优先队列
优先队列介绍:采用stl中的priority_queue实现。priority_queue默认的是最大优先队列,声明时只要priority_queue q就行了。如果是最小堆,麻烦一些
priority_queue,cmp> q。其中cmp函...
分类:
其他好文 时间:
2014-10-24 14:45:31
阅读次数:
205
sorted(...)
Help on built-in function sorted in module __builtin__:
sorted(...)
sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted list
sort(...)
Help on built-in function sor...
分类:
编程语言 时间:
2014-10-24 13:03:18
阅读次数:
202
题意 给你n个点 m条边 求最小生成树的权
这是最裸的最小生成树了
#include
#include
#include
using namespace std;
const int N = 55, M = 3000;
int par[N], n, m, ans;
struct edge{int u, v, w;} e[M];
bool cmp(edge a, edge b){return...
分类:
Web程序 时间:
2014-10-23 10:43:45
阅读次数:
229
题意 给你农场的邻接矩阵 求连通所有农场的最小消耗
和上一题一样裸的最小生成树
#include
#include
#include
using namespace std;
const int N = 105, M = 10050;
int par[N], ans, n, m, t;
struct edge { int u, v, w;} e[M];
bool cmp(edge a, ...
分类:
Web程序 时间:
2014-10-22 11:02:47
阅读次数:
203
IOI2009论文reference:http://www.cnblogs.com/staginner/archive/2012/02/02/2335600.html 1 int wa[maxn],wb[maxn],wv[maxn],ws[maxn]; 2 int cmp(int *r,int a,...
分类:
编程语言 时间:
2014-10-21 13:41:17
阅读次数:
241