HDOJ(HDU) 1563 Find your present!(异或)

简介: HDOJ(HDU) 1563 Find your present!(异或)

Problem Description

In the new year party, everybody will get a “special present”.Now it’s your turn to get your special present, a lot of presents now putting on the desk, and only one of them will be yours.Each present has a card number on it, and your present’s card number will be the one that different from all the others.For example, there are 5 present, and their card numbers are 1, 2, 3, 2, 1.so your present will be the one with the card number of 3, because 3 is the number that different from all the others.


Input

The input file will consist of several cases.

Each case will be presented by an integer n (1<=n<=200, and n is odd) at first. Following that, n positive integers will be given in a line. These numbers indicate the card numbers of the presents.n = 0 ends the input.


Output

For each case, output an integer in a line, which is the card number of your present.


Sample Input

5

1 1 3 2 2

3

1 2 1

0


Sample Output

3

2


题意:找出一行数中独立的数!


按位异或的3个特点:

(1) 0^0=0,0^1=1 0异或任何数=任何数

(2) 1^0=1,1^1=0 1异或任何数-任何数取反

(3) 任何数异或自己=把自己置0


先说一下异或运算的运算法则:

1. a ^ b = b ^ a

2. a ^ b ^ c = a ^ (b ^ c) = (a ^ b) ^ c

3. d = a ^ b ^ c 可以推出 a = d ^ b ^ c

4. a ^ b ^ a = b


对于性质1,显而易见。

对于性质2和4,就是可以查找出一组数列中具有奇数个数的数。比如:

题目:有2n+1个数,其中有n个数出现过两次,只有一个数字出现过一次。要求是找出这个数字。


import java.util.Scanner;


public class Main{

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);


       while(sc.hasNext()){

           int n =sc.nextInt();

           if(n==0){

               return ;

           }

           int m =0;

           int s;

           while(n-->0){

               s = sc.nextInt();

               m = m^s;

           }

           System.out.println(m);

       }

   }

}


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22


程序编程之旅


微信公众号


编程之旅,踏人生之路,观世界之行


与50位技术专家面对面


20年技术见证,附赠技术全景图


谙忆

关注


1



2


0



专栏目录






逸川先生

2017.11.14


学长,我拿你的代码去还是超时了,怎么回事


丁国华

2016.04.19


感谢博主的分享。


谙忆作者

回复

丁国华

2016.04.19


客气了(^-^)

相关推荐


hdu-1563 Find your present!

Just do IT!

629

关于寻找数组中的特别数字的小技巧 Find your present! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2335    Accepted Submission(s): 1524 Problem

HDU 1563 Find your present! 异或妙用找到独立出现的数

最新发布

xiongshuxian2019的博客

54

Problem Description In the new year party, everybody will get a “special present”.Now it’s your turn to get your special present, a lot of presents now putting on the desk, and only one of them will be yours.Each present has a card number on it, and your p

HDU 1563 Find your present! 找出不同的数 异或 - 小...

10-13

and your present's card number will be the one that different from all the others.For example, there are 5 present, and their card numbers are 1, 2, 3, 2, 1.so your present will be the one with the card nu...

hdoj 1563 Find your present!&&2095 Find your present(2) 异或...

3-16

&&2095 Find your present(2) 异或运算    http://acm.hdu.edu.cn/showproblem.php?pid=1563 Find your present! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)...

D - find your present (2)

LMengi000的博客

253

D - find your present (2) In the new year party, everybody will get a “special present”.Now it’s your turn to get your special present, a lot of presents now putting on the desk, and only one of them

find your present

杨的博客

202

In the new year party, everybody will get a "special present".Now it's your turn to get your special present, a lot of presents now putting on the desk, and only one of them will be yours.Each present...

【基础训练-异或的运用】find your present_It's the C...

3-9

【基础训练-异或的运用】find your present 问题链接:HDU1563 Find your present!,HDU2095 find your present(2)。 问题简述:(略) 问题分析:For example, there are 5 present, and their card numbers are 1, 2, 3, 2, 1....

hdu-oj 1563 Find your present!_MatchstickMen的博客

3-29

