北邮OJ 84. Single Number
84. Single Number
時間限制1000 ms????內存限制 65536 KB????題目描述
Given an array with N? integers where all elements appear three times except for one. Find out the one which appears only once.
輸入格式
Several test cases are given, terminated by EOF.
Each test case consists of two lines. The first line gives the length of arrayN(1≤N≤10?5?)?, and the other line describes the N? elements. All elements are ranged in [0,2?63??1]?.
輸出格式
Output the answer for each test case, one per line.
輸入樣例
4 1 1 1 3 10 1 2 3 1 2 3 1 2 3 4輸出樣例
3 4?
正文:
此類題目的描述多形如“在一堆正整數中,有一個數恰好出現了B次,而其他的數均出現了A次,一共有N個數,請求出那出現B次的數,數據保證有解”。
設題目輸入為:
第一行3個正整數n,a,b( b<a ),第二行n個正整數,所有的數均在int范圍之內。輸出那個出現b次的數。
分析:
針對此類題目,我們在此給出一個通解——位統計法:本題中,所有數大小在int范圍內,所以數字長度最長不超過10,我們開一個10*10的二維數組。用來統計,所有數字中出現在從第1位(個位)起到第10位(十億位)每一位上0~9這10個數字每個數字出現的次數。
然后我們處理完之后,最后只需要從第10位(十億位)開始到第1位(個位)依次檢查0~9這10個數字出現的次數中,有沒有不被a整除的即可,如果有,輸出之,就可以得到你想要的那個出現了b次的數了。
?
?
總結
以上是生活随笔為你收集整理的北邮OJ 84. Single Number的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Ansj配置指南!
- 下一篇: 北邮OJ 85. Three Point