A - Edit Distance Gym - 102001A

A - Edit Distance

 Gym - 102001A 

A binary string is a non-empty sequence of 00's and 11's, e.g., 010110, 1, 11101, etc. The edit distance of two binary strings SS and TT, denoted by edit(S,T)edit(S,T), is the minimum number of single-character edit (insert, delete, or substitute) to modify SSinto TT. For example, the edit distance of 0011 and 1100 is 44, i.e. 0011 →→ 011 →→11 →→ 110 →→ 1100. The edit distance of 1100101 and 1110100 is 22, i.e. 1100101 →→1110101 →→ 1110100.

Ayu has a binary string SS. She wants to find a binary string with the same length as SS that maximizes the edit distance with SS. Formally, she wants to find a binary string TmaxTmax such that |S|=|Tmax||S|=|Tmax| and edit(S,Tmax)≥edit(S,T′)edit(S,Tmax)≥edit(S,T′) for all binary string T′T′ satisfying |S|=|T′||S|=|T′|.

She needs your help! However, since she wants to make your task easier, you are allowed to return any binary string TT with the same length as SS such that the edit distance of SS and TT is more than half the length of SS. Formally, you must return a binary string TT such that |S|=|T||S|=|T| and edit(S,T)>|S|2edit(S,T)>|S|2.

Of course, you can still return TmaxTmax if you want, since it can be proven that edit(S,Tmax)>|S|2edit(S,Tmax)>|S|2 for any binary string SS. This also proves that there exists a solution for any binary string SS. If there is more than one valid solution, you can output any of them.

Input

Input contains a binary string SS (1≤|S|≤20001≤|S|≤2000).

Output

Output in a line a binary string TT with the same length as SS that satisfies edit(S,T)>|S|2edit(S,T)>|S|2.

Examples

Input

0011

Output

1100

Input

1100101

Output

0011010

Note

Explanation for the sample input/output #1

As illustrated in the example above, the edit distance of 0011 and 1100 is 44. Since 4>424>42, 1100 is one of the valid output for this sample.

 

题意:

给你一个字符串S,请输出一个字符串T,使T与S长度相等的且S到T的编辑距离e>S长度的一半(即 e>ls/2)

思路:

可以先找出S串中0,1的个数。

1)当0、1个数相等时,判断S[0],

       如果S[0]为‘0’的话,则将S[0]变为‘1’,之后的字符串中的‘1’都变成’0‘;

       如果S[0]为’1‘的话,则将S[0]变为‘0’,之后的字符串中的‘0’都变成‘1’;

这样的话,编辑距离e为S长的一半+1;(一半的‘1’变成‘0’ + 一个‘0’变成‘1’)

2)当0、1个数不等时,判断0、1的个数,

       如果0的个数大于1的个数,则将字符串中的‘0’都变成‘1’;

       如果1的个数大于0的个数,则将字符串中的‘1’都变成’0‘;

这样的话,因为0、1个数不等,必有一个的个数大于一半的长度,所以改变这个数就可以使编辑距离>ls/2.

题解:

#include<math.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=2005;
long long n;
char text[maxn];
int main()
{
    scanf("%s",text);
    int lt=strlen(text);
    int x=0,y=0;
    for(int i=0; i<lt; i++)
    {
        if(text[i]=='0')
            x++;
        else
            y++;
    }

    if(x==y)    //
    {
        if(text[0]=='0')
        {
            printf("1");
            for(int i=0; i<lt-1; i++)
                printf("0");
        }
        if(text[0]=='1')
        {
            printf("0");
            for(int i=0; i<lt-1; i++)
                printf("1");
        }
        printf("\n");
    }
    else
    {
        for(int i=0; i<lt; i++)
            if(x>y)
            {
                if(text[i]=='0')
                    text[i]='1';
            }
            else
            {
                if(text[i]=='1')
                    text[i]='0';
            }
        printf("%s\n",text);
    }
    return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
IoT是物联网(Internet of Things)的缩写,是指通过物理设备和传感器等技术将物理世界与互联网连接起来的概念。Sensor是传感器的意思,是一种能够感知和测量周围环境参数的装置。Gym master是指健身房的管理系统。那么,"IoT-Sensor-Gym-Master"指的是结合物联网、传感器技术和健身房管理系统的项目或产品。 在这个项目中,通过在健身房内部部署各种类型的传感器设备,可以实时感知和监控健身房的各种环境参数以及用户的行为。例如,可以使用体感传感器来监测用户的运动状态,心率传感器来监测用户心率变化,温湿度传感器来监测环境的温度和湿度等等。这些传感器会把收集到的数据通过物联网技术传输到云端服务器进行处理和分析。 在云端服务器上,会有一个健身房管理系统,通过对接收到的传感器数据进行分析和处理,可以提供各种健身相关的功能和服务。例如,可以根据用户的运动状态自动调整健身器材的强度,提供个性化的健身方案;还可以通过用户心率数据实时预警和监控用户的身体状况,保证用户的健康安全;同时,还可以通过温湿度传感器来实时监测健身房的环境,保证用户的舒适度。 总之,"IoT-Sensor-Gym-Master"项目结合了物联网、传感器技术和健身房管理系统的优势,将智能化和个性化服务引入健身领域,为用户提供更好的健身体验和管理服务。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值