NC214492. Treasurecave
描述
输入描述
The first line contains one integer t(1<=t<=20)——the number of test cases.Each test case consists of two lines.The first line contains two integers n and x(1<=n<=105,1<=x<=109)——the number of piles on the air and the numer of coins on the ground.The second line contains n integers a1, a2, a3, ... , an(1<=ai<=109).
输出描述
For each test case, print one line consists of one integer.
示例1
输入:
2 3 4 1 5 2 3 4 1 4 4
输出:
5 0
说明:
C++(clang++11) 解法, 执行用时: 172ms, 内存消耗: 4584K, 提交时间: 2021-01-27 09:52:19
#include <bits/stdc++.h> using namespace std; const int N=1e5+10; int a[N]; int main(){ int n; cin>>n; while(n--){ int n,x; int numn; int num=0; cin>>n>>x; for(int i=0;i<n;i++) cin>>a[i]; a[n]=x; sort(a,a+1+n); for(int i=0;i<=n;i++){ if(a[i]==a[i-1]) { num++; numn=a[i]; } } if(num>1) cout<<"0"<<endl; else if(num==1) cout<<numn<<endl; else cout<<a[n]<<endl; } }
Python3 解法, 执行用时: 201ms, 内存消耗: 22552K, 提交时间: 2021-12-24 12:24:33
T=eval(input()) for i in range(T): m=input().split() x=eval(m[0]) n=eval(m[1]) a=[] m=input().split() for i in range(x): a.append(int(m[i])) a.append(n) if len(set(a))==len(a): print(max(a)) elif len(set(a))==len(a)-1: for i in a: if a.count(i)==2: print(i) break else: print(0)