zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 12

                        A. Buses Between Cities
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Buses run between the cities A and B, the first one is at 05:00 AM and the last one departs not later than at 11:59 PM. A bus from the city Adeparts every a minutes and arrives to the city B in a ta minutes, and a bus from the city B departs every b minutes and arrives to the city Ain a tb minutes.

    The driver Simion wants to make his job diverse, so he counts the buses going towards him. Simion doesn't count the buses he meet at the start and finish.

    You know the time when Simion departed from the city A to the city B. Calculate the number of buses Simion will meet to be sure in his counting.

    Input

    The first line contains two integers a, ta (1 ≤ a, ta ≤ 120) — the frequency of the buses from the city A to the city B and the travel time. Both values are given in minutes.

    The second line contains two integers b, tb (1 ≤ b, tb ≤ 120) — the frequency of the buses from the city B to the city A and the travel time. Both values are given in minutes.

    The last line contains the departure time of Simion from the city A in the format hh:mm. It is guaranteed that there are a bus from the city Aat that time. Note that the hours and the minutes are given with exactly two digits.

    Output

    Print the only integer z — the number of buses Simion will meet on the way. Note that you should not count the encounters in cities A and B.

    Examples
    input
    10 30
    10 35
    05:20
    output
    5
    input
    60 120
    24 100
    13:00
    output
    9
    Note

    In the first example Simion departs form the city A at 05:20 AM and arrives to the city B at 05:50 AM. He will meet the first 5 buses from the city B that departed in the period [05:00 AM - 05:40 AM]. Also Simion will meet a bus in the city B at 05:50 AM, but he will not count it.

    Also note that the first encounter will be between 05:26 AM and 05:27 AM (if we suggest that the buses are go with the sustained speed

    题意:在A地每a分钟就有一辆车出发,经过ta分钟到达B地,在B地则每b分钟有一辆车出发,经过tb分钟到达A地。发车时间限制为早上5:00到晚上11:59。Simion在hh:mm从A地上了一辆车,问他在车上可以遇见多少辆从B地开往A地的车,当他处于A地或者B地时遇见的不计。

    题解:见代码注释。

     1 /*A*/
     2 #include<cstdio>
     3 #include<cstring>
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     int a,ta;
     9     int b,tb;
    10     int h,m;
    11     while(scanf("%d%d%d%d %d:%d",&a,&ta,&b,&tb,&h,&m)!=EOF)
    12     {
    13         int time=h*60+m;/*把时:分转化*/
    14         int ans=0;
    15         int star,end;/*B地发车的时间和到达A的时间*/
    16         for(int i=0;;i++)/*从5:00开始模拟B地发车*/
    17         {
    18             star=300+i*b;
    19             end=star+tb;
    20             if(star>=(time+ta))/*当Simion的车已经到达B地时就退出*/
    21                 break;
    22             if(star>=1440)/*发车时间超过晚上十二点也退出*/
    23                 break;
    24             if(end<=time)/*如果B地发的车到A地时,Simion还没有上车则继续 */
    25                 continue;
    26             if(end>time||star<(time+ta))/*满足条件则计数*/
    27                 ans++;
    28             
    29             
    30         }
    31         printf("%d
    ",ans);
    32     }
    33     return 0;
    34 }
    View Code

                            B. Shopping

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online.

    The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in thei-th person's order.

    Due to the space limitations all the items are arranged in one single row. When Ayush receives the i-th order he will find one by one all the items aij (1 ≤ j ≤ m) in the row. Let pos(x) denote the position of the item x in the row at the moment of its collection. Then Ayush takes time equal to pos(ai1) + pos(ai2) + ... + pos(aim) for the i-th customer.

    When Ayush accesses the x-th element he keeps a new stock in the front of the row and takes away the x-th element. Thus the values are updating.

    Your task is to calculate the total time it takes for Ayush to process all the orders.

    You can assume that the market has endless stock.

    Input

    The first line contains three integers n, m and k (1 ≤ n, k ≤ 100, 1 ≤ m ≤ k) — the number of users, the number of items each user wants to buy and the total number of items at the market.

    The next line contains k distinct integers pl (1 ≤ pl ≤ k) denoting the initial positions of the items in the store. The items are numbered with integers from 1 to k.

    Each of the next n lines contains m distinct integers aij (1 ≤ aij ≤ k) — the order of the i-th person.

    Output

    Print the only integer t — the total time needed for Ayush to process all the orders.

    Example
    input
    2 2 5
    3 4 1 2 5
    1 5
    3 1
    output
    14
    Note

    Customer 1 wants the items 1 and 5.

    pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5].

    pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2].

    Time taken for the first customer is 3 + 5 = 8.

    Customer 2 wants the items 3 and 1.

    pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2].

    pos(1) = 3, so the new positions are: [1, 3, 5, 4, 2].

    Time taken for the second customer is 3 + 3 = 6.

    Total time is 8 + 6 = 14.

    Formally pos(x) is the index of x in the current row.

    题意:有n个顾客,每个顾客要买m件商品,仓库有k件商品,并且商品是以队列的形式存放的。售货员依次接待每一个顾客,他会将顾客需要的商品依次放到队列的最前面来,每个商品需要处理的时间就是它的位置。现在问售货员接待这些顾客需要多久的时间。

    题解:直接模拟。将每个商品与前一个商品交换,交换的次数+1就是它的位置。

     1 /*B*/
     2 #include<cstdio>
     3 #include<cstring>
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     int n,m,k;
     9     int a[100+10];
    10     while(scanf("%d%d%d",&n,&m,&k)!=EOF)
    11     {
    12         memset(a,0,sizeof(a));
    13         for(int i=0;i<k;i++)
    14             scanf("%d",&a[i]);
    15         int b[100+10];
    16         int ans=0;
    17         while(n--)
    18         {
    19             memset(b,0,sizeof(b));
    20             for(int i=0;i<m;i++)
    21                 scanf("%d",&b[i]);
    22             for(int i=0;i<m;i++)/*依次接待每一个顾客*/
    23             {
    24                 for(int j=0;j<k;j++)/*处理他们的每件商品*/
    25                 {
    26                     if(a[j]==b[i])/*在库存中寻找*/
    27                     {
    28                         int p=j;
    29                         while(1)/*找到就开始交换*/
    30                         {
    31                             if(a[0]==b[i])/*当需要的商品在第一个时就退出*/
    32                                 break;
    33                             int t=a[p];
    34                             a[p]=a[p-1];
    35                             a[p-1]=t;
    36                             p--;
    37                             ans++;
    38                         }
    39                         ans++;/*所在的位置是交换的次数+1*/
    40                     }
    41                 }
    42             }
    43         }
    44         printf("%d
    ",ans);
    45     }
    46     return 0;
    47 }
    View Code
                            C. Simple Strings
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    zscoder loves simple strings! A string t is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoderare simple whereas aa, add are not simple.

    zscoder is given a string s. He wants to change a minimum number of characters so that the string s becomes simple. Help him with this task!

    Input

    The only line contains the string s (1 ≤ |s| ≤ 2·105) — the string given to zscoder. The string s consists of only lowercase English letters.

    Output

    Print the simple string s' — the string s after the minimal number of changes. If there are multiple solutions, you may output any of them.

    Note that the string s' should also consist of only lowercase English letters.

    Examples
    input
    aab
    output
    bab
    input
    caaab
    output
    cabab
    input
    zscoder
    output
    zscoder

    题意:如果一个字符串中有连续的字符相同,那么用其他的字符代替它(小写仅限字母)。
    题解:从前往后扫一遍,如果发现两个字符相同,那么就更改第二个,我是把它+1,这样的话需要特别处理一下y和z,因为他们+2或者+2后就不是小写字符啦(成功hack一人,哈哈哈!)
    看别人写的代码时有点人是直接只用a,b,c三个字母来代替那些重复的字符。
     1 /*C*/
     2 #include<cstdio>
     3 #include<cstring>
     4 using namespace std;
     5 
     6 const int maxn=200000+10;
     7 
     8 int main()
     9 {
    10     char s[maxn];
    11     while(scanf("%s",s)!=EOF)
    12     {
    13         int len=strlen(s);
    14         for(int i=0;i<len;i++)
    15         {
    16             if(s[i]==s[i+1])/*发现两个字符相同*/
    17             {
    18                 char t=s[i+1]+1;
    19                 if(s[i+2]==t)/*如果将要用来代替的字母与后一个相同*/
    20                     t++;
    21                 if(t>'z')/*特殊处理*/
    22                 {
    23                     t='a';
    24                     if(s[i+2]==t)
    25                         t++;
    26                 }
    27                 s[i+1]=t;
    28             }
    29         }
    30         printf("%s
    ",s);
    31         memset(s,0,sizeof(s));
    32     }
    33     return 0;
    34 }
    View Code
    
    
    


  • 相关阅读:
    重载与复写的区别
    Linux常用的网络命令
    JAVA帮助文档全系列 JDK1.5 JDK1.6 JDK1.7 官方中英完整版下载
    Java中重载与复写的区别、super与this的比较
    JAVA中extends 与implements区别
    Android控件系列之Button以及Android监听器
    Could not find SDK_Root\tools\adb.exe 的解决方法
    路由知识普及和经验分享
    abort函数
    细说Cookie
  • 原文地址:https://www.cnblogs.com/yepiaoling/p/5422897.html
Copyright © 2011-2022 走看看