SRM 634 #DIV2

原创 2015年07月09日 00:09:01

SRM#634

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.

题意:

求谷峰(即满足条件(h[i]>h[i-1]&&h[i]>h[i+1])

分析:

直接搞了,水题,注意边界

#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.

题意:

这道题比较有意思,就是说有N个人,M种物品,每个人可以选任意件,但每种商品每个人最多选一个,给你每种商品有多少人选,问你最少有多少人选了全部商品

分析:

注意到N<=100,那么可以直接枚举有多少人选了全部物品,然后看剩余的选择(N-i)个人能不能完成,即res<=(N-i)(n-1)

#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.

题意:

告诉你一种特殊的串,给定一个这样的串,问你下一个这样的串

分析:

这道题开始虽然注意到要从前到后找0,但是最后没想好,我们知道给定长度的串,全是1肯定不符合,那么从前到后找0的过程中,发现0后,将这个位置以后的都置为1,然后逐位变成0,看是否符合,不符合再变成1

#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 "";
   }
};
版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

TopCoder SRM 634 Div.2[ABC]

TopCoder SRM 634 Div.2[ABC] ACM 题目地址: TopCoder SRM 634 赛后做的,感觉现场肯定做不出来Orz,简直不能多说。 Level One-M...
  • hcbbt
  • hcbbt
  • 2014-09-27 21:02
  • 1855

topcoder SRM495 div1 level2

Problem Statement   There are N boxes numbered 0 through N-1. Every box except for one conta...

我是如何成为一名python大咖的?

人生苦短,都说必须python,那么我分享下我是如何从小白成为Python资深开发者的吧。2014年我大学刚毕业..

TOPCODER SRM 613 DIV2

250: 确保字符串

Topcoder srm 653 div.2 1000 - SingingEasy(区间DP)

题意: 给出一个序列,请你找出两个没有交且并为全集的子序列,使得每个子序列相邻两位之间的数字差的绝对值之和最小。 思路: DP....(dp弱渣, 折腾了好久请教了人才会>, dp[i][j] 表示A...

SRM537-div1-2-KingXMagicSpells

zz: http://www.strongczq.com/2012/03/srm537-div1-2-kingxmagicspells.html 题目原文:http://community.t...

TopCoder 250 points 28-SRM 157 DIV 2 185.60/250 74.24%

普通的二分查找。 Problem Statement   A popular guessing game is "Guess the number", where one pe...

SRM 556 DIV2 解题报告

250:简单的字符串处理题目,因为最多只有50个字符,所以可以用O(n^2)的算法,对从每个位置开始的字符进行扫描,每次扫到了重复的字符即退出此次扫描,并比较长度是否最大即可。 500:看起...

TopCoder SRM558 backup 1 DIV 2

Problem Statement   Surrounding Game is a single-player game played on a rectangular grid o...

SRM 464 DIV1 500 2-sat 思路和hdu3622基本差不多

SRM 464 DIV1 500 #include #include #include #include #include #include #include #include #include...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)