zoukankan      html  css  js  c++  java
  • Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)

    A. Broken Clock
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.

    You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.

    For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.

    Input

    The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.

    The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.

    Output

    The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.

    Examples
    input
    24
    17:30
    output
    17:30
    input
    12
    17:30
    output
    07:30
    input
    24
    99:99
    output
    09:09

    这么一道水题,我写的什么烂代码。。。

     1 #include<iostream>
     2 using namespace std;
     3 
     4 int n;
     5 int a,b;
     6 
     7 int main()
     8 {
     9     cin>>n;
    10     scanf("%d:%d",&a,&b);
    11     if(n==12)
    12     {
    13         if(a==0)cout<<"10:";
    14         else
    15         if(0<=a&&a<10)
    16             cout<<"0"<<a%10<<':';
    17         else
    18         if(a>12)
    19         {
    20             if(a%10==0)
    21                 cout<<"10:";
    22             else cout<<'0'<<a%10<<':';
    23         }
    24         else cout<<a<<':';
    25         if(0<=b&&b<10) cout<<"0"<<b%10;
    26         else
    27         if(b>=60)
    28             cout<<'0'<<b%10;
    29         else cout<<b;
    30     }
    31     if(n==24)
    32     {
    33         if(0<=a&&a<10)
    34             cout<<"0"<<a%10<<':';
    35         else
    36         if(a>=24)
    37         {
    38             if(a%10==0)
    39                 cout<<"10:";
    40             else cout<<'0'<<a%10<<':';
    41         }
    42         else cout<<a<<':';
    43         if(0<=b&&b<10) cout<<"0"<<b%10;
    44         else
    45         if(b>=60)
    46             cout<<'0'<<b%10;
    47         else cout<<b;
    48     }
    49     return 0;
    50 }
    B. Verse Pattern
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters.

    We define a syllable as a string that contains exactly one vowel any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels: 'a', 'e', 'i', 'o', 'u' and 'y'.

    Each word of the text that contains at least one vowel can be divided into syllables. Each character should be a part of exactly one syllable. For example, the word "mamma" can be divided into syllables as "ma" and "mma", "mam" and "ma", and "mamm" and "a". Words that consist of only consonants should be ignored.

    The verse patterns for the given text is a sequence of n integers p1, p2, ..., pn. Text matches the given verse pattern if for each i from 1 to n one can divide words of the i-th line in syllables in such a way that the total number of syllables is equal to pi.

    You are given the text and the verse pattern. Check, if the given text matches the given verse pattern.

    Input

    The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of lines in the text.

    The second line contains integers p1, ..., pn (0 ≤ pi ≤ 100) — the verse pattern.

    Next n lines contain the text itself. Text consists of lowercase English letters and spaces. It's guaranteed that all lines are non-empty, each line starts and ends with a letter and words are separated by exactly one space. The length of each line doesn't exceed 100 characters.

    Output

    If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).

    Examples
    input
    3
    2 2 3
    intel
    code
    ch allenge
    output
    YES
    input
    4
    1 2 3 1
    a
    bcdefghi
    jklmnopqrstu
    vwxyz
    output
    NO
    input
    4
    13 11 15 15
    to be or not to be that is the question
    whether tis nobler in the mind to suffer
    the slings and arrows of outrageous fortune
    or to take arms against a sea of troubles
    output
    YES
    Note

    In the first sample, one can split words into syllables in the following way:

    in-tel
    co-de
    ch al-len-ge

    Since the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3syllables in the third one.

    简单的字符计数,一遍过

     1 #include<iostream>
     2 #include<string>
     3 using namespace std;
     4 
     5 int n;
     6 int P[101];
     7 char S[6]={'a','e','i','o','u','y'};
     8 string s;
     9 
    10 int main()
    11 {
    12     cin>>n;
    13     for(int i=1;i<=n;i++)
    14         cin>>P[i];
    15     cin.ignore(1);
    16     for(int i=1;i<=n;i++)
    17     {
    18         int num=0;
    19         getline(cin,s);
    20         for(int j=0;j<s.size();j++)
    21             for(int k=0;k<6;k++)
    22                 if(s[j]==S[k])
    23                 {
    24                     num++;break;
    25                 }
    26         if(num!=P[i])
    27         {
    28             cout<<"NO";
    29             return 0;
    30         }
    31     }
    32     cout<<"YES";
    33     return 0;
    34 }
    C. Destroying Array
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given an array consisting of n non-negative integers a1, a2, ..., an.

    You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to n defining the order elements of the array are destroyed.

    After each element is destroyed you have to find out the segment of the array, such that it contains no destroyed elements and the sum of its elements is maximum possible. The sum of elements in the empty segment is considered to be 0.

    Input

    The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the length of the array.

    The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).

    The third line contains a permutation of integers from 1 to n — the order used to destroy elements.

    Output

    Print n lines. The i-th line should contain a single integer — the maximum possible sum of elements on the segment containing no destroyed elements, after first i operations are performed.

    Examples
    input
    4
    1 3 2 5
    3 4 1 2
    output
    5
    4
    3
    0
    input
    5
    1 2 3 4 5
    4 2 3 5 1
    output
    6
    5
    5
    1
    0
    input
    8
    5 5 4 4 6 6 5 5
    5 2 8 7 1 3 4 6
    output
    18
    16
    11
    8
    8
    6
    6
    0
    Note

    Consider the first sample:

    1. Third element is destroyed. Array is now 1 3  *  5. Segment with maximum sum 5 consists of one integer 5.
    2. Fourth element is destroyed. Array is now 1 3  *   * . Segment with maximum sum 4 consists of two integers 1 3.
    3. First element is destroyed. Array is now  *  3  *   * . Segment with maximum sum 3 consists of one integer 3.
    4. Last element is destroyed. At this moment there are no valid nonempty segments left in this array, so the answer is equal to 0.

     这题仍需优化,超时了。。。

     1 #include<iostream>
     2 #include<algorithm>
     3 using namespace std;
     4 
     5 int n;
     6 long long T[100001]={0},F[100001]={0},DP[100001]={0};
     7 long long ans=0;
     8 
     9 int main()
    10 {
    11     cin>>n;
    12     for(int i=1;i<=n;i++)
    13     {
    14         cin>>T[i];
    15         DP[i]=DP[i-1];
    16         DP[i]+=T[i];
    17     }
    18     for(int i=1;i<=n;i++)
    19     {
    20         cin>>F[i-1];
    21         T[F[i-1]]=-1;
    22         sort(F,F+i);
    23         ans=0;
    24         for(int j=0;j<i;j++)
    25             ans=max(ans,DP[F[j]-1]-DP[F[j-1]]);
    26         cout<<max(ans,DP[n]-DP[F[i-1]])<<endl;
    27     }
    28     return 0;
    29 }
  • 相关阅读:
    了解java注解
    使用java泛型设计通用方法
    dbutils基本使用
    jquery+ajax+struts2
    c3p0连接数据库的3种方式
    ASP单步调试工具
    设置网页图片不能被用户下载或者另存为
    简单树形菜单
    GBK,GB3212 Unicode编码问题详解
    html页面乱码问题解决方法编码批量转换
  • 原文地址:https://www.cnblogs.com/InWILL/p/5927351.html
Copyright © 2011-2022 走看看