列表

详情


NC237553. Rabbit

描述

What a cute rabbit! Mr.Gree has a lot of cute rabbits in the farm, and every rabbit has a number a_1, a_2, a_3...a_n. Different rabbits may have same numbers. Mr.Gree thinks The Cute Value of these rabbits is . One day, he wants to make The Cute Value changed, so he takes away exactly one rabbit and The Cute Value is changed.

Mr.Gree wants to know how many different numbers The Cute Value could be?

For example, Mr.Gree has three rabbits numbered [3,4,5], now The Cute Value is . If he takes away a rabbit numbered 3, The Cute Value will change to . And if he takes away a rabbit numbered 4, now The Cute Value will change to . And if he take away a rabbit numbered 5, now The Cute Value will change to . So The Cute Value could change to 12, 15 or 20 three numbers after one rabbit is took away.

输入描述

The first line of input contains a single integer 

The second line of input contains n integer means the number that the rabbit has.

输出描述

print one line contains an integer.

示例1

输入:

3
3 4 5

输出:

3

示例2

输入:

4
1 1 2 2

输出:

1

示例3

输入:

4
-1 -1 1 1

输出:

1

说明:

In the second case, initially The Cute Value is 1*1*2*2=4, if Mr.Gree takes away the rabbit numbered 1, The Cute Value is still 4, not changed.But if Mr.Gree takes away the rabbit numbered 2, The Cute Value is 1*1*2=2, The Cute Value is changed to 2, so he can make The Cute Value be one different number.

In the third case, the only way to make The Cute Value change is take away the rabbit numbered -1.

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(clang++ 11.0.1) 解法, 执行用时: 100ms, 内存消耗: 4096K, 提交时间: 2022-10-20 19:20:39

#include<bits/stdc++.h>
using namespace std;
map<int,int>p;
int main()
{
	int n;
	cin>>n;
	int s=0;
	while(n--)
	{
		int d;
		cin>>d;
		
		if(d!=1) p[d]++;
		if(p[d]==1) s++;
	}
	if(p[0]==0||p[0]==1)
	cout<<s;
	else
	{
		cout<<"0";
	}
}

pypy3 解法, 执行用时: 266ms, 内存消耗: 36940K, 提交时间: 2022-05-30 10:21:57

from collections import Counter

n=int(input())
a=list(map(int,input().split()))
d=Counter(a)
if 0 in a:
    if d[0]==1:
        print(1)
    else:
        print(0)
else:
    print(len(d)-(1 in a))

Python3 解法, 执行用时: 106ms, 内存消耗: 16188K, 提交时间: 2022-06-25 14:52:54

n = int(input())
a = list(map(int, input().split()))
s = set(a)
ans = len(s)
if a.count(0) > 1:
  ans = 0
elif 0 in s:
  ans = 1
elif 1 in s:
  ans -= 1
print(ans)

上一题