HDU 6186 CS Course
生活随笔
收集整理的這篇文章主要介紹了
HDU 6186 CS Course
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
點(diǎn)擊打開鏈接
CS Course
Time Limit: 4000/2000 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1699????Accepted Submission(s): 726
Problem Description
Little A has come to college and majored in Computer and Science.Today he has learned bit-operations in Algorithm Lessons, and he got a problem as homework.
Here is the problem:
You are giving n non-negative integers a1,a2,?,an, and some queries.
A query only contains a positive integer p, which means you
are asked to answer the result of bit-operations (and, or, xor) of all the integers except ap.
Input
There are no more than 15 test cases.Each test case begins with two positive integers n and p
in a line, indicate the number of positive integers and the number of queries.
2≤n,q≤105
Then n non-negative integers a1,a2,?,an follows in a line, 0≤ai≤109 for each i in range[1,n].
After that there are q positive integers p1,p2,?,pqin q lines, 1≤pi≤n for each i in range[1,q].
Output
For each query p, output three non-negative integers indicates the result of bit-operations(and, or, xor) of all non-negative integers except ap in a line.Sample Input 3 31 1 1123 Sample Output 1 1 01 1 01 1 0
Source 2017ACM/ICPC廣西邀請(qǐng)賽-重現(xiàn)賽(感謝廣西大學(xué))
Recommend liuyiding???|???We have carefully selected several similar problems for you:??6275?6274?6273?6272?6271
?
題意:
給定n個(gè)數(shù),然后是q次詢問(wèn),每次詢問(wèn)為去掉第i個(gè)數(shù),輸出剩下n-1個(gè)數(shù)與、或、異或的結(jié)果
解法1:
前綴數(shù)組和后綴數(shù)組
用p1[i]表示 [1,i] 所有數(shù)與的結(jié)果,b1[i]表示 [i,n] 所有數(shù)與的結(jié)果
解法2:
用num數(shù)組記錄n個(gè)數(shù)轉(zhuǎn)為二進(jìn)制后,每一位上1的個(gè)數(shù)之和,
當(dāng)去掉一個(gè)數(shù)后,更新num數(shù)組,然后遍歷num數(shù)組
如果num[i]==n-1,那么這一位與的結(jié)果為1,否則為0(與運(yùn)算:全1為1,有0為0)
如果num[i]>=1,那么這一位或的結(jié)果為1,否則為0,(或運(yùn)算:全0為0,有1為1)
對(duì)于異或運(yùn)算:
先讓n個(gè)數(shù)異或的結(jié)果為XOR,然后XOR和去掉的數(shù)字異或,結(jié)果就是n-1個(gè)數(shù)字異或的結(jié)果(異或運(yùn)算的逆運(yùn)算)
總結(jié)
以上是生活随笔為你收集整理的HDU 6186 CS Course的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: HDU 1175 连连看 dfs+剪枝
- 下一篇: C++容器 bitset