Dual horsetail
2015-11-24 15:52
477 查看
题目链接; http://acm.fafu.edu.cn/problem.php?id=1564
题意:给一个数n,输出n被分成最小的集合数,要求集合里任意的X,Y,X&Y不能在同一个集合内
思路:找规律,发现每个数的二进制1的数量一样多的分到同一个集合,结果就为小于等于n的二进制1数量的最大值
代码:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
int a[33];
int main()
{
int T,t=0;
scanf("%d",&T);
for(t=1;t<32;t++)
a[t]=(1<<t) - 1;
t=0;
while(T--)
{
t++;
int n;
scanf("%d",&n);
int i;
for(i=1;i<32;i++)
{
if(n<a[i])
break;
}
printf("Case #%d: %d\n",t,i-1);
}
return 0;
}
题意:给一个数n,输出n被分成最小的集合数,要求集合里任意的X,Y,X&Y不能在同一个集合内
思路:找规律,发现每个数的二进制1的数量一样多的分到同一个集合,结果就为小于等于n的二进制1数量的最大值
代码:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
int a[33];
int main()
{
int T,t=0;
scanf("%d",&T);
for(t=1;t<32;t++)
a[t]=(1<<t) - 1;
t=0;
while(T--)
{
t++;
int n;
scanf("%d",&n);
int i;
for(i=1;i<32;i++)
{
if(n<a[i])
break;
}
printf("Case #%d: %d\n",t,i-1);
}
return 0;
}
相关文章推荐
- 粒子群算法(二)全局版本
- Table XXX is marked as crashed and should be repaired问题
- AirPlay无线技术研究
- raid5+lvm实验
- 使用个推的时候出现Installation error: INSTALL_FAILED_DUPLICATE_PERMISSION
- coderforce 519C A and B and Team Training
- 粒子群算法(一)
- WM_PAINT介绍及OnPaint()函数的作用原理
- Linux 命令行发邮件sendmail,mailutils,mutt msmtp
- error LNK2019: 无法解析的外部符号_cvReleaseImage,该符号在函数_main 中被引用
- sgu 252 Railway Communication
- Error in Microsoft Visual Studio 2012 :No exports were found that match the constraint
- 解决Chrome、Safair、Webkit等内核浏览器默认文本域和文本
- [AlwaysOn Availability Groups]监控AG性能
- <学习笔记>安装apk报错:an error occured while deploying the file install failed older sdk
- 【leetcode】Container With Most Water
- 算法杂货铺——分类算法之朴素贝叶斯分类(Naive Bayesian classification)
- implicitlyWait和explicitlyWait的秘密
- 关于MediaRecorder(3761): start failed: -2147483648
- M2 Daily SCRUM要求