当前位置:网站首页>pat A1041 Be Unique
pat A1041 Be Unique
2022-07-29 04:02:00 【Boiled water】
pat A1041 Be Unique
subject :
Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1,10^4]. The first one who bets on a unique number wins. For example, if there are 7 people betting on { 5 31 5 88 67 88 17 }, then the second one who bets on 31 wins.
Input Specification:
Each input file contains one test case. Each case contains a line which begins with a positive integer N (≤10^5) and then followed by N bets. The numbers are separated by a space.
Output Specification:
For each test case, print the winning number in a line. If there is no winner, print None instead.
Sample Input 1:
7 5 31 5 88 67 88 17
Sample Output 1:
31
Sample Input 2:
5 888 666 666 888 888
Sample Output 2:
None
link :pat A1041
#include <stdio.h>
int a[100010];
int hashTable[10010] = {
};
int main(){
int n;
scanf("%d", &n);
// Read in all numbers
for(int i = 0; i < n; i++){
// Order hash ---> linear transformation
scanf("%d", &a[i]);
// Count hash ---> Identity transformation
hashTable[a[i]]++;
}
// determine
int ans = -1;
for(int i = 0; i < n; i++){
if(hashTable[a[i]] == 1){
ans = a[i];
break;
}
}
// Output
if(ans == -1){
printf("None");
}else{
printf("%d", ans);
}
return 0;
}
summary :
- There are three useful data in this question :
① Order of input
② Specific values
③ The number of occurrences of each specific value .
Now use the appropriate hash function and array (hashTable) Connect these three values .【 Understand hashes from a special perspective : Connect useful data gracefully 】【 And three useful data need to be connected twice 】.
For order , Just distinguish the order , There is no need for exact order , Therefore, the direct addressing method of integer hash is used -> linear transformation ,H( order ) = order -1,H(key1) Recorded in the array a Of the key values .
For specific values , The direct addressing method of integer hash is used -> Identity transformation ,H(key2) Recorded in the array hashTable Of the key values . - hash The length of an array is always be equal to Max(H(Key)) + 10.
边栏推荐
- First ALV program 2
- Use case of arrow function of new features in ES6
- Design of environment detection system based on STM32 and Alibaba cloud
- Problems encountered in vscode connection SSH
- Form verification of landline
- MySQL第四篇(完结)
- Batch production and upload sales NFT opensea eth polygon
- 这个报错是什么鬼啊,不影响执行结果,但是在执行sql时一直报错。。。连接maxComputer是使用
- Note: restframe work records many to one tables, how to serialize in that table (reverse query)
- VScode连接ssh遇到的问题
猜你喜欢

3.解决Pycharm报错Unresolved reference ‘selenium‘ Unresolved reference ‘webdriver‘

Shopify卖家:EDM营销就要搭配SaleSmartly,轻松搞定转化率

Nacos registry

STM32F103ZET6程序移植为C8T6+C8T6下载程序flash timeout的解决方案

Note: restframe work records many to one tables, how to serialize in that table (reverse query)

Batch production and upload sales NFT opensea eth polygon
![[deep learning CPU (part outside) - virtual memory]](/img/f7/4c72d583456f6f68c52424602ff5d9.png)
[deep learning CPU (part outside) - virtual memory]

UCOS task switching process

BGP的基础配置---建立对等体、路由宣告

Simple cases of inner connection and left connection
随机推荐
First knowledge of C language (3)
MySQL第四篇(完结)
一文学透MySQL表的创建和约束
Press the missing number of interview question 17.04 | | 260. the number that appears only once (including bit operation knowledge points)
[原理] 横向渗透的几种方式
Deconstruction assignment of new features of ES6
The digitalization of the consumer industry is upgraded to "rigid demand", and weiit's new retail SaaS empowers enterprises!
【C语言入门】ZZULIOJ 1031-1035
基于STM32和阿里云的环境检测系统设计
初识C语言(3)
Typescript from getting started to mastering (XVI) configuration file - first knowledge of compileroptions configuration item
Configmap配置与Secret加密
VScode连接ssh遇到的问题
消费行业数字化升级成 “刚需”,weiit 新零售 SaaS 为企业赋能!
How to understand "page storage management scheme"
Pointer variables -printf%d and%p meaning
Safari's compatibility with Z-index
[introduction to C language] zzulioj 1031-1035
The output comparison function of Tim is introduced in detail through PWM breathing lamp and PWM controlled DC motor
Pointer constant and constant pointer