当前位置:网站首页>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;
}
边栏推荐
- 【QT】QT项目:自制Wireshark
- MySQL:你做过哪些MySQL的优化?
- 论旅行之收获
- Arcgis进阶篇(1)——安装Arcgis Enterprise,创建sde库
- What is a Cross-Site Request Forgery (CSRF) attack?How to defend?
- 数据挖掘和数据仓库之间的区别
- 别再用 offset 和 limit 分页了,性能太差!
- 【二叉树-中等】1261. 在受污染的二叉树中查找元素
- 【每日一题】1413. 逐步求和得到正数的最小值
- 2022.8.8 Exam questions for photographer Lao Ma (photographer)
猜你喜欢
随机推荐
Pagoda server PHP+mysql web page URL jump problem
On the Harvest of Travel
2022年立下的flag完成情况
数组(一)
T5: Text-to-Text Transfer Transformer
What is a Cross-Site Request Forgery (CSRF) attack?How to defend?
SQLserver adds a judgment
量化交易策略介绍及应用市值中性化选股
2022.8.9考试独特的投标拍卖--800题解
2022.8.9考试立方和--1100题解
Under pressure, there must be cowards
控制台中查看莫格命令的详细信息
微生物是如何影响身体健康的
FusionCompute产品介绍
Go语言JSON文件的读写操作
gbase 8a数据库如何查看数据或数据文件是否正常?
Arcgis进阶篇(1)——安装Arcgis Enterprise,创建sde库
2022.8.8考试从记忆中写入(memory)题解
Redis - Basic operations and usage scenarios of String|Hash|List|Set|Zset data types
2020.11.22考试哥德巴赫猜想题解









