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 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
  • 222

SRM 649 div2 1000

题意: 给一个整数序列。 选择一个整数B,将序列中所有数XOR上B后得到另一个序列。。 顺序对:a[i]...
  • slowlight93
  • slowlight93
  • 2015年02月12日 18:31
  • 500

SRM 670 div2 B BearSlowlySorts

Problem Statement    Problem Statement for BearSlowlySorts Pro...
  • ZZ_AC
  • ZZ_AC
  • 2015年11月19日 22:11
  • 221

TC SRM 670 Div2 1050 Treestrat

Problem StatementTwo players are playing a game with some tokens on a tree.Player A has one or more ...
  • Liao_Jingyi
  • Liao_Jingyi
  • 2015年10月14日 18:35
  • 249

SRM 633 DIV2 A

Problem Statement   Here at [topcoder], we call a contestant a "target" if their rating is 3000 ...
  • chaoweilanmao
  • chaoweilanmao
  • 2015年02月10日 12:15
  • 599

Topcoder SRM 636 Div2 A

题意:给你n堆石子,每堆石子有一定数目的石子。我们定义一种移动,每一次从一堆的石子中拿出两个石子,对于某堆石子的数目少于3个不能再取。判断最少需要多少次使得每一堆的石子的个数都相等。如果不能输出-1。...
  • huayunhualuo
  • huayunhualuo
  • 2016年06月02日 21:42
  • 186

【SRM 717 div2 A】 NiceTable

Problem StatementYou are given a vector t that describes a rectangular table of zeroes and ones. Ea...
  • harlow_cheng
  • harlow_cheng
  • 2017年07月01日 11:13
  • 139

TopCoder SRM 637 Div2 A

题意:两个人玩游戏,每一出的数大的人得一分,现在给你两个出数的顺序,判断第一个人的得分。#include using namespace std;class GreaterGameDiv2 { ...
  • huayunhualuo
  • huayunhualuo
  • 2016年06月07日 19:38
  • 165

TopCoder SRM 670 Div2 Problem 1050 - Treestrat (floyd)

RT
  • u014247806
  • u014247806
  • 2015年10月11日 10:00
  • 511

猫抓老鼠 floyd SRM 670 Div2 Problem 1050 - Treestrat

题意 在一棵树上,一些猫在一些结点上,一些老鼠在一些结点上。  每轮老鼠方先走,每只老鼠可以选择原地不动或者走到相邻结点。  如果老鼠走到有猫上的结点游戏结束。  问最多进行几轮游戏 ...
  • ACM_10000h
  • ACM_10000h
  • 2015年10月12日 13:09
  • 459
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:SRM 670 div2 A BearSong
举报原因:
原因补充:

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