当前位置:网站首页>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.
边栏推荐
- 谁能详细说下mysqlRC下的半一致读和怎么样减少死锁概率?
- Spark dataframe replaces empty characters (or other values) in each column with null
- Data too long for column 'xxx' at row 1 solution
- Three tier architecture of enterprise network
- 消费行业数字化升级成 “刚需”,weiit 新零售 SaaS 为企业赋能!
- Typescript from getting started to mastering (19) enumeration types
- Basic configuration of BGP - establish peers and route announcements
- 关于ALV格式控制部分的写法
- C language - character array - string array - '\0' -sizeof-strlen() -printf()
- 华为天才少年稚晖君做了一把模块化机械键盘,引起极客圈地震,网友:这才是真正的客制化...
猜你喜欢

Meeting notice of OA project (Query & whether to attend the meeting & feedback details)
![[原理] 横向渗透的几种方式](/img/fc/2ef7dd6ebc5c0bd8f7d302d8b596d6.png)
[原理] 横向渗透的几种方式

数据挖掘——关联分析例题代码实现(下)

Ma Zhixing entered the mass production of front loading, starting with the self-developed domain controller?

The solution of porting stm32f103zet6 program to c8t6+c8t6 download program flash timeout

小马智行进军前装量产,从自研域控制器入手?

Object array merges elements according to a field

CUB_ Visualization of key points in 200 bird dataset

Ribbon principle analysis namedcontextfactory

Typescript from getting started to mastering (XX) function generics
随机推荐
Arrow function of new features of ES6
Note: restframe work records many to one tables, how to serialize in that table (reverse query)
[原理] 横向渗透的几种方式
Is the array name a pointer
SQL窗口函数
关于双指针的思想总结
Analysis of new retail o2o e-commerce model
Typescript from getting started to mastering (19) enumeration types
[BGP] small scale experiment
Opensql quick learning
3.解决Pycharm报错Unresolved reference ‘selenium‘ Unresolved reference ‘webdriver‘
Safari's compatibility with Z-index
Problems encountered in vscode connection SSH
Lucifer 98 life record ing
SSL==证书相关概念
Big manufacturers finally can't stand "adding one second", and companies such as Microsoft, Google meta propose to abolish leap seconds
C language - character array - string array - '\0' -sizeof-strlen() -printf()
Wechat applet monitors sliding events on the screen
基于STM32和阿里云的环境检测系统设计
大厂们终于无法忍受“加一秒”了,微软谷歌Meta等公司提议废除闰秒