No pain No gain

# SRM 634 #DIV2

#### 250题目：

Tom is in charge of a tourist agency. He has a lovely picture of the local mountain range. He would like to sell it to the tourists but first he needs to know how many peaks are visible in the picture.
The mountain range in the picture can be seen as a sequence of heights. You are given these heights as a vector height. An element of height is called a peak if its value is strictly greater than each of the values of adjacent elements. Compute and return the number of peaks in the given mountain range.

#### 分析：

#include <iostream>
#include <cstring>
#include <deque>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <cstdio>
#include <functional>
#include <algorithm>
typedef long long LL;
#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )
#define CLEAR( a , x ) memset ( a , x , sizeof a )
using namespace std;
const int INF = 0x3f3f3f3f;
typedef pair<int,int>pil;
class MountainRanges {
public:
int countPeaks( vector <int> heights ) {
int sz=heights.size();
if(sz==1)
return 1;
int ans=0;
for(int i=0;i<sz;i++)
{
if(i==0&&heights[i]>heights[i+1])
ans++;
else if(i==sz-1&&heights[i]>heights[i-1])
ans++;
else if(heights[i]>heights[i-1]&&heights[i]>heights[i+1])
ans++;
}
return ans;
}
};

#### 500题目：

A store sells M different items, conveniently numbered 0 through M-1. For a shopping survey you interviewed N customers. Each customer responded to the survey with a list of items they’ve bought. Each customer bought at most one of each item. It is possible that some customers did not buy anything at all.
After collecting the responses, you’ve summed up the results and found that s[i] people have bought item i. Due to an unfortunate accident, you’ve then lost the actual survey responses. All you have left are the values s[i] you computed.
You are now supposed to report the number of big shoppers among the survey respondents. A big shopper is defined as a customer who has bought all M items. Of course, having lost the detailed responses, you might be unable to determine the actual number of big shoppers.
You are given the int N and the vector s with M elements. Compute and return the smallest possible number of big shoppers.

#### 分析：

#include <iostream>
#include <cstring>
#include <deque>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <cstdio>
#include <functional>
#include <algorithm>
typedef long long LL;
#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )
#define CLEAR( a , x ) memset ( a , x , sizeof a )
using namespace std;
const int INF = 0x3f3f3f3f;
typedef pair<int,int>pil;
class ShoppingSurveyDiv2 {
public:
int minValue( int N, vector <int> s ) {
int sum=0;
int n=s.size();
for(int i=0;i<n;i++)
sum+=s[i];
for(int i=0;i<=N;i++)
{
int res=sum-i*n;
if(res<=(N-i)*(n-1))
return i;
}
}
};

#### 1000题目：

A string S is called special if it satisfies the following two properties:
Each character in S is either ‘0’ or ‘1’.
Whenever S = UV where both U and V are nonempty strings, U is strictly smaller than V in lexicographic order.
For example, the string S = “00101” is special because we have “0” < “0101”, “00” < “101”, “001” < “01”, and “0010” < “1”.
You are given a string current that is guaranteed to be special. Let N be the length of current. Consider the lexicographically sorted list of all special strings of length N. Compute and return the string that comes immediatelly after current in this list. If current happens to be the last string in the list, return an empty string instead.

#### 分析：

#include <iostream>
#include <cstring>
#include <deque>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <cstdio>
#include <functional>
#include <algorithm>
typedef long long LL;
#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )
#define CLEAR( a , x ) memset ( a , x , sizeof a )
using namespace std;
const int INF = 0x3f3f3f3f;
typedef pair<int,int>pil;
bool ok(string s,int len)
{
string s1,s2;
for(int i=0;i<len-1;i++)
{
s1="";s2="";
for(int j=0;j<=i;j++)
s1+=s[j];
for(int j=i+1;j<len;j++)
s2+=s[j];
if(s1>s2||s1==s2)
return false;
}
return true;
}
class SpecialStrings {
public:
string findNext( string current ) {
int len=current.length();
for(int i=len-1;i>=0;i--)
{
if(current[i]=='0')
{
string s=current;
for(int j=i;j<len;j++)
s[j]='1';
if(ok(s,len))
{
for(int j=i+1;j<len;j++)
{
s[j]='0';
if(!ok(s,len))
s[j]='1';
}
return s;
}
}
}
return "";
}
};

#### SRM602 (div2)

2013-12-29 15:13:48

#### 记第一次SRM （SRM489 div2）

2010-12-01 09:41:00

#### SRM145_DIV2

2016-10-24 09:08:27

#### SRM 145 DIV 2 250

2016-10-19 00:35:25

#### topcoder-srm610-div2-1000(dp)

2015-05-07 16:19:26

#### SRM 387 DIV2 [600]

2008-04-27 19:32:00

#### TopCoder SRM 634 Div2 Problem 500 - ShoppingSurvey

2014-09-27 16:27:03

#### TopCoder SRM 634 Div2 Problem 1000 - SpecialStrings

2014-09-27 16:18:59

#### TopCoder SRM 634 Div.2[ABC]

2014-09-27 21:02:06

#### SRM 611 div2

2014-03-05 12:02:00