A . 250

Problem Statement
    
Some people are sitting in a row. Each person came here from some country. You have a theory that people from the same country are all sitting together. You decided to test this theory. You asked each person the same question: "How many people from your country (including you) are here?"
You are given a vector <int> a containing their answers. The answers are given in the order in which the people sit in the row. (Note that some of the answers may be incorrect. See the examples for clarification.)
If all the answers are consistent with your theory, return the number of different countries that are present. (Given that all answers are consistent with the theory, the number of countries can always be uniquely determined.) Otherwise, return -.
Definition
    
Class:
CountryGroup
Method:
solve
Parameters:
vector <int>
Returns:
int
Method signature:
int solve(vector <int> a)
(be sure your method is public)
Limits
    
Time limit (s):
2.000
Memory limit (MB): Stack limit (MB): Constraints
-
The number of elements in a will be between and , inclusive.
-
All elements of a will be between and , inclusive.
Examples
)     
{,,,,}
Returns:
These answers are consistent with your theory. The first two people are from one country, the other three are from a different country. Thus, there are two countries and the correct return value is .
)     
{,,,,}
Returns:
Here, each person comes from a different country.
)     
{,}
Returns: -
These answers do not correspond to your theory. In particular, they are not even correct: there are only two people but each of them claims that there are three people from their country.
)     
{,,,,,,,,,,}
Returns: )     
{,,,,,}
Returns: -
These answers do not correspond to your theory. It is possible that these are people from four different countries, but even if that were the case, we can tell that people from some countries are not sitting together. For example, consider the leftmost person. According to her answer, there are two people from her country. However, the person sitting next to her cannot be from the same country.
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c), TopCoder, Inc. All rights reserved.

题目

模拟 , 看看给出的串是否合法 。

#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = ; class CountryGroup
{
bool vis[N];
public: int solve( vector<int> x )
{
memset( vis , , sizeof vis );
int ans = , n = (int) x.size() ; bool tag = true ;
for( int i = ; i < n ; ++i ) if( !vis[i] ) {
if( i + x[i] > n ) { tag = false ; break ; }
for( int j = i ; j < i + x[i] ; ++j ) {
if( x[j] != x[i] ) { tag = false ; break ; }
vis[j] = true ;
}
ans++ ;
}
if( !tag ) return - ;
else return ans ;
}
};

B. 500

Problem Statement
    
Alice and Bob are going to play a variant of the traditional rock-paper-scissors game. Their game is played using cards. Each card shows one of the three pictures: a rock, a paper, or scissors. There is a sufficient supply of cards of each type. Bob has already chosen a sequence of cards and he has arranged them into a row, face down. It is now Alice's turn to do the same. Once she does that, they will use the two sequences of cards to play the game: For each i, Alice's i-th card and Bob's i-th card will be revealed and compared using the standard rules of rock-paper-scissors. Whenever Alice's card wins, Alice gets a point. Alice gets no points for a loss or a tie.
Alice has marked Bob's cards, so now she can tell which card has which symbol on it. You are given this information as a vector <int> card. Each element of card is between 0 and 2, inclusive: 0 is a rock, 1 is a paper, and 2 are scissors.
You are also given an int score. Alice has just announced that she will get a total of score points.
Let X be the number of sequences in which Alice can play her cards if she wants to achieve exactly score points. Return the value (X modulo ,,,).
Definition
    
Class:
RockPaperScissorsMagicEasy
Method:
count
Parameters:
vector <int>, int
Returns:
int
Method signature:
int count(vector <int> card, int score)
(be sure your method is public)
Limits
    
Time limit (s):
2.000
Memory limit (MB): Stack limit (MB): Constraints
-
The number of elements in card will be between and ,, inclusive.
-
All elements of card will be between and , inclusive.
-
score will be between and ,, inclusive.
Examples
)     
{,,} Returns:
Bob has played his cards in the order rock-paper-scissors. Alice wants to score points. Hence, she must win twice, and lose to Bob or tie him once.
One possible way in which she can play her cards is paper-scissors-scissors: her paper beats Bob's rock (1 point), scissors beat paper (1 point), and scissors tie with scissors (0 points).
There are five other ways how Alice can score points: paper-scissors-paper, paper-paper-rock, paper-rock-rock, rock-scissors-rock, and scissors-scissors-rock.
)     
{,} Returns: )     
{,,,,} Returns: )     
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,} Returns: )     
{,,,,,,,,} Returns: This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c), TopCoder, Inc. All rights reserved.

