“玲珑杯”ACM比赛 Round #5 B -- Private Value【STL-map】
2016-11-27 01:30
435 查看
B -- Private Value
Time Limit:1s Memory Limit:128MByte
Submissions:526Solved:174
DESCRIPTION
The "private value" is the value that occurs, but most infrequent.
An array of integers is given, and you need print the private values of the array.
Please notice that, there might be several private values, and you need print them in increasing order.
INPUT
The first line is an integer T(1 <= T <= 4), indicating the number of test cases.For each case, the first line contains an integer n (n <= 100000).The second line contains n integers a_i (0 <= a_i <= 10^9),
OUTPUT
For each case, print all private values in increasing order in a line.
SAMPLE INPUT
2
7
1 1 2 2 3 3 3
5
5 3 2 4 1
SAMPLE OUTPUT
1 2
1 2 3 4 5
SOLUTION
玲珑杯”ACM比赛 Round #5
原题链接:http://www.ifrog.cc/acm/problem/1057
题意:输出一个序列中出现次数最少的元素,数组可能会超时,类似于桶排序的方法估计也会超时,我用map就不用考虑那么多了。
AC代码:
/**
* 行有余力,则来刷题!
* 博客链接:http://blog.csdn.net/hurmishine
*
*/
#include <iostream>
#include <map>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
map<int,int>mp;
mp.clear();
int x;
for(int i=0; i<n; i++)
{
cin>>x;
mp[x]++;
}
map<int,int>::iterator iter;
int minn=1e9;
for(iter=mp.begin(); iter!=mp.end(); iter++)
{
if(iter->second<minn)
minn=iter->second;
}
bool first=true;
for(iter=mp.begin(); iter!=mp.end(); iter++)
{
if(iter->second==minn)
{
if(!first)
cout<<" "<<iter->first;
else
{
first=false;
cout<<iter->first;
}
}
}
cout<<endl;
}
return 0;
}
Time Limit:1s Memory Limit:128MByte
Submissions:526Solved:174
DESCRIPTION
The "private value" is the value that occurs, but most infrequent.
An array of integers is given, and you need print the private values of the array.
Please notice that, there might be several private values, and you need print them in increasing order.
INPUT
The first line is an integer T(1 <= T <= 4), indicating the number of test cases.For each case, the first line contains an integer n (n <= 100000).The second line contains n integers a_i (0 <= a_i <= 10^9),
OUTPUT
For each case, print all private values in increasing order in a line.
SAMPLE INPUT
2
7
1 1 2 2 3 3 3
5
5 3 2 4 1
SAMPLE OUTPUT
1 2
1 2 3 4 5
SOLUTION
玲珑杯”ACM比赛 Round #5
原题链接:http://www.ifrog.cc/acm/problem/1057
题意:输出一个序列中出现次数最少的元素,数组可能会超时,类似于桶排序的方法估计也会超时,我用map就不用考虑那么多了。
AC代码:
/**
* 行有余力,则来刷题!
* 博客链接:http://blog.csdn.net/hurmishine
*
*/
#include <iostream>
#include <map>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
map<int,int>mp;
mp.clear();
int x;
for(int i=0; i<n; i++)
{
cin>>x;
mp[x]++;
}
map<int,int>::iterator iter;
int minn=1e9;
for(iter=mp.begin(); iter!=mp.end(); iter++)
{
if(iter->second<minn)
minn=iter->second;
}
bool first=true;
for(iter=mp.begin(); iter!=mp.end(); iter++)
{
if(iter->second==minn)
{
if(!first)
cout<<" "<<iter->first;
else
{
first=false;
cout<<iter->first;
}
}
}
cout<<endl;
}
return 0;
}
相关文章推荐
- 玲珑杯1052 - See car——STL集合的应用(“玲珑杯”ACM比赛 Round #4 )
- 玲珑杯”ACM比赛 Round #5
- “玲珑杯”ACM比赛 Round #5 H -- Variance(线段树+方差)
- “玲珑杯”ACM比赛 Round #5 C -- Coco(递归)
- “玲珑杯”ACM比赛 Round #5 H -- Variance 简单树状数组
- “玲珑杯”ACM比赛 Round #5 I -- I am Two【位运算判断2的幂】
- “玲珑杯”ACM比赛 Round #5------I am Two
- 玲珑杯”ACM比赛 Round #5 --2的幂次方
- 玲珑杯”ACM比赛 Round #15 D
- 玲珑杯”ACM比赛 Round #4 E -- array【DP】
- “玲珑杯”ACM比赛 Round #18 A -- 图论你先敲完模板(DP+思路)
- “玲珑杯”ACM比赛 Round #18
- “玲珑杯”ACM比赛 Round #19
- ACM: 一题STL map题 poj 1002 (bt…
- 玲珑杯”ACM比赛 Round #15 D 咸鱼商店【二分+01背包】
- “玲珑杯”ACM比赛 Round #12题解&源码
- “玲珑杯”ACM比赛 Round #4 A -- chess play
- 玲珑杯”ACM比赛 Round #4 G -- See car【Set】
- 玲珑学院ACM比赛 Round #5 Aplus B
- “玲珑杯”ACM比赛 Round #18 A -- 计算几何你瞎暴力