NC237553. Rabbit
描述
输入描述
The first line of input contains a single integer
The second line of input contains 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 , 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 , The Cute Value is changed to 2, so he can make The Cute Value be one different number.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)