题目地址:HDU 4588
这题是学长跟我说的1道数位DP。。然后我就按着数位DP去做的,倒是写出来了,但是1直TLE。。后来用类似找规律的方法解出来了。。
首先这题其实就是求每位上总共有多少个1,然后不断从低位开始向高位进位。
方法是比如2进制为1010010的这个数,就能够拆成1000000+10000+103个数,然后从0到111111就是0和1的1个全排序,那末每位上的1的个数总和1定是占1半,然后首位+1,那末10000也能够这样算,然后累加起来就行了。但是还要注意的是,首位的1不只是1000000的时候+1,还有后面的也要加上,所以直接从低位开始枚举,并设置1个变量不断累加就好了。
代码以下:
#include <iostream>
#include <string.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <stdlib.h>
#include <map>
#include <set>
#include <stdio.h>
using namespace std;
#define LL __int64
#define pi acos(⑴.0)
const int mod=100000000;
const int INF=0x3f3f3f3f;
const double eqs=1e⑻;
int c[40], d[3][40], sum[103];
LL Cal(LL x, int f)
{
int i, cnt=0, j;
LL ans=0;
while(x){
c[cnt++]=(x&1);
x>>=1;
}
for(i=0;i<cnt;i++){
if(c[i]){
d[f][i]+=ans+1;
for(j=0;j<i;j++){
d[f][j]+=(1<<i⑴);
}
ans+=(1<<i);
}
}
}
int main()
{
LL a, b, i, ans;
while(scanf("%I64d%I64d",&a,&b)!=EOF){
memset(sum,0,sizeof(sum));
memset(d,0,sizeof(d));
Cal(b, 0);
if(a)
Cal(a⑴, 1);
ans=0;
for(i=0;i<35;i++){
sum[i]=d[0][i]-d[1][i];
//printf("%I64d
",sum[i]);
}
sum[0]>>=1;
ans=sum[0];
//printf("%I64d
",ans);
for(i=1;i<=100;i++){
sum[i]+=sum[i⑴];
sum[i]>>=1;
ans+=sum[i];
//printf("%I64d
",ans);
}
printf("%I64d
",ans);
}
return 0;
}
#include <string.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <stdlib.h>
#include <map>
#include <set>
#include <stdio.h>
using namespace std;
#define LL __int64
#define pi acos(⑴.0)
const int mod=100000000;
const int INF=0x3f3f3f3f;
const double eqs=1e⑻;
int c[40], d[3][40], sum[103];
LL Cal(LL x, int f)
{
int i, cnt=0, j;
LL ans=0;
while(x){
c[cnt++]=(x&1);
x>>=1;
}
for(i=0;i<cnt;i++){
if(c[i]){
d[f][i]+=ans+1;
for(j=0;j<i;j++){
d[f][j]+=(1<<i⑴);
}
ans+=(1<<i);
}
}
}
int main()
{
LL a, b, i, ans;
while(scanf("%I64d%I64d",&a,&b)!=EOF){
memset(sum,0,sizeof(sum));
memset(d,0,sizeof(d));
Cal(b, 0);
if(a)
Cal(a⑴, 1);
ans=0;
for(i=0;i<35;i++){
sum[i]=d[0][i]-d[1][i];
//printf("%I64d
",sum[i]);
}
sum[0]>>=1;
ans=sum[0];
//printf("%I64d
",ans);
for(i=1;i<=100;i++){
sum[i]+=sum[i⑴];
sum[i]>>=1;
ans+=sum[i];
//printf("%I64d
",ans);
}
printf("%I64d
",ans);
}
return 0;
}
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » HDU 4588 Count The Carries (2013年南京邀请赛)
波比源码 » HDU 4588 Count The Carries (2013年南京邀请赛)
buy levaquin 250mg pill buy levaquin generic
tadalafil generic name anafranil 50mg pills buy clomipramine 50mg sale
norvasc usa amlodipine cost order tadalafil
order levitra 20mg without prescription methylprednisolone 8mg oral methylprednisolone 16mg tablet
order clomid pills slots free casino online real money
brand tadalafil 20mg tadalafil 5 mg tablet buy clopidogrel 150mg online
order prednisone 20mg online cheap order deltasone 20mg online generic amoxil 500mg
deltasone generic prednisone 10mg brand vermox 100mg cost
generic retin gel buy avanafil 100mg purchase avanafil
purchase biaxin generic antivert 25mg us meclizine cost
oral naprosyn 500mg order omnicef pill prevacid for sale online
spiriva for sale online order minocin 50mg pill terazosin 1mg brand
order proventil generic albuterol over the counter order generic cipro 500mg
best cialis sites online Cialis no rx slot machine games
best online poker sites casino online games empire city casino online
golden nugget online casino blackjack online free write paper online
purchase altace online purchase glimepiride pill purchase arcoxia
benicar price cost olmesartan order depakote 500mg generic
acetazolamide 250 mg pill acetazolamide 250mg ca azathioprine pills
digoxin order online digoxin generic molnunat 200 mg tablet
buy indomethacin capsule cenforce medication buy cenforce 50mg online
requip pills cheap rocaltrol 0.25 mg trandate online buy
tadalafil online tadacip 20mg for sale buy trimox 250mg pills
nexium 40mg over the counter order generic esomeprazole 20mg purchase lasix pill
cheap tadalafil pills for erection non prescription erection pills
order glucophage 1000mg online cheap order metformin online buy tamoxifen 20mg without prescription
modafinil buy online order promethazine 25mg for sale buy promethazine
prednisone 5mg drug amoxicillin 1000mg us order amoxicillin 250mg generic
clomiphene for sale online clomiphene 50mg sale prednisolone 20mg for sale
accutane for sale online deltasone 40mg generic order ampicillin 500mg
ivermectin 3mg without prescription men’s ed pills buy prednisone 10mg for sale
buy albuterol 2mg inhaler amoxiclav brand augmentin price
isotretinoin 40mg ca zithromax over the counter azithromycin generic
modafinil 200mg pill buy metoprolol pills buy metoprolol 50mg pill
cheap prednisolone tablets neurontin usa furosemide 100mg brand
buy avodart sale cephalexin 500mg for sale buy orlistat 60mg generic
cost imuran purchase naprosyn online cheap order naprosyn online cheap
order cefdinir generic lansoprazole 30mg us protonix 40mg pill
oxybutynin 2.5mg cost ditropan 2.5mg cheap order oxcarbazepine 300mg online