Gym 100818 I Olympic Parade(位运算)
来源:互联网 发布:黑龙江网络骗局 编辑:程序博客网 时间:2024/05/16 12:38
【题目链接】:click here~~
【代码】:
/** Problem: Gym 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;}
1 0
- Gym 100818 I Olympic Parade(位运算)
- gym100818I - Olympic Parade
- csu1709 olympic parade
- CSU1888-Olympic Parade-STL
- Olympic Parade UVALive
- 位运算之 i & -i
- Gym - 100203A Ariel 暴力+位运算
- Olympic
- Java I/O : Bit Operation 位运算
- Java I/O : Bit Operation 位运算
- FZU1860 :Funny Hash game I(位运算)
- 位运算的奇思妙想之i&(-i)
- Parade。。。。
- Parade
- CodeForces Gym 100735I
- Mirrored String I Gym
- Gym 101147.I
- Gym 101164.I
- 自定义viewpager显示内容的风格,viewpager定时循环
- hdoj2066
- wordpress中页面的用户权限设置
- 数据结构学习笔记(十)-图的最小生成树与拓扑排序
- Java 性能笔记:自动装箱/拆箱
- Gym 100818 I Olympic Parade(位运算)
- hdu4027 Can you answer these queries?(成段更新)
- Oracle基础 -- SQL *Plus基本用法
- 预约页面在红米手机上显示异常的问题解决总结
- 英语总结系列(十六):这个四月真不错
- 对接口和抽象类的学习总结
- LeetCode[Stack]----Min Stack&Stack&Queue
- 记录一下DialogFragment的满屏显示与对话框显示
- Ubuntu 14.04远程登录服务器