hdu-oj 1563 Find your present! Find your present! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2690 Accepted Submission(s): 1785...

HDU 2095 find your present (2)

可可 の 猫

435

Problem Description In the new year party, everybody will get a "special present".Now it's your turn to get your special present, a lot of

hdoj problem 1563 Find your present!(位运算(异或运算求特殊数))

亿念之茶的专栏

368

Find your present! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2803    Accepted Submission(s): 1854 Problem Description In the ne

hdu 1563

ysc504的专栏

325

Find your present! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1716    Accepted Submission(s): 1111 Problem Description In the new

杭电OJ-- 2095 find your present (依然很水)

李树花开,风中摇曳

1596

Problem Description In the new year party, everybody will get a "special present".Now it's your turn to get your special present, a lot of presents now putting on the desk, and only one of them wil

【ACM解题报告】Find Your Present 2

Bill好想

510

Problem Description In the new year party, everybody will get a "special present".Now it's your turn to get your special present, a lot of presents now putting on the desk, and only one of them will

OJ-HDU find your present (2)

the blog of Lee

219

                          find your present (2) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 28605    Accepted Submission(s): 11214Problem...

HDU-2095 find your present (异或运算)

Sclong0218的博客

112

                                    find your present (2)                            Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)                              ...

hdoj 2095 find your present (2)【位运算,异或】

nailnehc的博客

284

find your present (2) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 18608    Accepted Submission(s): 7167 题目大意:给你n个数,找出其中唯一一个出现过奇数次的

HDU1563 HDU2095 Find your present!【密码】

海岛Blog

1628

Find your present! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4422    Accepted Submission(s): 2922 Problem Description In the new

杭电 HDU ACM 1563 Find your present!

舒哥的blog

965

Find your present! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3096    Accepted Submission(s): 2051 Problem Description In the new

find your present (2)

逆水行舟 不进则退

840

In the new year party, everybody will get a "special present".Now it's your turn to get your special present, a lot of presents now putting on the desk, and only one of them will be yours.Each present

HDOJ-1563-Find your present! 解题报告

JZQT_T的博客

743

位运算巧解题。题意:给你n个数,n为奇数,这n个数里面除了一个数只出现一次其他数都有出现两次,请输出那个出现一次的数。        我的解题思路:根据异或运算性质,相同的数异或等于0,0与任何数异或都得任何数,异或运算满足交换律。这么以来把这所有的数都异或之后就得到了只出现一次的数了。        我的解题代码: #include #include #include

HDU 1563 【Find your present!】

weixin_30753873的博客

29

Problem Description In the new year party, everybody will get a "special present".Now it's your turn to get your special present, a lot of presents now putting on the desk, and only one of them will ...

Find your present!(杭电1563)

My Castle

583

Find your present! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2742    Accepted Submission(s): 1815 Problem Description In the

“相关推荐”对你有帮助么?


非常没帮助


没帮助


一般


有帮助


非常有帮助

©️2022 CSDN 皮肤主题:代码科技 设计师:Amelia_0503 返回首页

关于我们

招贤纳士

商务合作

寻求报道


400-660-0108


kefu@csdn.net


在线客服

工作时间 8:30-22:00

公安备案号11010502030143

京ICP备19004658号

京网文〔2020〕1039-165号

经营性网站备案信息

北京互联网违法和不良信息举报中心

家长监护

网络110报警服务

中国互联网举报中心

Chrome商店下载

©1999-2022北京创新乐知网络技术有限公司

版权与免责声明

版权申诉

出版物许可证

营业执照


谙忆



码龄7年

Java领域优质创作者

1033

原创

4654

周排名

1336

总排名

443万+

访问

等级

4万+

积分

1万+

粉丝

1952

获赞

2173

评论

1909

收藏


















私信

关注


友情栏目


GitHub


QQ技术交流群:819539788

联系邮箱:uifuture@uifuture.com

微信公众号:程序编程之旅

编程之旅,人生之路,不止于编程,还有诗和远方。

阅代码原理,看框架知识,学企业实践;

赏诗词,读日记,踏人生之路,观世界之行;

