您的位置:首页 > 其它

SRM 595 1A 2013.12.9

2016-02-13 20:08 218 查看
SRM 595 1A 2013.12.9

DIV 1

250

Problem Statement

Little Elephant from the Zoo of Lviv hassome balls arranged in a row. Each ball can be painted in one of two possiblecolors: black or white. Initially all the balls are painted white.

You are given an int M, which representsthe number of balls in the row. The balls are numbered from left to right,starting from 1. You are also given two vector <int>s L and R. To repaintballs, Little Elephant wants to use a robot. The robot will paint the
balls inseveral consecutive stages. For each i, the i-th stage (1-based index) willlook as follows: First, the robot will choose one of the two colors: white orblack. Then, the robot will paint the balls with indices from L[i-1] to R[i-1],inclusive, using
the chosen color. (Painting a ball covers all previous layersof paint.)

Return the number of different coloringsLittle Elephant can get after the last stage. (Two colorings are considereddifferent if there exists some ball that is white in one coloring and black inthe other one).

Definition

Class:

LittleElephantAndIntervalsDiv1

Method:

getNumber

Parameters:

int, vector <int>, vector <int>

Returns:

long long

Method signature:

long long getNumber(int M, vector<int> L, vector <int> R)

(be sure your method is public)

Constraints

-

M will be between 1 and 1,000, inclusive.

-

L will contain between 1 and 50 elements,inclusive.

-

R will contain the same number of elementsas L.

-

Each element of R will be between 1 and M,inclusive.

-

i-th element of L will be between 1 andR[i], inclusive.

Examples

0)

4

{1, 2, 3}

{1, 2, 3}

Returns: 8

In the three stages the robot will choosethe color for balls number 1, 2, and 3. The choices are independent of eachother. The last, fourth ball will always remain white. Thus there are 2*2*2 = 8different colorings.

1)

3

{1, 1, 2}

{3, 1, 3}

Returns: 4

2)

1000

{47}

{747}

Returns: 2

3)

42

{5, 23, 4, 1, 15, 2, 22, 26, 13, 16, 28,13, 27, 9, 18, 4, 10, 3, 4, 4, 3, 4, 1, 18, 18, 2, 38, 4, 10, 12, 3, 30, 11,38, 2, 13, 1, 13, 18, 16, 13, 2, 14, 27, 13, 3, 26, 19, 5, 10}

{30, 41, 17, 1, 21, 6, 28, 30, 15, 19, 31,28, 35, 27, 30, 13, 31, 5, 8, 25, 40, 10, 3, 26, 23, 9, 40, 8, 40, 23, 12, 37,35, 39, 11, 34, 10, 21, 22, 21, 24, 5, 39, 27, 17, 16, 26, 35, 25, 36}

Returns: 256

This problem statement is the exclusive andproprietary property of TopCoder, Inc. Any unauthorized use or reproduction ofthis information without the prior written consent of TopCoder, Inc. isstrictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

179.86

#include<iostream>

#include<string>

#include<vector>

using namespace std;

class LittleElephantAndIntervalsDiv1

{

public: long long getNumber(int M, vector<int> L, vector <int> R)

{

longlong ans=1;

intexp=0;

intline[1010]={0};

for(inti=0;i<L.size();i++)

{

for(intj=L[i];j<=R[i];j++)

line[j]=i+1;

}

for(intk=1;k<=M;k++)

{

if((line[k]!=0)&&(line[k]!=line[k-1]))

exp++;

}

ans=ans<<exp;

returnans;

}

};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: