UVALive-7279
来源:互联网 发布:中指数据库登录 编辑:程序博客网 时间:2024/05/22 08:14
题目连接:7279
题目大意是:给你一个数字,他可以变成由10组成的二进制的这样的串
然后让你判断下能不能组成ABABAB*****AB或者ABABABABABA这样的形式;(A=1,B=0)
第一种情况是:全部都是A没有B;
第二种情况就是上边写的那两种,一个是以A结尾一个是以B结尾。
数据量不大最多就63,三层63的循环无压力。
这个地方用到了STL里面的set,不会的去百度下。
还要注意数据需要用unsignedlonglong 因为数据是2的63次方
long long 存不到。还要注意我用的是pow,但是自带的pow到了后来
就不精确了,具体我也不清楚,所以自己手写了一个Pow,也可以用快速幂。
#include<stdio.h>#include <set>#define LL unsigned long longusing namespace std;set<LL>se;LL pow(int a,int b){LL sum=1;for(int i=1;i<=b;i++)sum=sum*a;return sum;}void sett(){for(int i=1;i<64;i++)//1的个数 {for(int j=0;j<63;j++)//0的个数 {for(int len=1;len<=63;len++)//长度 {if((len%(i+j)==0 || len%(i+j)==i) && ((i+j)<=len)) //当前正好可以放开,当前多一个1的位置{int flag=0;//判断当前是加0还是加1int temp=i;//加的1的个数int temp1=j;//加0的个数int length=len;LL sum=0;while(length){if(flag==0)//开始放1 {sum=sum+pow(2,length-1);temp--;if(temp==0){temp=i;flag=1;}}else if(flag==1 && temp1>=1)//放0 {temp1--;if(temp1==0){temp1=j;flag=0;}}else if(flag==1 && temp1==0)//考虑0 不放但是1放完的情况 所以需要把长度再加上1 {length++;flag=0;}length--;}
if(!se.count(sum)) //有没有都能过。 se.insert(sum); } }}}}int main(){LL a,b;sett();while(scanf("%llu%llu",&a,&b)!=EOF){int sum=0;set<LL>::iterator it;for(it=se.begin();it!=se.end();it++){if(*it>=a && *it<=b)sum++;}printf("%d\n",sum);}}
阅读全文
0 0
- UVALive-7279
- UVALive 7279 Sheldon Numbers
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- 通过虚拟打印机生成pdf文件来转换EXCEL使用方法
- java 关于项目导出功能实现过程中遇到的问题及思路历程
- 第九篇 :微信公众平台开发实战Java版之如何实现自定义分享内容
- 热分析之路1——板级电路案例
- Unity中打开文件窗口(OpenFileDialog)的几种方法对比
- UVALive-7279
- centos7下安装mysql,网上文章都不太准
- Object-c 快速入门
- npoi table样板填写并导出word
- observable
- Elasticsearch-2.3.x填坑之路
- UVA
- c# base关键字的用法
- mysql数据表索引的使用