SRM 670 div2 A BearSong

原创 2015年11月19日 23:14:01
  Problem Statement  

 Problem Statement for BearSong

Problem Statement

 

Bear Limak has recently learned about musical notes. He then listened to a song and noticed that some notes appeared less often than others. In fact, some notes were so rare that they appeared in the song only once!



Limak now wants to look for such notes in other songs. Write a program that will look for the rare notes.



You are given a int[] notes that describes a song. Each number in notes represents one note of the song. Different numbers represent different notes, equal numbers represent equal notes.



Compute and return the number of notes that occur exactly once in the given song.

 

Definition

 
Class: BearSong
Method: countRareNotes
Parameters: int[]
Returns: int
Method signature: int countRareNotes(int[] notes)
(be sure your method is public)
 
 
 

Constraints

- notes will contain between 1 and 50 elements, inclusive.
- Each element in notes will be between 1 and 1000, inclusive.
 

Examples

0)  
 
{9,10,7,8,9}
Returns: 3
The rare notes are the notes 7, 8, and 10. Each of these notes occurs exactly once in the whole song. The note 9 occurs twice, so it is not a rare note
1)  
 
{8,8,7,6,7,3,5,10,9,3}
Returns: 4
Each of the notes 5, 6, 9, and 10 occurs exactly once in this song.
2)  
 
{234,462,715,596,906}
Returns: 5
3)  
 
{17}
Returns: 1

4)  
 
{1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,
1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,
1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000}
Returns: 0


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)2010, TopCoder, Inc. All rights reserved.

This problem was used for: 
       Single Round Match 673 Round 1 - Division II, Level One

题意:给你一个序列,求只出现一次的数的种数

很久没打TC了,忘记要加头文件,一直编译错误...............

#include
#include
#include
#include
using namespace std;

class BearSong
{
    public:
        int countRareNotes(vector  notes)
        {
            int ans = 0;
            int i;
            int flag[2001];
            for(i = 0; i < notes.size(); i++)
            {
                int val = notes[i];
                if(!flag[ val ])
                {
                    flag[ val ] = 1;
                    ans++;
                }
                else if(flag[ val ] == 1)
                {
                    flag[ val ] = 2;
                    ans--;
                }
            }
            return ans;
        }
};

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

SRM 670 DIV 2 Cdgame 250-point

Problem StatementTwo players are playing a cooperative game. At the beginning of the game each play...

SRM 670 div2 A

Problem Statement   Two players are playing a cooperative game. At the beginning of the...
  • ZZ_AC
  • ZZ_AC
  • 2015年10月11日 19:38
  • 203

TC SRM 388 div 2 problem 3

  • 2012年04月16日 22:16
  • 2KB
  • 下载

【jzoj3918】【TC Srm 636 Div2 1000pt】【蛋糕】【二分答案】

题目大意今天是Bessie的生日,他买了一个蛋糕和朋友们一起分享,蛋糕可以看成是一个R行C列的表格,共有R*C个格子,每个格子都有一个0至9的数字,表示该格子蛋糕拥有的巧克力。现在Bessie要把蛋糕...

topcoder-srm-595-div2

250分: 暴力就行了/************************************************************************* > Fil...

【topcoder SRM 702 DIV 2 250】TestTaking

Problem StatementRecently, Alice had to take a test. The test consisted of a sequence of true/false ...

topcoder SRM div 2 level 1

Problem Statement   Dmitry likes TopCoder Single Round Matches. Once, he registered for an ...

SRM 492 div1 level 2

There is a kingdom with N cities numbered 0 through N-1. Gogo wants to survey several cities in the...

Topcoder SRM 562 DIV2 900 RandomOption

Topcoder SRM 562 DIV2 900 RandomOption

SRM 668 DIV 2 AnArray 1000-point

Problem StatementOne day, Bob the Coder was wondering whether abstract programming problems can have...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:SRM 670 div2 A BearSong
举报原因:
原因补充:

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