0
点赞
收藏
分享

微信扫一扫

Gym 100818 I Olympic Parade(位运算)


【题目链接】:​​click here~~​​

【代码】:

100818I  Olympic Parade
* Running time: 15MS
* Complier: G++
* Author: herongwei
* Create Time: 9:43 2016/4/30 星期六
【题意】:

给出N个数,找出没有恰好出现K次的那个数.

【解题思路】:
题目各种卡,开个1e6数组不用都超内存,因此(暴力,排个序再遍历)没有用,然后想到用位运算,把所有数字的二进制位都累加起来(就是算第i位一共出现了几次1)
如果某一位上1的数目不是k的倍数,那么要找的那个数在这一位必定为1,否则为0。
*/

#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;
const int maxm = 55;
const LL MOD = 999999997;
const double eps = 1e-8;

inline LL read(){
int c=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){c=c*10+ch-'0';ch=getchar();}
return c*f;
}

int gcd(int a,int b){
return b==0?a:gcd(b,a%b);
}

int Eular(int n){
int ret =1;
for(int i=2; i*i<=n; ++i){
if(n%i==0){
ret *= (i-1);
n/=i;
while(n%i==0){
ret*=i;
n/=i;
}
}
}
if(n>1) ret*=(n-1);
return ret;
}

int Get_divisor_sum(int n){
int sum=0;
for(int i=2; i*i<=n; ++i){
if(n%i==0){
sum+=i;
if(n/i!=i) sum+=n/i;
}
}
sum++;
return sum;
}

LL Quick_Mod(LL a,LL b){
LL ans=a,ret=1;
while(b){
if(b&1) ret = ret*ans;
b>>=1;
ans=ans*ans;
}
return ret;
}
LL bitwei(LL x){
LL s=0;
while(x){
if(x%2) s++;
x/=2;
}
return s;
}
int ac[233],bc[233], n,k;
int main(){

// freopen("1.txt","r",stdin);
n=read(),k=read();
memset(ac,0,sizeof(ac));
for(int i=0; i<n; ++i){
int v;v=read();
for(int j=0; j<32; ++j){
if( (1<<j) &v )
ac[j]++;
}
}
int ans=0;
for(int i=0; i<32; ++i){
if(ac[i]%k!=0) ans|=(1<<i);
}
printf("%d\n",ans);
return 0;
}


举报

相关推荐

0 条评论