1228 - Integer Transmission

You’re transmitting an n -bits unsigned integer k through a simulated network. The i -th bit counting from left is transmitted at time i (e.g. 4-bit unsigned integer 5 is transmitted in this order: 0-1-0-1). The network delay is modeled as follows: if a bit is transmitted at time i , it may arrive at as early as i + 1 and as late is i + d + 1 , where d represents the maximal network delay. If more than one bit arrived at the same time, they could be received in any order.

For example, if you’re transmitting a 3-bit unsigned integer 2 (010) for d = 1 , you may receive 010, 100 (first bit is delayed) or 001 (second bit is delayed).

Write a program to find the number of different integers that could be received, and the smallest/largest ones among them.

Input

The input contains several test cases. Each case consists of three integers n, d, k (1n64, 0dn, 0k < 2n) , the number of bits transmitted, the maximal network delay, and the integer transmitted. The last test case is followed by a single zero, which should not be processed.

Output

For each test case, print the case number and the number of different integers that could be received, followed by the minimal and maximal one among them.

Sample Input

3 0 2
3 1 2
10 2 888
7 3 107
0
Sample Output

Case 1: 1 2 2
Case 2: 3 1 4
Case 3: 25 490 984
Case 4: 19 47 122

我有话说:
1.简化问题:我们把转换成二进制的0和1都看成按出现的顺序依次收到。只是0和1进行了交叉错位。
2.求最大值和最小值,可以利用贪心思想,最大值尽量先收到1,最小值尽量先收到0;
3.接收的时间限制为1~n,因为同一时刻接收到的数的排列是任意的,所以尽管理论上可以超出n,但是并没有得到更多的解。
4.由1中的定义我们可以得到有关状态的定义:d(i,j)代表已经接收了i个0,j个1所有的情况数。那么转移的方向不外乎d(i+1,j)和d(i,j+1)两种。所以,关键点是判断下一个收到bit是0还是1.
判断方法是当T(i+1)+d>=T(j+1)时,其中Ti表示第i个0开始发出的时间,Tj表示第j个1开始发出的时间,d为最长延时。
状态转移方程为
if(can_receive_one(i,j))f[i][j+1]+=f[i][j];
if(can_receive_zero(i,j))f[i+1][j]+=f[i][j];
边界:
f[0][0]=1;

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=64;
typedef long long LL;
int n,d,K[maxn],zcnt,ocnt;
unsigne long long f[maxn+1][maxn+1],minv,maxv;
int Z[maxn],O[maxn];
bool can_receive_zero(int i,int j)//当前我们已经收到i个0,j个1,求收到的下一数
{
    return i+1<=zcnt&&(j==ocnt||O[j]+d>=Z[i]);//请注意第1到zcnt个0的数组下标为0到zcnt-1;
}
bool can_receive_one(int i,int j)
{
    return j+1<=ocnt&&(i==zcnt||Z[i]+d>=O[j]);
}
void greedy()
{
    int i=0,j=0;
    minv=maxv=0;
    while(i<zcnt||j<ocnt)
    {
        if(can_receive_one(i,j)){
            j++;maxv=maxv*2+1;
        }else{
            i++;maxv=maxv*2;
        }
    }
    i=j=0;
    while(i<zcnt||j<ocnt)
    {
        if(can_receive_zero(i,j)){
            i++;minv=minv*2;
        }else{
            j++;minv=minv*2+1;
        }
    }
}
void solve()
{
    memset(f,0,sizeof(f));
    zcnt=ocnt=0;
    for(int i=0;i<n;i++)
    {
        if(K[i]==1)O[ocnt++]=i;
        else Z[zcnt++]=i;
    }

    greedy();
    f[0][0]=1;
    for(int i=0;i<=zcnt;i++)
    {
        for(int j=0;j<=ocnt;j++)
        {
            if(can_receive_one(i,j))f[i][j+1]+=f[i][j];
            if(can_receive_zero(i,j))f[i+1][j]+=f[i][j];
        }
    }
    printf("%d %d %d\n",f[zcnt][ocnt],minv,maxv);
}
int main()
{
    int kase=0;
    unsigned long long k;

    while(scanf("%d%d%d",&n,&d,&k)==3){
    for(int i=0;i<n;i++){
      K[n-i-1]=k%2;k/=2;
    }
    printf("Case %d: ",++kase);
    solve();
  }
    return 0;
}

你发送一个n位无符号整数k通过模拟网络。我th位计数从左传播在时间我(例如4比特无符号整数5是传播在这个顺序:0-1-0-1)。网络延迟是建模如下:如果我有点传播时间,它可能到达早在i+ 1晚是i+ d + 1,其中d表示最大的网络延迟。如果多个同时到达,他们可以在任何顺序。
例如,如果你发送一个3-bit无符号整数2 d = 1(010),你可能会收到010,100(第一位是延迟)或001(第二位是延迟)。
编写一个程序,找到许多不同的整数,可以收到,和最小/最大的其中之一。
输入
输入包含多个测试用例。每个案例包括三个整数n、d、k(1至今,0 dn,0 k < 2 n),传输的比特数,最大网络延迟和整数传播。最后一个测试用例是紧随其后的是一个零,它不应该被处理。
输出
为每个测试用例,打印数量和不同的整数的数量,可以收到,紧随其后的是它们之间的最小和最大的一个。
样例输入
3 0 2
3 1 2
888 2
107 3
0
样例输出
案例1:1 2 2
案例2:3 1 4
案例3:25 490 984
案例4:19 47 122

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值