zoukankan      html  css  js  c++  java
  • Codeforces Round #372 (Div. 2)

    一下晚自习就急冲冲的跑回家,一二三,电脑,水杯,草稿纸,笔

    熟悉的Linux

    然后第一题

    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 a c 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 if b - a ≤ c, just the new word is appended to other words on the screen. If b - 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 seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 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 integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... < tn ≤ 109), where ti denotes the second when ZS the Coder typed the i-th word.

    Output

    Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.

    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 second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. 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 because 10 - 9 ≤ 1.

    一开始没检查好,居然还错了一次

     1 #include<iostream>
     2 #include<cstdio>
     3 using namespace std;
     4 
     5 int n,c,t1,t2,ans=1;//一开始ans=0,要仔细检查啊!!
     6 
     7 int main()
     8 {
     9     scanf("%d %d",&n,&c);
    10     scanf("%d",&t1);
    11     for(int i=2;i<=n;i++)
    12     {
    13         scanf("%d",&t2);
    14         if(t2-t1<=c)
    15             ans++;
    16         else ans=1;
    17         t1=t2;
    18     }
    19     printf("%d",ans);
    20     return 0;
    21 }
    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 is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, 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 string s (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 with uppercase 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 length 26 (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 as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS.

    In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 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.

    这题不知道为什么只过了6个点,应该是哪里没看懂题目吧

     1 #include<iostream>
     2 #include<string>
     3 #include<cstring>
     4 using namespace std;
     5 
     6 const int INF=0x7fffffff;
     7 string s;
     8 int A[26]={0};
     9 int n,m;
    10 
    11 int main()
    12 {    
    13     cin>>s;
    14     if(s.size()<26)
    15     {
    16         cout<<-1;
    17         return 0;
    18     }
    19     for(int i=0;i<s.size();i++)
    20     {    
    21         if(i>=26) A[s[i-26]]--;
    22         if(s[i]=='?')
    23         {
    24             n=INF;
    25             for(int j=0;j<26;j++)
    26                 if(n>A[j])
    27                 {
    28                     n=A[j];
    29                     m=j;
    30                 }
    31             A[m]++;
    32             s[i]='A'+m;
    33         }
    34         else A[s[i]-'A']++;
    35         if(i>=26&&A[s[i-26]]==0)
    36         {
    37             cout<<-1;
    38             return 0;
    39         }
    40     }
    41     for(int i=0;i<26;i++)
    42         if(A[i]==0)
    43         {
    44             cout<<-1;
    45             return 0;
    46         }
    47     cout<<s;
    48     return 0;
    49 }
    果然是没有理解题目意思
     1 #include<iostream>
     2 #include<cstring>
     3 using namespace std;
     4 
     5 string s;
     6 int A[26];
     7 bool flag,flag2,f=0;
     8 
     9 int main()
    10 {
    11     cin>>s;
    12     if(s.size()<26){cout<<-1;return 0;}
    13     for(int i=0;i<=s.size()-26;i++)
    14     {
    15         memset(A,0,sizeof(A));
    16         for(int j=0;j<26;j++)
    17             if(s[i+j]!='?') A[s[i+j]-'A']++;
    18         flag=0;flag2=0;
    19         for(int j=0;j<26;j++)
    20             if(A[j]>1){flag=1;break;}
    21         if(flag) continue;
    22         for(int j=0;j<26;j++)
    23             if(s[i+j]=='?')
    24                 for(int k=0;k<26;k++)
    25                     if(A[k]==0) 
    26                     {
    27                         s[i+j]='A'+k;
    28                         A[k]++;
    29                         break;
    30                     }
    31         for(int j=0;j<26;j++)
    32             if(A[j]==0){flag2=1;break;}
    33         if(!flag2) f=1;
    34     }
    35     if(!f){cout<<-1;return 0;}
    36     for(int i=0;i<s.size();i++)
    37         cout<<(s[i]=='?'?'A':s[i]);
    38     return 0;
    39 }

     

    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 are n + 1 levels in the game and ZS the Coder start at the level 1.

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

    1. Press the ' + ' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, 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 becomes k + 1. This button can only be pressed when x is a perfect square, i.e. x = m2 for some positive integer m.

    Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.

    ZS the Coder needs your help in beating the game — he wants to reach level n + 1. In other words, he needs to press the '' button ntimes. 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 level n + 1, but not necessarily a sequence minimizing the number of presses.

    Input

    The first and only line of the input contains a single integer n (1 ≤ n ≤ 100 000), denoting that ZS the Coder wants to reach level n + 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 level i.

    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
    Note

    In the first sample case:

    On the first level, ZS the Coder pressed the ' + ' button 14 times (and the number on screen is initially 2), so the number became 2 + 14·1 = 16. Then, ZS the Coder pressed the '' button, and the number became .

    After that, on the second level, ZS pressed the ' + ' button 16 times, so the number becomes 4 + 16·2 = 36. Then, ZS pressed the '' button, levelling up and changing the number into .

    After that, on the third level, ZS pressed the ' + ' button 46 times, so the number becomes 6 + 46·3 = 144. Then, ZS pressed the '' button, levelling up and changing the number into .

    Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.

    Also, note that pressing the ' + ' button 10 times on the third level before levelling up does not work, because the number becomes 6 + 10·3 = 36, and when the '' button is pressed, the number becomes  and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.

    In the second sample case:

    On the first level, ZS the Coder pressed the ' + ' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2 + 999999999999999998·1 = 1018. Then, ZS the Coder pressed the '' button, and the number became 

    After that, on the second level, ZS pressed the ' + ' button 44500000000 times, so the number becomes 109 + 44500000000·2 = 9·1010. Then, ZS pressed the '' button, levelling up and changing the number into 

    Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.

    这题的时候就已经没时间做了,粗略看一下,好像要用到欧几里得算法

    好吧。。。事实证明是找规律

  • 相关阅读:
    【转】Aspose.Cells读取excel文件
    sencha treestore 取消自动加载数据
    百度地图js根据经纬度定位和拖动定位点
    sencha gridpanel checkbox 复选框的勾选 以及和单机行冲突
    c# tcp备忘及networkstream.length此流不支持查找解决
    小程序view排版
    .net+mvc,ueditor
    爬虫BS4—淘女郎
    爬虫手动流程
    python web cgi
  • 原文地址:https://www.cnblogs.com/InWILL/p/5880143.html
Copyright © 2011-2022 走看看