题目描述
The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a diploma.
- None of those with score equal to zero should get awarded.
- When someone is awarded, all participants with score not less than his score should also be awarded.
- Determine the number of ways to choose a subset of participants that will receive the diplomas.
关键信息部分翻译:
- 至少有一个参与者应该获得文凭。
- 得分为零者不得获奖。
- 当有人被奖励时,所有得分不低于他的参与者也应该被奖励
- 确定选择一部分将获得文凭的参与者的方式的数量。
Setsuna wants to know the shortest time for the message to reach at least one of the stars after she sends it.
You can assume that Einstein’s theory of relativity doesn’t work in Setsuna’s world.
输入描述
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of participants.
The next line contains a sequence of n integers a1, a2, …, an (0 ≤ ai ≤ 600) — participants’ scores.
It’s guaranteed that at least one participant has non-zero score.
输出描述
Print a single integer — the desired number of ways.
输入输出样例
//Example1
//Input
4
1 3 3 2
//Output
3
//Example2
//Input
3
1 1 1
//Output
1
//Example3
//Input
4
42 0 0 42
//Output
1
线索提示
There are three ways to choose a subset in sample case one.(对于线索1)
- Only participants with 3 points will get diplomas.
- Participants with 2 or 3 points will get diplomas.
- Everyone will get a diploma!
The only option in sample case two is to award everyone.(对于线索二)
Note that in sample case three participants with zero scores cannot get anything.
一、解题思路
上面说了一大堆,翻译过来的人话就是:
给了你一堆分数,主要按照当有人被奖励时,所有得分不低于他的参与者也应该被奖励这一奖励方式对参赛者进行颁奖,喊你求有多少种颁奖的方式
其实,这道题目可以转化为求一个集合的子集的问题 (集合中没有重复元素,想想你和另外的一个同学考了98分,他有奖金,你也一定要有,换句话说,他拿到奖状就代表着你拿到奖状了,所以你们俩只需要那98这一个成绩出来和其他同学比一比就可以了)
对于这个要求,我们只需要用STL库中的set类型即可(具有自动去重功能)
我们于是举几个例子,就能够说明问题
如输入
6
0 1 2 3 3 4
则有4种不同的元素(除0,除重复)
- 我们选4个同学获奖 >>>>> 有1种情况
- 我们选3个同学获奖 >>>>> 有1种情况
- 我们选2个同学获奖 >>>>> 有1种情况
- 我们选1个同学获奖 >>>>> 有1种情况
所以,我们可以得到规律:
集合元素个数
≡
颁奖方案个数
\text{集合元素个数} \equiv \,\,\text{颁奖方案个数}
集合元素个数≡颁奖方案个数
我们只需要对每个范例逐一将元素添加进集合,最后用.size()输出元素个数即可
二、题解
源代码
代码如下:
/*
* Author: FeverTwice
* Date: 2021-05-02
* Func: Solution for Olympiad
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <functional>
#include <set>
#define debug(a) cout<<#a<<"="<<a<<endl;
#define lyh(i,a,b) for(int i=a;i<=b;i++)
#define hyl(i,a,b) for(int i=a;i>=b;i--)
#define LL long long
#define mm memset
#define EPS 1e-8
#define INF 0x7fffffff
using namespace std;
set<int> stu; //定义集合
int main()
{
int n;
cin >> n;
int temp;
for (int i = 0; i < n; i++)
{
cin >> temp;
if (temp > 0)
{
stu.insert(temp); //如果非零,往集合内添加元素
}
}
cout << stu.size() << endl; //输出集合个数
return 0;
}
VJudge评判结果

写在最后
各位看官,都看到这里了,麻烦动动手指头给博主来个点赞8,您的支持作者最大的创作动力哟! <(^-^)>
才疏学浅,若有纰漏,恳请斧正
本文章仅用于各位同志作为学习交流之用,不作任何商业用途,若涉及版权问题请速与作者联系,望悉知
2948




被折叠的 条评论
为什么被折叠?



