其他分享
首页 > 其他分享> > 10.9-10.10补题报告

10.9-10.10补题报告

作者:互联网

10.9

B - A Tide of Riverscape

Walking along a riverside, Mino silently takes a note of something.

"Time," Mino thinks aloud.

"What?"

"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."

"And what are you recording?"

"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.

Doubtfully, Kanno peeks at Mino's records.

The records are expressed as a string ss of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).

You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer pp is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.

In this problem, a positive integer pp is considered a period of string ss, if for all 1≤i≤|s|−p1≤i≤|s|−p, the ii-th and (i+p)(i+p)-th characters of ss are the same. Here |s||s| is the length of ss.

Input

The first line contains two space-separated integers nn and pp (1≤p≤n≤20001≤p≤n≤2000) — the length of the given string and the supposed period, respectively.

The second line contains a string ss of nn characters — Mino's records. ss only contains characters '0', '1' and '.', and contains at least one '.' character.

Output

Output one line — if it's possible that pp is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).

Examples

Input
10 7
1.0.1.0.1.
Output
1000100010
Input
10 6
1.0.1.1000
Output
1001101000
Input
10 9
1........1
Output
No

Note

In the first example, 77 is not a period of the resulting string because the 11-st and 88-th characters of it are different.

In the second example, 66 is not a period of the resulting string because the 44-th and 1010-th characters of it are different.

In the third example, 99 is always a period because the only constraint that the first and last characters are the same is already satisfied.

Note that there are multiple acceptable answers for the first two examples, you can print any of them.

解题思路:输入一串字符只有01'.',点字符可以改变成0或者1,判断第i个和i+p个字符是否可以不相等。

先将所有'.'字符变为字符0或1,然后判断i和i+p和i和i-p的字符是否一样,一样就换成0或1中的另一个字符。

再判断第i个和i+p个字符是否相等即可。

ac代码:

#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstring>
using namespace std;
int main(){
    int n,p,i,m,k;
    cin>>n>>p;
    char s[2005];
    cin>>s;
    m=strlen(s);
    k=0;
    for(i=0;i<m;i++){
        if(s[i]=='.'){
            s[i]='0';
            if(i+p<n&&s[i+p]=='0'||i-p>=0&&s[i-p]=='0')
                s[i]='1';
        }
    }
    for(i=0;i<m-p;i++){
        int jj=i+p;
        if(s[i]==s[jj]){
            continue;
        }
        else{
            k=1;
            break;
        }
    }
    if(k==1){
        for(i=0;i<m;i++){    
            cout<<s[i];    
        }
        cout<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}
View Code

 

E - High School: Become Human

Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.

It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-class android which is produced by a little-known company. His design is not perfect, his characteristics also could be better. So he is bullied by other androids.

One of the popular pranks on Vasya is to force him to compare xyxy with yxyx. Other androids can do it in milliseconds while Vasya's memory is too small to store such big numbers.

Please help Vasya! Write a fast program to compare xyxy with yxyx for Vasya, maybe then other androids will respect him.

Input

On the only line of input there are two integers xx and yy (1≤x,y≤1091≤x,y≤109).

Output

If xy<yxxy<yx, then print '<' (without quotes). If xy>yxxy>yx, then print '>' (without quotes). If xy=yxxy=yx, then print '=' (without quotes).

Examples

Input
5 8
Output
>
Input
10 3
Output
<
Input
6 6
Output
=

Note

In the first example 58=5⋅5⋅5⋅5⋅5⋅5⋅5⋅5=39062558=5⋅5⋅5⋅5⋅5⋅5⋅5⋅5=390625, and 85=8⋅8⋅8⋅8⋅8=3276885=8⋅8⋅8⋅8⋅8=32768. So you should print '>'.

In the second example 103=1000<310=59049103=1000<310=59049.

In the third example 66=46656=6666=46656=66.

解题思路:判断x^y与y^x谁大。题目给的数据较大,将指数运算转换成对数运算。

用作差法来比较两个小数的大小,如果两数之差的绝对值小于或等于一个非常小的精度值eps(如1e-8或者1e-9),一般默认它们是相等的。

ac代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
    double x,y,m,n;
    cin>>x>>y;
    m=y*log10(x);
    n=x*log10(y);
    if(abs(m-n)<=1e-8){
        cout<<"="<<endl;
    }
    else if(m>n){
        cout<<">"<<endl;
    }
    else{
        cout<<"<"<<endl;
    }
    return 0;
} 
View Code

 

10.10

7-3 N个数求和 (20分)  

本题的要求很简单,就是求N个数字的和。麻烦的是,这些数字是以有理数分子/分母的形式给出的,你输出的和也必须是有理数的形式。

输入格式:

输入第一行给出一个正整数N(≤100)。随后一行按格式a1/b1 a2/b2 ...给出N个有理数。题目保证所有分子和分母都在长整型范围内。另外,负数的符号一定出现在分子前面。

输出格式:

输出上述数字和的最简形式 —— 即将结果写成整数部分 分数部分,其中分数部分写成分子/分母,要求分子小于分母,且它们没有公因子。如果结果的整数部分为0,则只输出分数部分。

输入样例1:

5
2/5 4/15 1/30 -2/60 8/3
 

输出样例1:

3 1/3
 

输入样例2:

2
4/3 2/3
 

输出样例2:

2
 

输入样例3:

3
1/3 -1/6 1/8
 

输出样例3:

7/24
ac代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long int gcd(long long a,long long b)
{
    if(a==0)
    {
        return 0;
    }
    else
    {
        return(b== 0)?a:gcd(b,a % b);
    }
}
int main()
{
    int n;
    long long int l;
    long long int a,b,c,d;
    scanf("%d",&n);
    scanf("%lld/%lld",&a,&b);
    int t=gcd(a,b);
    if(a)
    {
        a/=t;
        b/=t;
    }
    int i=1;
    while (i<n)
    {
        scanf("%lld/%lld",&c,&d);
        l= b / gcd(b,d) * d;
        a = a*l/b+c*l/d;
        b = l;
        int t = gcd(a,b);
        if(t != 0)
        {
            a=a/t;
            b=b/t;
        }
         i++;
    }
    if(a&&a/b==0)
        printf("%lld/%lld\n",a%b,b);
    else if(a%b==0)
        printf("%lld\n",a/b);
    else
        printf("%lld %lld/%lld\n",a/b,a%b,b);
    return 0;
}
View Code

 



标签:string,10.9,long,int,补题,Output,10.10,include,Input
来源: https://www.cnblogs.com/nanan/p/13835965.html