Olympic Parade UVALive - 7181 卡时间空间,哈希
2017-10-02 01:20
351 查看
Olympic Parade UVALive - 7181
大意:
多组样例,每组样例给一个 N 和 K ,给出 N 个数字,求数字出现的次数不为 K 的倍数的那一个。
样例输入:
10 3
1
1
2
3
1
3
3
2
2
2
输出:
2
Hint:
有3个1,4个2,3个3,故答案为2。
分析:
各种卡时间,unordered_map也不行,用位运算分析优化。
处理出二进制表示,这个位上出现 K 的倍数次,说明是对的,否则这个位是不满足的答案的二进制表示之一。具体见代码
具体实现:
大意:
多组样例,每组样例给一个 N 和 K ,给出 N 个数字,求数字出现的次数不为 K 的倍数的那一个。
样例输入:
10 3
1
1
2
3
1
3
3
2
2
2
输出:
2
Hint:
有3个1,4个2,3个3,故答案为2。
分析:
各种卡时间,unordered_map也不行,用位运算分析优化。
处理出二进制表示,这个位上出现 K 的倍数次,说明是对的,否则这个位是不满足的答案的二进制表示之一。具体见代码
具体实现:
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int,int> pii; #define mem(s,t) memset(s,t,sizeof(s)) #define D(v) cout<<#v<<" "<<v<<endl #define inf 0x3f3f3f3f #define pb push_back //#define LOCAL const int mod=1e9+7; const int MAXN =1e5+10; int cnt[30]; int main() { #ifdef LOCAL freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int n,k; while(~scanf("%d%d",&n,&k)){ mem(cnt,0); for(int i=0;i<n;i++){ int x; scanf("%d",&x); for(int j=0;j<32;j++){ if((1<<j)&x) cnt[j]++; } } int ans=0; for(int i=0;i<32;i++){ if(cnt[i]%k) ans|=(1<<i); } printf("%d\n",ans); } return 0; }
相关文章推荐
- Confusing Date Format UVALive 7711 给定mm-mm-mm格式的时间。年份(1900-1999)只给了后两位数,问有多少种合法的排列使时间正确。
- UVALive 4327 Parade(hdu 2490 Parade)
- UVALive - 4856 OmniGravity(哈希+枚举)
- PAT 1048. Find Coins (25) 常见哈希应用,空间换时间
- UVALive 4327 Parade
- UVALive 4327 Parade(hdu 2490 Parade)
- Decoding Baby Boos UVALive - 6917-------降低时间复杂度
- UVaLive 4327 | POJ 3926 - Parade (单调队列优化DP)
- UVALive - 6893 The Big Painting 字符串哈希
- UVALive 2678 利用序列的前缀来减少时间复杂度
- UVA 11078 Open Credit System(空间优化+时间优化)
- UVALive - 4327 Parade DP + 优先队列
- UVALive 4815 || SYSU 2387 Kids' Wishes dfs+(字典树哈希)
- UVaLive 6627 First Date (转换时间)
- UVA Live Achrive 4327 Parade (单调队列,dp)
- UVALive 6047 Perfect Matching(字符串哈希)#by zh
- HDU 1665 or UVALive 3263 || That Nice Euler Circuit (欧拉定理求面数 F = E+2-V
- 算法的时间复杂度和空间复杂度-总结
- UVALive - 6469(博弈、记忆化搜索)
- 《剑指offer》刷题笔记(时间空间效率的平衡):丑数