find your present (2)
題意是找出一些數字(奇數個)中出現奇數次得數。看了題解一會才會的,此題涉及到異或,表示有點蒙。
1、一個數異或本身恆等於0,如5^5恆等於0;
2、一個數異或0恆等於本身,如5^0恆等於5。
3 滿足交換律
822833885=5; 用來尋找一串數字中唯一odd次出現的數
所以顯然用異或運算是很完美的解法
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int n,ans,a;
while(scanf("%d",&n)!=EOF) {
if(n==0)break;
scanf("%d",&ans);
for(int i=1;i<n;i++){
scanf("%d",&a);
ans^=a;
}
printf("%d\n",ans);
}
return 0;
}
相關推薦
HD-ACM算法專攻系列(14)——find your present (2)
sent logs light com cnblogs space 問題 bool std 問題描述: 源碼: #include"iostream" #include"algorithm" using namespace std; bool cmp(i
HDU 2095 find your present (2) 異或
然而 open pre aps play 直接 ring clas div 異或 暴力開數組,然而明顯不過,要求32768k,結果超時了 #include <cstdio> #include <cstring> int book[100000
【HDOJ】find your present (2)(思路題)
利用 自己 names namespace pro ble get nbsp tdi find your present (2) 題意:找有唯一一個出現奇數次的數 思路:利用位異或。一個數異或自己本身是0; #include<stdio.h> int
HDU 2095 find your present (2)
number party osi pri there () ont sum light http://acm.hdu.edu.cn/showproblem.php?pid=2095 Problem Description In the new year party, e
find your present (2)
題意是找出一些數字(奇數個)中出現奇數次得數。看了題解一會才會的,此題涉及到異或,表示有點蒙。 1、一個數異或本身恆等於0,如5^5恆等於0; 2、一個數異或0恆等於本身,如5^0恆等於5。 3 滿足交換律 822833885=5; 用來尋找一串數字中唯一odd次出現的數 所
hdu-2095 find your present(2)
using 題目 res pytho href key-value void bubuko 一個數 題目描述如下: 方法一: 位運算 原理:兩個相同的數x,x進行按位與操作,即x^x,結果為0,某個數y與0按位與則結果為原數,即y^0=y;
hdu1563-----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
HDU-2095 find your present (異或運算)
find your present (2) Time Limit: 2000/1000 MS (Java/Others) Memory Li
<gym101343J. Husam and the Broken Present 2> (狀壓DP)
一起 names 都是 預處理 ret %d 註意 一個 size 題意:給定n個串 每個串長度不超過100 找到一個新串 使得這n個串都是它的字串 輸出這個新串的最小長度 題解:n是15 n的階乘的復雜度肯定不行 就想到了2的15次方的復雜度 想到了狀壓
Find Your Personality Out
至今參加過兩次職業測評,第一次是大學期間鄰近畢業時做的郎途職業測評,結果是哲學家型,這方面的代表人物舉例是幾米;第二次是工作快兩年時在才儲上的MBTI職業性格測試,結果是INTP(內傾、直覺、思考和知覺)型,即聰穎機制解決問題的人,亦被稱為智多星型。 這些測試結果不一定正確,卻可以幫助我們更好的分
Find Your Park and Some Rock with Greta Van Fleet
If you mentally visualize a digital map of your town, you might think about the intersections, buildings, landmarks, and parks. On a Mapbox map, each of th
Find your desired fishing site in Ontario Canada
Find your desired fishing site in Ontario CanadaOnce, I was talking with my colleague about outdoor activities, and he told me that he is a fishing enthusi
【jason的專欄】It is easier to find your bugs if you take it slow.Actually taking it slow is faster in the long run
It is easier to find your bugs if you take it slow.Actually taking it slow is faster in the long run
Ubuntu12.04下Qt5.2編譯使用webkit程式 cannot find -lxslt gio-2.0 gstapp-0.10
用Qt5.2編譯一個在Qt5.1.1下能正常編譯的程式,出現如下連結錯誤 /usr/bin/ld: cannot find -lxslt /usr/bin/ld: cannot find -lgio-2.0 /usr/bin/ld: cannot find -lgstapp-0.10 /usr/bin/l
Not able to find Java executable or version. Please check your Java installation. errorlevel=2
'findstr' 不是內部或外部命令,也不是可執行的程式或批處理檔案。Not able to find Java executable or version. Please check your Javainstallation.errorlevel=2請按任意鍵繼續. .
Xcode7 運行iOS10以上系統(10.1、10.2、10.3)解決Could not find Developer Disk Image
ges 添加 -1 eve device images 真機 文件 eight 由於歷史原因,需要在Xcode7上真機運行下app,無奈手機系統已是10.3了,一運行, 就提示:Could not find Developer Disk Image 解決辦法: 1、找
Lesson 2 Building your first web page: Part 1
appear mage ats ref with display sed emp bare In this ‘hands-on’ module we will be building our first web page in no time. W
Lesson 2 Building your first web page: Part 3
create should bsp str process .html anything step rule Time to build your first HTML page by hand I could go on with more theory and sen
Lesson 2 Building your first web page: Part 2
examples pear reads port example eth span contain animation Tag Diagram You may have noticed that HTML tags come in pairs; HTML has bot
coursera Algorithms week1 練習測驗2:Union-find with specific canonical element
data take log pre n) nbsp -- poi take for 題目原文: Add a method find() to the union-find data type so that find(i) returns the largest eleme