题目

玩剪刀石头布, 每局赢了拿1分, 输了或者打平没分, 问能达到k 分的出拳发案数 。

设 dp[i][j] ...表示前i盘拿到 j 分的方案数

#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
const int mod = 1e9+;
const int N = ; class RockPaperScissorsMagicEasy
{
long long dp[N][N];
public: int count( vector <int> card, int score)
{
int n = card.size();
memset( dp , , sizeof dp );
dp[][] = ;
for( int i = ; i <= n ; ++i ) {
for( int j = ; j <= i ; ++j ) {
if( j > ) dp[i][j] = ( dp[i][j] + dp[i-][j-] ) % mod ;
dp[i][j] = ( dp[i][j] + * dp[i-][j] ) % mod ;
}
}
int ans = (int) dp[n][score] ;
return ans ;
}
};

C.1000

Problem Statement
    
Alice and Bob are going to sing a song together. For simplicity, we will assign the numbers through ,, to the pitches that occur in the song (from the lowest to the highest). Both Alice and Bob are able to sing all of these pitches. You are given a vector <int> pitch containing the pitches of all notes in the song, in order. Each note of the song will be sung by exactly one of our singers.
Changing the pitch of one's voice is exhausting. Given a sequence of pitches to sing, the difficulty for the singer can be computed by summing up the differences between consecutive pitches. For example, the difficulty of the sequence 8, 8, 13, 12 is abs(8-8) + abs(13-8) + abs(12-13) = 0+5+1 = 6.
The total difficulty of singing the song can be computed as the difficulty for Alice plus the difficulty for Bob. Return the smallest possible total difficulty of singing the given song.
Definition
    
Class:
SingingEasy
Method:
solve
Parameters:
vector <int>
Returns:
int
Method signature:
int solve(vector <int> pitch)
(be sure your method is public)
Limits
    
Time limit (s):
2.000
Memory limit (MB): Stack limit (MB): Constraints
-
The number of elements in pitches will be between and ,, inclusive.
-
all elements in pitch will be between and ,,, inclusive.
Examples
)     
{,,,,}
Returns:
One optimal solution is to let Alice sing the first two notes and Bob the remaining three. Then, Alice will sing the sequence of pitches {,} and Bob will sing {,,}. The difficulty for Alice is abs(-) = . The difficulty for Bob is abs(-) + abs(-) = . Thus, the total difficulty is + = .
)     
{,,,,}
Returns:
One optimal solution is to let our singers sing in the order Alice-Bob-Bob-Alice-Alice. In this case Alice sings the sequence of pitches {,,} and Bob sings {,}. Hence the difficulty for Alice is and the difficulty for Bob is .
)     
{,,,,,,,}
Returns: )     
{}
Returns: )     
{,,,,,,,,,,,,,,,,,,,,,,}
Returns: This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c), TopCoder, Inc. All rights reserved.

题目

两个人唱歌,换音要费用为音调差。

设dp[i][j] .. 表示唱到1个人第i个音, 另一个人唱到第j个音的最小费用。

转移的时候要注意某个人还未唱的情况。 用状态[0]表示

#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
const int mod = 1e9+;
const LL inf = 1e17;
const int N = ; class SingingEasy
{
long long dp[N][N] , x[N] ;
public: int solve(vector <int> pitch)
{
int n = pitch.size();
for( int i = ; i < n ; ++i ) x[i+] = pitch[i] ;
for( int i = ; i <= n ; ++i ) {
for( int j = ; j <= n ; ++j ) {
dp[i][j] = inf ;
}
}
dp[][] = ;
for( int i = ; i < n ; ++i ) {
for( int j = ; j < i ; ++j ) {
if( !j ) {
dp[i+][] = min( dp[i+][] , dp[i][] + abs( x[i+] -x[i] ) );
dp[i+][i] = min( dp[i+][i] , dp[i][] );
} else {
dp[i+][i] = min( dp[i+][i] , dp[i][j] + abs( x[i+] - x[j] ) );
dp[i+][j] = min( dp[i+][j] , dp[i][j] + abs( x[i+] - x[i] ) );
}
}
}
LL ans = inf ;
for( int i = ; i < n ; ++i ) ans = min( ans , dp[n][i] );
return (int)ans;
}
};

