Codeforces Round #372 (Div. 2)


A. Crazy Computer
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

ZS the Coder is coding on a crazy computer. If you don't type in a word for ac consecutive seconds, everything you typed disappear!

More formally, if you typed a word at second a and then the next word at second b, then ifb - a ≤ c, just the new word is appended to other words on the screen. Ifb - a > c, then everything on the screen disappears and after that the word you have typed appears on the screen.

For example, if c = 5 and you typed words at seconds1, 3, 8, 14, 19, 20 then at the second8 there will be 3 words on the screen. After that, everything disappears at the second13 because nothing was typed. At the seconds14 and 19 another two words are typed, and finally, at the second20, one more word is typed, and a total of3 words remain on the screen.

You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.

Input

The first line contains two integers n and c (1 ≤ n ≤ 100 000, 1 ≤ c ≤ 109) — the number of words ZS the Coder typed and the crazy computer delay respectively.

The next line contains n integerst1, t2, ..., tn (1 ≤ t1 < t2 < ... < tn ≤ 109), whereti denotes the second when ZS the Coder typed thei-th word.

Output

Print a single positive integer, the number of words that remain on the screen after alln words was typed, in other words, at the secondtn.

Examples
Input
6 5
1 3 8 14 19 20
Output
3
Input
6 1
1 3 5 7 9 10
Output
2
Note

The first sample is already explained in the problem statement.

For the second sample, after typing the first word at the second1, it disappears because the next word is typed at the second3 and3 - 1 > 1. Similarly, only1 word will remain at the second9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because10 - 9 ≤ 1.

题意:

给你n个数和一个c值,如果后一个数减前一个数的值<=c,ans++.否则ans重新初始化为1.输出ans。

题解:理解题意后就是个模拟题

代码:


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mx=1e5;
int a[mx];
int main()
{
    int n,m;
    cin>>n>>m;
    int ans=1;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=2;i<=n;i++)
    {
        if(a[i]-a[i-1]<=m)
            ans++;
        else
            ans=1;
    }
    cout<<ans<<endl;
}

B. Complete the Word
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

ZS the Coder loves to read the dictionary. He thinks that a word isnice if there exists asubstring (contiguous segment of letters) of it of length26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than26, no such substring exists and thus it is not nice.

Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him?

Input

