当前位置:网站首页>Zcmu--1099: find Element II
Zcmu--1099: find Element II
2022-07-18 03:56:00 【Little why】
Description
Given a set of integers s, There are n Elements , I have a m Time to ask , Give an integer for each query x, if x Exists in the set s Medium output x found at y,y For collection s It appears for the first time after sorting from small to large x The subscript , Otherwise output x not found.
Input
Multiple sets of test data , The first line of each group is two positive integers n,m.(1<=n,m<=1000) Represents the number of elements in the set and the number of queries , Next n Each row has a positive integer representing the elements in the set .( The size of each integer is less than or equal to 100000), Next m Each row has a positive integer representing the element of the query .
Sample Input
4 1
2
3
5
1
5
5 2
1
3
3
3
1
2
3
Sample Output
CASE# 1:
5 found at 4
CASE# 2:
2 not found
3 found at 3
analysis : After sorting, use two points to find The first is greater than or equal to Enter the array subscript of the element , Then compare whether it is the same , The same is to find , Either or the element does not exist .
#include <stdio.h>
#include <algorithm>
using namespace std;
int a[1005];
int main()
{
int n,q,i,c=1,l,z,mid,y;
while(~scanf("%d%d",&n,&q)){
for(i=0;i<n;i++) scanf("%d",&a[i]);
sort(a,a+n);
printf("CASE# %d:\n",c++); // Test case number
while(q--){
scanf("%d",&l);
z=0,y=n-1;
while(z<y){ // Binary small core
mid=(z+y)/2;
if(a[mid]>=l) y=mid;
else z=mid+1;
}
if(a[(z+y)/2]==l) printf("%d found at %d\n",l,y+1);// Equality is finding
else printf("%d not found\n",l);
}
}
return 0;
}边栏推荐
- UTONMOS:社交元宇宙如何构建数字世界
- 深更半夜 - excel办公自动化定制版
- Polardb for PostgreSQL in Alibaba cloud has a function that only read-write nodes are accessed at the application level, and the database automatically
- Unp learning notes - Chapter 2 transport layer
- C # use tooltip control to realize bubble prompt
- The latest research of Zhu Songchun's team: robots can "confide" with humans! Also said that the next step is to create "Ai white"
- Andorid Studio 制作欢乐写数字(Timer启动+帧动画)
- Mise en œuvre du modèle proxy actif zabbix
- 软考 系统架构设计师 简明教程 | 企业信息化与电子商务
- leetcode:558. 四叉树交集【四叉树dfs】
猜你喜欢

Do you know the architecture and engine of MySQL?

MGRE环境下的OSPF实验
![[Voforia] 通过识自己设定图片,显示特定AR模型](/img/4c/36a2009ea309379aa105a94f82b7ac.png)
[Voforia] 通过识自己设定图片,显示特定AR模型

授人以渔-在 SAP MM 物料显示界面上看到一个字段,如何查找哪张数据库表的哪个字段进行的存储

vulnhub Funbox: Easy (funbox3)
![[C language] static & dynamic & file address book (over 10000 words)](/img/c5/171e0d8537d9f09c688e31b290ad65.jpg)
[C language] static & dynamic & file address book (over 10000 words)

Trends in Plant Science | 向改善生态的植物-微生物组互作的方向育种

Is it true that double non undergraduate students cannot enter the big factory? Ali technology four sides + cross face +hr face, successfully got the offer!!
![[vuforia] detailed explanation · Qualcomm vuforia identifies and tracks 3D objects / models, developed by unity](/img/21/b47943605664473d5d6ad1578e9b9a.png)
[vuforia] detailed explanation · Qualcomm vuforia identifies and tracks 3D objects / models, developed by unity

360 is expected to deduct a non net loss of 450million to 630million in the first half of the year, and the advertising budget is less than expected
随机推荐
[C language] static & dynamic & file address book (over 10000 words)
AI briefing - model integration Sam and SWA
抢占新赛道,和数集团大力布局“元宇宙”产业
OpenHarmony藏头诗应用
Prospect of distributed database technology
Andorid studio makes happy writing numbers (timer start + frame animation)
Google Earth engine (GEE) - random forest classification has mapped the detailed code of mangrove app in Guyana in 2000, 2010 and 2020
Ant begin opens PDF to add authentication parameter data
MGRE与OSPF
What is the overall solution for Oracle to migrate to polardb for PostgreSQL?
MGRE环境下的OSPF实验
Google Earth Engine(GEE)——随机森林分类法绘制了2000年、2010年和2020年圭亚那的红树林APP详细代码
Codeforces Round #804 (Div. 2) D. Almost Triple Deletions time limit per test2 seconds (dp好题)
A concise course for the architect of soft examination system | government informatization and e-government
是时候升级你的Junit了,Junit5超详细实战
Between the virtual and the real 03 | with these technologies, you are the "magic pen Ma Liang" that makes digital people live
The colleague next to me was suddenly promoted to meituan P7 because he secretly learned this JVM note?
Gates donated another $20billion, Google cloud switched to arm, and twitter employees were warned by CEO musk. Today, more big news is here
Teach people to fish - see a field on the sap mm material display interface, how to find which field of which database table to store
Really cow b! JD t3-2 is still learning microservice +mysql+kafka+boot2 X+ virtual machine pdf