当前位置:网站首页>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;
}
边栏推荐
- [Syntax sugar] About the mapping of category strings to category numeric ids
- 【二叉树-中等】1104. 二叉树寻路
- Database management tool: dynamic read-write separation
- 论旅行之收获
- 中英文互译在线翻译-在线翻译软件
- RESOURCE_EXHAUSTED: etcdserver: mvcc: database space exceeded
- ArcGIS Advanced (1) - Install ArcGIS Enterprise and create an sde library
- Shell编程--awk
- 【二叉树-中等】1261. 在受污染的二叉树中查找元素
- 免费文档翻译软件电脑版软件
猜你喜欢
随机推荐
Janus actual production case
SQL注入的order by ,limit与宽字节注入
翻译工具-翻译工具下载批量自动一键翻译免费
SQLserver adds a judgment
将信号与不同开始时间对齐
自动化测试中,测试数据与脚本分离以及参数化方法
2020.11.22考试哥德巴赫猜想题解
数据治理(五):元数据管理
小菜鸟河北联通上岗培训随笔
2022.8.8考试摄像师老马(photographer)题解
QT中,QTableWidget 使用示例详细说明
C# 正则表达式分组查询
宝塔服务器PHP+mysql网页URL跳转问题
RESOURCE_EXHAUSTED: etcdserver: mvcc: database space exceeded
2022.8.8考试区域链接(district)题解
[Swoole Series 3.5] Process Pool and Process Manager
Unity3D创建道路插件EasyRoads的使用
控制台中查看莫格命令的详细信息
按钮倒计时提醒
高压之下,必有懦夫