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次的数了。

#include<stdio.h>
#define clr(a) memset(a,0,sizeof a)
int main(){int i,j,cnt[20][20]={0},n;while(scanf("%d",&n)!=EOF){clr(cnt);getchar();for(i=0;i<n;i++){char ch;j=0;while((ch=getchar())>47)cnt[j++][ch-48]++;}for(i=0;i<20;i++)for(j=0;j<20;j++)if(cnt[i][j]%3)printf("%c",j+'0');printf("\n");}return 0;
}

北邮OJ 84. Single Number相关推荐

  1. 数学问题 | 北邮OJ | 84. Single Number

    https://vpn.bupt.edu.cn/http/10.105.242.80/problem/p/84/ wa到怀疑人生, 原来是要64位整数 map大法 #include <bits/ ...

  2. 北邮oj题库刷题计划(更新ing)

    北邮oj题库刷题计划(更新ing) 83. A + B Problem 84 Single Number 85. Three Points On A Line 120 日期 121 最值问题 122 ...

  3. 北邮OJ 141 虚数

    北邮OJ 虚数 #include <bits/stdc++.h> using namespace std; typedef struct fushu{int x; //实部 int y; ...

  4. 校外如何登陆北邮oj

    由于北邮oj不对外开放,准备复试的我需要进入北邮oj:其他小朋友也有这个想法.故写此博客. 先找北邮土著借北邮账号,包括一些认识的同学,直系学长学姐,他们都很乐意帮助的~ 下面是校外进北邮校内网的方法 ...

  5. 北邮OJ 981. 16校赛-Saber's Number Game

    时间限制 1000 ms 内存限制 65536 KB 题目描述 Saber is fond of number games of various kinds, she particularly lik ...

  6. 北邮OJ 2016 网预-Square Coins

    时间限制 1000 ms 内存限制 65536 KB 题目描述 Artoria, also known as Saber-chan, was born into a time of chaos and ...

  7. 北邮OJ 1010. 16校赛-Binary Strings

    时间限制 5000 ms 内存限制 65536 KB 题目描述 One day, the teacher asked Weishen to judge whether a binary string ...

  8. 北邮OJ 1005. 16校赛-Hawei Learning C

    时间限制 1000 ms 内存限制 65536 KB 题目描述 Hawei is learning C programming language recently, but he is so naiv ...

  9. 北邮OJ 2016网预 - Saber's Conjecture

    时间限制 1000 ms 内存限制 65536 KB 题目描述 In a parallel universe, young Saber-chan does not have a humongous a ...

最新文章

  1. 四、Input框改placeholder中字体的颜色
  2. 用Table变量返回多行数据
  3. php 企业号文本消息推送,Python如何实现微信企业号文本消息推送功能的示例
  4. ios 视频旋转---分解ZFPlayer
  5. 【5分钟系列】搭建基于docker环境搭建下springboot-mysql项目框架
  6. 作业19——夜间模式的开启与关闭,父模板的制作
  7. linux open函数_Linux驱动开发 / 字符设备驱动内幕 (1)
  8. 假如古代有了云计算,延禧攻略里的各位嫔妃要如何宫斗
  9. 用SAX2方式解析XML
  10. 为什么 MapReduce 再次流行起来了?
  11. 区块链入门教程,这一篇就足够了
  12. 统计 假设检验 显著性差异
  13. JAVA基础_IO流_字节流_抽象类OutStreamInputStream
  14. python第五次笔记
  15. AssemblyInfo.cs文件中的程序集属性
  16. 亲亲亲亲兄弟们必学成为首富第一步学习Linux基础命令
  17. java第五章:面向对象(oop)三大特性之多态
  18. 别焦虑了,这才是中国各行业平均工资的真相
  19. ping 工具的使用
  20. Couldn't find include 'Atk-1.0.gir'

热门文章

  1. NLP技术中的Tokenization
  2. 工业界推荐系统必读论文:基于深度学习的推荐模型——DLRM
  3. 数学建模公选课Ch1.2020.4.4
  4. AI识虫:林业病虫害数据集和数据预处理方法
  5. 二维计算几何基础知识
  6. 增大iphone音量技巧_原来苹果手机隐藏功能这么好用!调整这个设置,一键增大外放音量...
  7. python发送消息到微信_通过python登录微信发送消息
  8. 面试官:什么是HTTP连接池?你怎么回答?Feign性能调优之HTTP连接池
  9. LeetCode 22 括号生成
  10. 《操作系统》课程设计报告——用JAVA语言模仿实现“吃水果”问题