The first and only line of the input contains a single strings (1 ≤ |s| ≤ 50 000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember.

Output

If there is no way to replace all the question marks withuppercase letters such that the resulting word is nice, then print - 1 in the only line.

Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters.

If there are multiple solutions, you may print any of them.

Examples
Input
ABC??FGHIJK???OPQR?TUVWXY?
Output
ABCDEFGHIJKLMNOPQRZTUVWXYS
Input
WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO
Output
-1
Input
??????????????????????????
Output
MNBVCXZLKJHGFDSAQPWOEIRUYT
Input
AABCDEFGHIJKLMNOPQRSTUVW??M
Output
-1
Note

In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such asABCDEFGHIJKLMNOPQRSTUVWXYZ orABCEDFGHIJKLMNOPQRZTUVWXYS.

In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length26 that contains all the letters of the alphabet, so the answer is - 1.

In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.

题意:给你一个字符串(由大写字母和问号组成),问你是否存在一个长度为26的子串并且这个子串包含了所有的大写字母,?可以替换成任意大写字母。

题解:

从头开始遍历,每次拿出一个长度为26的子串,如果子串内不同大写字母的数量加上问号的数量为26的话,输出即可。

如果存在这样的子串,将母串内除子串内的问号变成‘A',子串内的问号变成相应字母。没有输出-1。

代码:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int v[50020];
char a[50020];
void print(int x)
{
    for(int i=0;i<x;i++)
    {
        if(a[i]=='?')
            a[i]='A';
    }
   printf("%s\n",a);
}
int main()
{
    scanf("%s",a);
       int flag=0;
    int len=strlen(a);
    if(len<26)
    {
        cout<<-1<<endl;
        return 0;
    }
    else
    {
        int tmp=0;
        memset(v,0,sizeof(v));
        for(int i=0; i<26; i++)
        {
            if(a[i]=='?')
                tmp++;
            else
            {
            if(v[a[i]-'A']==0)
            {
                tmp++;
            }
                v[a[i]-'A']++;
            }
        }
        if(tmp==26)
        {
            int cur=0;
            while(v[cur])
                cur++;
            for(int i=0; i<26; i++)
            {
                if(a[i]=='?')
                {
                    a[i]='A'+cur;
                cur++;
                while(v[cur])
                    cur++;
                }
            }
            print(len);
            return 0;
        }
        else
        {
            for(int i=26; i<len; i++)
            {
                if(a[i-26]=='?')
                    tmp--;
                if(a[i]=='?')
                    tmp++;
                if(a[i-26]!='?')
                {
                    v[a[i-26]-'A']--;
                    if(v[a[i-26]-'A']==0)
                        tmp--;
                }
                if(a[i]!='?')
                {
                    v[a[i]-'A']++;
                    if(v[a[i]-'A']==1)
                        tmp++;
                }
                if(tmp==26)
                {
                        int cur=0;
                        while(v[cur])
                            cur++;
                        for(int j=i-25; j<=i; j++)
                        {
                            if(a[j]=='?')
                            {

                                a[j]='A'+cur;
                                cur++;
                            while(v[cur])
                                cur++;
                            }
                        }
                        print(len);
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(!flag)
            cout<<-1<<endl;
}

C. Plus and Square Root
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There aren + 1 levels in the game and ZS the Coder start at the level1.

When ZS the Coder is at level k, he can :

  1. Press the ' + ' button. This increases the number on the screen by exactlyk. So, if the number on the screen wasx, it becomes x + k.
  2. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes. After that, ZS the Coder levels up, so his current level becomesk + 1. This button can only be pressed whenx is aperfect square, i.e.x = m2 for some positive integerm.

Additionally, after each move, if ZS the Coder is at levelk, and the number on the screen ism, then m must be a multiple ofk. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level4 and current number is100, he presses the '' button and the number turns into 10. Note that at this moment,10 is not divisible by4, but this press is still valid, because after it, ZS the Coder is at level5, and10 is divisible by5.

ZS the Coder needs your help in beating the game — he wants to reach leveln + 1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the ' + ' button before pressing the '' button at each level.

Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach leveln + 1, but not necessarily a sequence minimizing the number of presses.

Input

The first and only line of the input contains a single integern (1 ≤ n ≤ 100 000), denoting that ZS the Coder wants to reach leveln + 1.

Output

Print n non-negative integers, one per line.i-th of them should be equal to the number of times that ZS the Coder needs to press the ' + ' button before pressing the '' button at leveli.

Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018.

It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.

Examples
Input
3
Output
14
16
46
Input
2
Output
999999999999999998
44500000000
Input
4
Output
2
17
46
97

题意:  你的基础分为两分,等级为1,你有两个操作,一:加上k*等级的分,二:将你的分开根号,结果必须为你下一个等级的倍数,然后你等级+1,给出一个数n,问你最终晋级到n+1,每次晋级需要的k是多少。

题解:这里我不明前两个样例是什么鬼,但第三个样例很好,我们模拟一下过程你就会发现规律了,

等级1——>等级2:    2(初始分)+ 2(k)*1(等级)=4,sqrt(4)=2,2是2的1倍。

等级2——>等级3:    2(初始分)+ 17(k)*2(等级)=36,sqrt(36)=6,6是3的2倍。

等级3——>等级4:    6(初始分)+ 46 (k)*3(等级)=144,sqrt(144)=12,12是4的3倍。

等级4——>等级5:   12(初始分)+97(k)*4(等级)=400,sqrt(400)=20,20是5的4倍。

。。。。。

我们假设当前等级为i,则sqrt(x)=i*(i+1),x=(i*(i+1))^2,  每次初始分/当前等级==i-1, 所以k等于 x/i -(i+1)。

带入发现除了1不满足,其他都可以,所以特判1,

代码;

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n;
    cin>>n;
    cout<<2<<endl;
    for(ll i=2;i<=n;i++)
    {
        cout<<i*(i+1)*(i+1)-i+1<<endl;
    }

}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值