How Many Zeroes? LightOJ - 1140

题目:

Jimmy writes down the decimal representations of all natural numbers between and including m and n, (m ≤ n). How many zeroes will he write down?

Input
Input starts with an integer T (≤ 11000), denoting the number of test cases.

Each case contains two unsigned 32-bit integers m and n, (m ≤ n).

Output
For each case, print the case number and the number of zeroes written down by Jimmy.

Sample Input
5
10 11
100 200
0 500
1234567890 2345678901
0 4294967295

Sample Output
Case 1: 1
Case 2: 22
Case 3: 92
Case 4: 987654304
Case 5: 3825876150

大意:

给你一个范围,求这个范围内的数字中出现0的次数

思路:

数位dp,注意按位dp时出现前导0

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int maxn = 123456;
int T;
ll l,r,ans;
ll a[25];
ll dp[25][25];//dp[i][j]处理到第i位时前面出现了j个0

ll dfs(int pos,bool limt,int cnt,bool is0)//is0表示前面是否一直为0
{
    if(!pos)//计算到最后一位
        return is0?1:cnt;//前导0之类的算一个0
    ll sum=0;
    if(!limt&&dp[pos][cnt]!=-1&&!is0)
        return dp[pos][cnt];
    int k=(limt?a[pos]:9);
    for(int i=0;i<=k;i++)
    {
        if(is0)
            sum+=dfs(pos-1,limt&&(i==k),0,i==0);
        else
            sum+=dfs(pos-1,limt&&(i==k),cnt+(i==0),0);
    }
    if(!limt&&!is0)
        dp[pos][cnt]=sum;
    return sum;
}

ll solve(ll k)
{
    int p=0;
    while(k)
    {
        a[++p]=k%10;
        k/=10;
    }
    return dfs(p,1,0,1);
}

int main()
{
    int no=0;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld%lld",&l,&r);
        memset(dp,-1,sizeof(dp));
        printf("Case %d: ",++no);
        printf("%lld\n",solve(r)-solve(l-1));
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
qemu -drive 是 QEMU 的一个命令行参数,用于指定虚拟机的磁盘驱动器。该参数的语法格式如下: ``` -drive [file=file][,if=type][,index=num][,media=type][,cache=type][,format=type][,discard=ignore|unmap][,aio=threads|native][,copy-on-read=on|off][,readonly=on|off][,detect-zeroes=on|off][,serial=serial][,boot=on|off][,discard=on|off][,snapshot=on|off][,sync=standard|full|none][,id=name][,werror=stop|report][,throttling.iops-read=max_iops][,throttling.iops-write=max_iops][,throttling.bps-read=max_bps][,throttling.bps-write=max_bps][,throttling.iops-total=max_iops][,throttling.bps-total=max_bps] ``` 其中,各个选项的含义如下: - `file`:指定虚拟磁盘镜像文件的路径。可以使用本地文件、网络文件、块设备等等。 - `if`:指定虚拟驱动器的接口类型。常见的有 `ide`、`scsi`、`virtio` 等。 - `index`:指定虚拟驱动器的编号。 - `media`:指定虚拟驱动器的类型,如 `disk`、`cdrom`、`floppy` 等。 - `cache`:指定虚拟磁盘的缓存策略。常见的有 `none`、`writeback`、`writethrough` 等。 - `format`:指定虚拟磁盘的格式,如 `raw`、`qcow2` 等。 - `discard`:指定是否在删除文件时立即释放磁盘空间。 - `aio`:异步 I/O 策略,可选值为 `threads` 和 `native`。 - `copy-on-read`:指定是否在读取操作时将数据复制到内存中。 - `readonly`:指定虚拟磁盘是否只读。 - `detect-zeroes`:指定是否在创建虚拟磁盘时检测文件中的零块并进行压缩。 - `serial`:指定虚拟磁盘的序列号。 - `boot`:指定虚拟磁盘是否可用于引导操作系统。 - `snapshot`:指定是否启用快照功能。 - `sync`:指定虚拟磁盘的同步策略。 - `id`:指定虚拟磁盘的ID。 - `werror`:指定写入错误的处理方式。 - `throttling.iops-read`:指定读取操作的最大 IOPS。 - `throttling.iops-write`:指定写入操作的最大 IOPS。 - `throttling.bps-read`:指定读取操作的最大带宽。 - `throttling.bps-write`:指定写入操作的最大带宽。 - `throttling.iops-total`:指定总的最大 IOPS。 - `throttling.bps-total`:指定总的最大带宽。 在使用 `-drive` 参数时,可以通过多次指定该参数来添加多个虚拟磁盘驱动器。例如,下面的命令将创建一个 IDE 接口的虚拟硬盘,其大小为 10G: ``` qemu-system-x86_64 -drive file=disk.qcow2,if=ide,index=0 ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值