当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
数据库治理利器:动态读写分离
程序员的专属浪漫——用3D Engine 5分钟实现烟花绽放效果
Difference Between Data Mining and Data Warehousing
OpenCV图像处理学习一,加载显示修改保存图像相关函数
数据在内存中的存储
Pagoda server PHP+mysql web page URL jump problem
【SSRF漏洞】实战演示 超详细讲解
用于X射线光学器件的哈特曼波前传感器
RESOURCE_EXHAUSTED: etcdserver: mvcc: database space exceeded
【Kali安全渗透测试实践教程】第9章 无线网络渗透
随机推荐
别再用 offset 和 limit 分页了,性能太差!
数据治理(五):元数据管理
控制台中查看莫格命令的详细信息
中英文互译在线翻译-在线翻译软件
2022年8月1日-8月7日(本周10小时,合计1422小时,剩余8578小时)
Fusion Compute网络虚拟化
用于X射线光学器件的哈特曼波前传感器
what is a microcontroller or mcu
Janus actual production case
MMDetection框架的anchor_generators.py解析
数据在内存中的存储
LeetCode 每日一题——1413. 逐步求和得到正数的最小值
Deep Learning (5) CNN Convolutional Neural Network
高压之下,必有懦夫
FusionCompute产品介绍
【二叉树-中等】2265. 统计值等于子树平均值的节点数
2022.8.9考试游记总结
【二叉树-中等】1379. 找出克隆二叉树中的相同节点
2022.8.9 Exam Travel Summary
2020.11.22考试哥德巴赫猜想题解