BC 拿ROOM rank1 之后 , 刚刚接触TC , 第一场DIV2 ROOM rank1 。

纪念一下。

Topcoder SRM653div2的更多相关文章

  1. TopCoder kawigiEdit插件配置

    kawigiEdit插件可以提高 TopCoder编译,提交效率,可以管理保存每次SRM的代码. kawigiEdit下载地址:http://code.google.com/p/kawigiedit/ ...

  2. 记第一次TopCoder, 练习SRM 583 div2 250

    今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...

  3. TopCoder比赛总结表

    TopCoder                        250                              500                                 ...

  4. Topcoder几例C++字符串应用

    本文写于9月初,是利用Topcoder准备应聘时的机试环节临时补习的C++的一部分内容.签约之后,没有再进行练习,此文暂告一段落. 换句话说,就是本文太监了,一直做草稿看着别扭,删掉又觉得可惜,索性发 ...

  5. TopCoder

    在TopCoder下载好luncher,网址:https://www.topcoder.com/community/competitive%20programming/ 选择launch web ar ...

  6. TopCoder SRM 596 DIV 1 250

    body { font-family: Monospaced; font-size: 12pt } pre { font-family: Monospaced; font-size: 12pt } P ...

  7. 求拓扑排序的数量,例题 topcoder srm 654 div2 500

    周赛时遇到的一道比较有意思的题目: Problem Statement      There are N rooms in Maki's new house. The rooms are number ...

  8. TopCoder SRM 590

     第一次做TC,不太习惯,各种调试,只做了一题...... Problem Statement     Fox Ciel is going to play Gomoku with her friend ...

  9. Topcoder Arena插件配置和训练指南

    一. Arena插件配置 1. 下载Arena 指针:http://community.topcoder.com/tc?module=MyHome 左边Competitions->Algorit ...

随机推荐

  1. 苹果账号需要的邓白氏D-U-N-S编码更新信息最新方法,官方已不受理邮件

    公司从上海搬迁到深圳,公司名称相应变更,但之前注册的苹果开发者账号上的名字还是就的,尝试在后台提交更新申请,官方给了邮件,要求邮件提交证明材料,证明材料提交后,苹果又反馈和邓白氏的资料不匹配,要求先修 ...

  2. xftp xshell 个人下载官网

    https://www.netsarang.com/zh/xftp-download/

  3. RocketMQ集群部署安装

    RcoketMQ:[ 1.低延时:在高压下,1毫秒内超过99.6%的反应延迟. 2.面向金融:具有跟踪和审计功能的高可用性. 3.行业可持续发展:保证了万亿级的消息容量. 4.厂商中立:一个新的开放的 ...

  4. Mongodb副本集实现及读写分离

    前言 地址:https://blog.csdn.net/majinggogogo/article/details/51586409 作者介绍了,mongodb副本集的读写原理,原理是通过代码层来实现. ...

  5. PCB项目 X1 STC12C5A60S2-LQPF48

    单片机控制系统双层板STC51 简介: STC12C5A60S2主芯片,12MHz主频 12V电源输入,12/5/3V电源输出 4路0~12V可调10位ADC输入 4路1A大电流达林顿输出 4路INT ...

  6. word从任意页设置页码

    把所有页都设置页码 首先设置分隔符,下一页 在第二节中,找到插入页码,设置起始页码为1即可

  7. php7 mysqli_query返回1 , 但是更新失败

    HTML中忘了传id 

  8. 2019最新create-react-app创建的react中使用sass/scss,以及在react中使用sass/scss公共变量的方法

    Sass(英文全称:Syntactically Awesome Stylesheets)是一个最初由Hampton Catlin设计并由Natalie Weizenbaum开发的层叠样式表语言.Sas ...

  9. UITextField 长按文本框指定删除某个位置内容

    普通的光标移动,点键盘的删除键,会从最后一位删除,加一UITextField的分类即可 #import <UIKit/UIKit.h> @interface UITextField (Ex ...

  10. VMware Workstation 官方正式版及激活密钥

    热门虚拟机软件VMware Workstation Pro现已更新至14.1.2,14.0主要更新了诸多客户机操作系统版本,此外全面兼容Wind10创建者更新.12.0之后属于大型更新,专门为Win1 ...