Dual horsetail

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 500    Accepted Submission(s): 189

Problem Description
  Nanaya's favorite Dual horsetail robot has run out of power!
  As a best friend of Nanaya, Cdfpysw decide to do something for him.
  Cdfpysw, the king of alpaca, has some very powerful energy balls numbered by 1,2,3……n. He let Nanaya divide them into some sets to save the robot.
  However, if there are three balls whose numbers are labeled X,Y and X&Y in the same set, they will explode! Nanaya must divide these balls into some sets and avoid explosion.
  Nanaya is a shy man, he don't want to divide these balls into too many sets. Please tell him the minimum number of sets.
 
Input
  The first line contains an integer T, indicating the number of cases.
  The next T line, each line contains an integer n indicating the number of balls. (1 <= n <= 109)
 
Output
  For each test case in the input, print one line: "Case #X: Y", where X is the test case number (starting with 1) and Y represents the minimum number of sets.
 
Sample Input
2
2
3
 
Sample Output
Case #1: 1
Case #2: 2
 
 
算法与题目分析:T组数据,每组输入一个n,代表1到n的数据。现在要把这n个数放到一些集合里,求最少的集合数目。
必须满足条件:x, y和(x&y),这三个元素不会同时出现在一个集合了!
      先需要知道一些特殊数字的二进制写法:
      十进制----------二进制
            1               0001
            3               0011
            7               0111
            15             1111
            31          0001 1111
            ......
            规律是:我们从1开始处理数据,当出现一个新的数字,而这个数字的二进制表示全都是1(忽略前导0),就
     必须把这个数字放到一个新增加的集合里面,否则这个数字会与前面的某些数字必定不会满足要求条件。
            n的范围(1 <= n <= 109),所以只需要找出所有的二进制表示全为1的数字的个数。注意不需要把1到n的数据
    挨着进行进制转换。我们只需要进行一个循环即可。二进制表示全为1的这些数是有规律的,如果你了解二进制转十进制
    的算法就会懂的!
            例如:1 = 2^0.
                    3 = 2^0+2^1.
                    7 = 2^2+2^1+2^0.
    代码:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#define PI acos(-1.0)
#define INF 1e9 using namespace std; int dd[100];
int main()
{
int t;
scanf("%d", &t);
int n;
memset(dd, 0, sizeof(dd)); int ans;
int e=1;
dd[e++]=1; ans=1;
int i=1;
while(ans < INF )
{
ans=ans+pow(2, i);
i++;
dd[e++]=ans;
}
// printf("-----%d\n", i); int cnt=1;
while(t--)
{
scanf("%d", &n);
int pos;
for(i=0; i<e; i++)
{
if(n>=dd[i] && n<dd[i+1])
{
pos=i; break;
}
}
printf("Case #%d: %d\n", cnt++, pos );
}
return 0;
}

hdu 2015校赛1002 Dual horsetail (思维题 )的更多相关文章

  1. 2019浙大校赛--G--Postman(简单思维题)

    一个思维水题 题目大意为,一个邮递员要投递N封信,一次从邮局来回只能投递K封.求最短的投递总距离.需注意,最后一次投递后无需返回邮局. 本题思路要点: 1.最后一次投递无需返回邮局,故最后一次投递所行 ...

  2. 2018 HDU多校第四场赛后补题

    2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...

  3. 2018 HDU多校第三场赛后补题

    2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...

  4. 【杂题总汇】HDU多校赛第十场 Videos

    [HDU2018多校赛第十场]Videos 最后一场比赛也结束了…… +HDU传送门+ ◇ 题目 <简要翻译> 有n个人以及m部电影,每个人都有一个快乐值.每场电影都有它的开始.结束时间和 ...

  5. HDU 6140 17多校8 Hybrid Crystals(思维题)

    题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...

  6. HDU多校赛第9场 HDU 4965Fast Matrix Calculation【矩阵运算+数学小知识】

    难度上.,,确实...不算难 问题是有个矩阵运算的优化 题目是说给个N*K的矩阵A给个K*N的矩阵B(1<=N<=1000 && 1=<K<=6),先把他们乘起 ...

  7. 2019 HDU 多校赛第二场 HDU 6598 Harmonious Army 构造最小割模型

    题意: 有n个士兵,你可以选择让它成为战士还是法师. 有m对关系,u和v 如果同时为战士那么你可以获得a的权值 如果同时为法师,你可以获得c的权值, 如果一个为战士一个是法师,你可以获得b的权值 问你 ...

  8. 2019浙大校赛--E--Potion(签到水题)

    一丢丢思维就ok 题目大意: 魔法师要煮药,有n个等级的药,所需要的药物为a1,a2...an,意为第n级需要多少药物,下一行为库存的不同等级药物,药物可降级使用不可升级. 思路:从高级药物开始解,把 ...

  9. 2019牛客多校C Governing sand——桶&&思维题

    题意 有 $n$ 种树,每种树都有高度 $H_i$,费用 $C_i$,数量 $P_i$,现要砍掉一些树,使得剩下的树中最高的树的数量超过一般,求最小的费用.($1 \leq n \leq 10^5, ...

随机推荐

  1. 18. 使用模板【从零开始学Spring Boot】

    转:http://blog.csdn.net/linxingliang/article/details/52017098 18.1 使用thymeleaf 整体步骤: (1)       在pom.x ...

  2. js 简单getByClass得封装

    function getByClass(oParent,sClass){ var elems = oParent.getElementsByTagName("*"); var ar ...

  3. rsync一些常用的命令

    渗透测试的时候会遇到RSYNC 匿名访问 在对一些大型互联网进行测试的时候经常会遇到rsync. 什么是Rsync Rsync(remote synchronize)是一个远程数据同步工具,可通过LA ...

  4. canvas图片压缩,局部放大,像素处理

    直接上代码:(具体看注释) 需要引用jquery.min.js <!DOCTYPE html> <html lang="en"> <head> ...

  5. View的滚动原理简单解析

    一直对View的滚动了解的不深,说明确了吧也能说出个所以然来,所以我就花了点时间做了一个小小的总结,言归正传,view的滑动分为下面三种: 1)View本身不滚动,指滚动View的内容,这也是View ...

  6. Django之通过tag推荐文章

    #路由 views.py def post_detail(request,year,month,day,post): ''' 文章详情 + 评论详情 :param request: :param ye ...

  7. python爬虫,从hao123爬取网址信息

    最近研究python的爬虫,小小程序,拿下来分享,本人使用python3.7,纯粹兴趣爱好,希望能帮助大家激发兴趣.从hao123,爬取各种网址信息,代码如下. import urllib.reque ...

  8. 【转】一步一步带你反编译apk,并教你修改smali和重新打包

    一.工具介绍: 1.apktool:aapt.exe,apktool.bat,apktool.jar;三个在同一目录结合使用,用来反编译apk,apk重新打包: 2.dex2jar:该工具作用是将cl ...

  9. C语言--循环结构

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvenVveW91MTMxNA==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  10. WPF的ListView控件自定义布局用法实例

    正文: 如何布局是在App.xaml中定义源码如下 <Application x:Class="CWebsSynAssistant.App"   xmlns="ht ...