HDOJ 2095 find your present (2)
来源:互联网 发布:2017淘宝年货节时间 编辑:程序博客网 时间:2024/06/06 03:37
HDACM2095
此题采用的是异或的方法计算
a^a == 0
a^0 == a
b^a^b == a —> (b^b==0,0^a==a)
只要输入相同值的个数是偶数则异或后必然为0,
0^n^n^n^…^n(n的个数为奇数)== 0^n^0^0^…^0==n
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.StreamTokenizer;public class Main{ public static void main(String[] args) throws IOException { StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); while(true){ in.nextToken(); int n = (int)in.nval; if (n==0) { break; } int ans = 0; for (int i = 0; i < n; i++) { in.nextToken(); ans = ans ^(int)in.nval; } System.out.println(ans); } }}
阅读全文
0 0
- HDOJ 2095 find your present (2)
- hdoj 2095 find your present (2)
- hdoj.2095 find your present (2) 20140804
- hdoj 2095 find your present (2)
- HDOJ 2095 find your present (2)
- HDOJ find your present (2) 2095
- HDOJ 2095 find your present (2)
- HDOJ 2095-find your present (2)
- HDOJ 2095 find your present (2)
- HDOJ 2095 find your present (2)
- hdoj 1563 Find your present!&&2095 Find your present(2) 异或运算
- hdoj 2095 find your present (2) 【位运算】
- hdoj-2095-find your present (2)【位异或】
- HDOJ 2095 find your present (2) 位运算
- hdoj 2095 find your present (2)【位运算,异或】
- HDOJ 2095 Find your present (2) 异或运算
- hdoj 2095 find your present (2)(异或运算)
- 异或的性质 HDOJ 2095 find your present (2)
- 二叉树的基本操作实现(递归和非递归)
- nginx命令详解
- centos7安装tomcat和jdk
- jmeter插件使用
- DOTween-Ease缓动函数
- HDOJ 2095 find your present (2)
- 机器学习技法课程学习笔记9 -- Decision Tree
- PostgreSQL将日志发送到系统日志中
- centos7 安装mysql5.7(源码安装)
- Android基于JsBridge封装的高效带加载进度的WebView
- C/C++编译器错误代码大全
- Basler Pylon.NET学习笔记1---参数配置
- PAT-甲级-1002 A+B for Polynomials
- Fragment嵌套Fragment,Viewpager和Fragment联动,懒加载