http://blog.sina.com.cn/s/blog_6f3a860501019z1f.html #include<iostream> #include<algorithm> using namespace std; int main() { int n[]={1,4,22,3,8,5}; int len=sizeof(n)/sizeof(int); cout<<*max_element(n,n+len)<<endl; cout<<*mi…
C++中*max_element(v.begin,v.end)找最大元素*min_element(v.begin,v.end)找最小元素. 数组: #include<iostream> #include<algorithm> using namespace std; int main() { int a[]={0,1,2,3,4,5,6,7,8,9,10}; int len=sizeof(a)/sizeof(int); cout<< *max_element(a,a+l…
Given an array A of integers, return true if and only if it is a valid mountain array. Recall that A is a mountain array if and only if: A.length >= 3 There exists some i with 0 < i < A.length - 1 such that: A[0] < A[1] < ... A[i-1] < A[…
题目链接:https://code.google.com/codejam/contest/4224486/ Problem A. Mushroom Monster 这题题意就是,有N个时间点,每个时间点,Kaylin可以吃掉一定数量的mushroom,Bartholomew可以放入任意数量的mushroom. 现在给出N个时间点分别有多少mushroom. 问:若Kaylin每个时间点可以吃任意数量的mushroom,那为了配合每个时间点的mushroom,Kaylin最少要吃掉多少蘑菇. 问:…
the algorithm of three version below is essentially the same, namely, Kadane's algorithm, which is of O(n) complexity. https://en.wikipedia.org/wiki/Maximum_subarray_problem the evolution of the implementations is to remove redundancy and do what is…
区间按左端点排序,dp. #include<cstdio> #include<algorithm> using namespace std; #define N 1001 struct Point{int l,r,w;}a[N]; bool operator < (const Point &a,const Point &b){return a.l<b.l;} int n,m,K,f[N]; int main() { scanf("%d%d%d&…
http://blog.csdn.net/u011265346/article/details/44906469 #include<cstdio> #include<algorithm> using namespace std; #define N 401 struct Point{int p,v;}a[N]; bool operator < (const Point &a,const Point &b){return a.v<b.v;} int n,m…