当前位置:网站首页>2022.8.9 Exam Unique Bid Auction--800 Question Solutions
2022.8.9 Exam Unique Bid Auction--800 Question Solutions
2022-08-10 03:21:00 【bj_hacker】
题目
4、Unique Bid Auction–800
时间限制: | 空间限制:
题目描述:
有 个正整数 .
请找出 满足: 是独特的(即这 And does not exist in the number 相等的数)且 中所有小于 The numbers are not unique,
Or judge that there is no eligible condition .
有 组测试数据.
输入格式:
第一行仅有一个正整数 ( ),表示测试数据的组数.
接下来有 组测试数据,每组共两行:
第一行仅一个正整数 ( ,and all test data 之和不超过 ),表示有 个
数;
第二行有 个正整数 ( )用空格隔开.
输出格式:
共 行,每行一个整数:If the set of test data does not meet the conditions ,输出 ;否则,输出符合条件的 .
思路
First use a bucket to store the number of occurrences of each number,Use another array to record whether all numbers smaller than a certain number are not unique.
代码实现
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int t,n;
int a[maxn],cnt[maxn];
bool op[maxn];
int main(){
scanf("%d",&t);
while(t--){
memset(cnt,0,sizeof(cnt));
memset(op,false,sizeof(op));
scanf("%d",&n);
int ans=-1;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
cnt[a[i]]++;
}
op[1]=true;
for(int i=2;i<=n;i++){
if(cnt[i-1]>1||cnt[i-1]==0){
if(op[i-1])op[i]=true;
}
}
for(int i=1;i<=n;i++){
if(cnt[a[i]]==1){
if(op[a[i]]){
ans=i;
break;
}
}
}
printf("%d\n",ans);
}
return 0;
}
边栏推荐
猜你喜欢
随机推荐
HRnet
【机器学习】随机森林、AdaBoost、GBDT、XGBoost从零开始理解
2022.8.9 Exam Travel Summary
控制台中查看莫格命令的详细信息
[Syntax sugar] About the mapping of category strings to category numeric ids
【二叉树-中等】687. 最长同值路径
2022.8.9 Remainder of Exam Balance--1000 Question Solutions
Process management and task management
How Microbes Affect Physical Health
FusionConpute虚拟机的发放与管理
桌面云组件介绍与安装
Deep Learning (5) CNN Convolutional Neural Network
【二叉树-简单】112. 路径总和
【QT】QT项目:自制Wireshark
自动化测试中,测试数据与脚本分离以及参数化方法
RESOURCE_EXHAUSTED: etcdserver: mvcc: database space exceeded
2022.8.9考试独特的投标拍卖--800题解
《GB39707-2020》PDF download
在蓝图中给组件动态加子Actor组件
what is eabi