另:博客中的大部分收费文章,在公众号免费看。关注后有技术交流群加入方式


友情链接

技术数据整合

IT数据的整合

Java技术  

import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n =sc.nextInt();
            if(n==0){
                return ;
            }
            int m =0;
            int s;
            while(n-->0){
                s = sc.nextInt();
                m = m^s;
            }
            System.out.println(m);
        }
    }
}
目录
相关文章
|
数据采集 机器学习/深度学习 数据可视化
R语言从数据到决策:R语言在商业分析中的实践
【9月更文挑战第1天】R语言在商业分析中的应用广泛而深入,从数据收集、预处理、分析到预测模型构建和决策支持,R语言都提供了强大的工具和功能。通过学习和掌握R语言在商业分析中的实践应用,我们可以更好地利用数据驱动企业决策,提升企业的竞争力和盈利能力。未来,随着大数据和人工智能技术的不断发展,R语言在商业分析领域的应用将更加广泛和深入,为企业带来更多的机遇和挑战。
|
10月前
|
人工智能 自然语言处理 JavaScript
体验 通义灵码 2.5 版
通义灵码是阿里云推出的智能编码辅助工具,支持代码生成、智能问答、多文件修改等功能。2.5版本新增智能体模式,具备自主决策与工程记忆能力,集成MCP广场,支持3000+工具扩展。同时升级Qwen3模型,参数量更少但性能更强,支持复杂问题深度思考。企业版提供多模型配置与私域知识增强功能,优化开发者体验。尽管插件安装需依赖本地环境(如node.js),但整体提升了开发效率与灵活性,推动AI原生研发新范式。
1876 5
|
开发工具
Vim如何清空文件
这样,你就清空了你的文件。
1227 1
|
机器学习/深度学习 测试技术 算法
文献解读-DNAscope: High accuracy small variant calling using machine learning
在这项研究中,研究组证明了DNAscope在不同样本和不同覆盖度水平下都能达到比DNAseq更高的准确性。使用GA4GH分层区域进行的分层分析,能够确认DNAscope在大多数分层区域中都具有高准确性,并突显了DNAscope在插入缺失(indels)和包含变异检测较困难的基因组区域的分层中具有更高的准确性。DNAscope结合了GATK's HaplotypeCaller中使用的成熟数学和统计模型,以及用于变异基因型分析的机器学习方法,在保持计算效率的同时实现了卓越的准确性。
211 3
文献解读-DNAscope: High accuracy small variant calling using machine learning
JAVA并发编程系列(9)CyclicBarrier循环屏障原理分析
本文介绍了拼多多面试中的模拟拼团问题,通过使用 `CyclicBarrier` 实现了多人拼团成功后提交订单并支付的功能。与之前的 `CountDownLatch` 方法不同,`CyclicBarrier` 能够确保所有线程到达屏障点后继续执行,并且屏障可重复使用。文章详细解析了 `CyclicBarrier` 的核心原理及使用方法,并通过代码示例展示了其工作流程。最后,文章还提供了 `CyclicBarrier` 的源码分析,帮助读者深入理解其实现机制。
|
开发框架 人工智能 前端开发
【GitHub】github学生认证,在vscode中使用copilot的教程
【GitHub】github学生认证,在vscode中使用copilot的教程
5831 4
|
SQL 关系型数据库 MySQL
MySQL魔法秀:揭秘常用字符串函数的神奇操作
MySQL魔法秀:揭秘常用字符串函数的神奇操作
172 1
|
存储 监控 网络协议
DP读书:《openEuler操作系统》(九)从IPC到网卡到卡驱动程序
DP读书:《openEuler操作系统》(九)从IPC到网卡到卡驱动程序
368 4
nodeValue 属性
`nodeValue`属性用于获取节点的值,如文本、属性。元素节点的nodeValue为undefined,文本节点为其文本内容,属性节点为属性值。示例中,代码加载&quot;books.xml&quot;,获取第一个&lt;title&gt;元素的文本节点值,将其赋给变量txt,结果为&quot;Everyday Italian&quot;。
|
Web App开发 JavaScript 前端开发
js调试的作用及用法
js调试的作用及用法
230 1