HDOJ-1563-Find your present! 解题报告
来源:互联网 发布:阿里云地域选择 编辑:程序博客网 时间:2024/05/23 13:25
位运算巧解题。题意:给你n个数,n为奇数,这n个数里面除了一个数只出现一次其他数都有出现两次,请输出那个出现一次的数。
我的解题思路:根据异或运算性质,相同的数异或等于0,0与任何数异或都得任何数,异或运算满足交换律。这么以来把这所有的数都异或之后就得到了只出现一次的数了。
我的解题代码:
#include <cstdio>#include <cstdlib>#include <cstring>#include <cctype>#include <cmath>#include <climits>#include <algorithm>using namespace std;const int N = 200;int num[N], n, ans;int main(){ while (~scanf("%d", &n) && n) { for (int i=0; i<n; ++i) scanf("%d", &num[i]); ans = num[0]; for (int i=1; i<n; ++i) ans ^= num[i]; printf("%d\n", ans); } return 0;}
1 0
- HDOJ-1563-Find your present! 解题报告
- 【ACM解题报告】Find Your Present 2
- HDOJ 1563 Find your present!
- Hdoj-1563-Find your present!
- hdoj-1563-Find your present!
- HDOJ 1563 Find your present!
- hdoj.1563 Find your present! 20140825
- hdoj 1563 Find your present!&&2095 Find your present(2) 异或运算
- HDOJ(HDU) 1563 Find your present!(异或)
- 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)
- 1587 - Box
- pdf文档下载地址
- C++私有继承派生类转换成基类引用实例
- 3.Material_EditText 你值得拥有
- C++内存泄漏和内存碎片的产生及避免策略
- HDOJ-1563-Find your present! 解题报告
- Linux进程实践(4) --wait避免僵尸进程
- C++数据结构线性表实例
- IL(Microsoft 中间语言)中间语言主要特征
- TextView中的连续空格只显示一个的解决方法
- Codeforces Round #292 (Div. 2) C. Drazil and Factorial(贪心YY)
- C#基础知识-非常经典的“Hello word !”
- TypeScript基本数据类型
- Android代码混淆之混淆规则