zoukankan      html  css  js  c++  java
  • Canada Cup 2016 A, B, C

    A. Jumping Ball
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.

    Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position.

    Input

    The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper.

    Output

    Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position.

      题目大意: 一个只包含'<', '>'的数组, 任意选择一个开始的地方如果是'<' 就向左移动一位, 是'>'就向右移动一位, 问有几个开始位置可以使小球最终掉落到地面?

      题目分析: 从反面考虑, 只有"><"会使小球永远不掉到地上, 同时'>'左面的连续的'>'开始也不会掉, 同理右边。 这样问题就是求'><'右面和左面的连续的'>' 和 '<'最后拿n 减 ,还有些细节需要注意。

    题目代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <string>
    using namespace std;
    
    char a[200005];
    int idx[200005];
    
    int main() {
    //    freopen( "in.txt", "r", stdin );
        int n;
        int count;
        int ans;
        while( cin >> n && n ) {
            ans = 0;
            count = 0;
            memset( a, 0, sizeof( a ) );
            memset( idx, 0, sizeof( idx ) );
            for( int i = 1; i <= n; i++ ) {
                cin >> a[i];
                if( a[i] == '<' && a[i-1] == '>' ) {
                    idx[count++] = i;
                    ans += 2;
                }
            }
            for( int i = 0; i < count; i++ ) {
                int left = idx[i] - 1;
                int right = idx[i];
                while( 1 ) {
                    if( a[--left] == '>' ) {
                        ans++;
                    }
                    else break;
                }
                while( 1 ) {
                    if( a[++right] == '<' ) {
                        ans++;
                    }
                    else break;
                }
            }
            cout << n - ans << endl;
        }
        return 0;
    }
    View Code
    B. Food on the Plane
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle.

    It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on.

    Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one — in seat 'c'. Assume that all seats are occupied.

    Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch.

    Input

    The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≤ n ≤ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space.

    Output

    Print one integer — the number of seconds Vasya has to wait until he gets his lunch.

       题目大意: .....解释起来好麻烦的, 就是有一个机舱, 有两个空姐儿提供时候, 他们每个人都推着一辆食物车, 所以他们之间必须隔一行, server1起始在第一行, server2起始在第三行, , server1服务第二行, server2服务第四行, 由于第一二三四行都已经服务完了, 所以server1服务第五行, server2服务第7行, 以此类推。其他一些细节不说了, 最后给出一个旅客的座位号, 问几秒后该旅客可以得到自己的食物?
       题目分析: 注意这里 旅客的行数在1e18, 太大了, 所以一定是推出来的, 首先创造一个map { 'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6 }, 这样以后后面字母的问题就不用考虑了, 主要考虑
    到该行数经过的时间, 有如下关系:
      
            if( ( n - 1 ) % 4 == 0 || ( n - 3 ) % 4 == 0 ) {
                ans += 16 * ( ( n - 1 ) / 4 );
            }
            else if ( ( n - 2 ) % 4 == 0 || n % 4 == 0 ) {
                ans += 16 * ( ( n - 2 ) / 4 ) + 7;
            }    

    附上代码: 

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <map>
    #include <algorithm>
    using namespace std;
    
    map<char, int> MAP;
    
    int main() {
        MAP.insert( make_pair( 'f', 1 ) );
        MAP.insert( make_pair( 'e', 2 ) );
        MAP.insert( make_pair( 'd', 3 ) );
        MAP.insert( make_pair( 'a', 4 ) );
        MAP.insert( make_pair( 'b', 5 ) );
        MAP.insert( make_pair( 'c', 6 ) );
    //    freopen( "in.txt", "r", stdin );
        long long int n;
        char ch;
        long long int ans = 0;
        while( cin >> n >> ch ) {
            ans = 0;
            ans += MAP[ch];
            if( ( n - 1 ) % 4 == 0 || ( n - 3 ) % 4 == 0 ) {
                ans += 16 * ( ( n - 1 ) / 4 );
            }
            else if ( ( n - 2 ) % 4 == 0 || n % 4 == 0 ) {
                ans += 16 * ( ( n - 2 ) / 4 ) + 7;
            }
            cout << ans << endl;
        }
        return 0;
    }
    View Code
    C. Hidden Word
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Let’s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of a grid:

    ABCDEFGHIJKLM
    NOPQRSTUVWXYZ

    We say that two tiles are adjacent if they share a side or a corner. In the example grid above, the tile with the letter 'A' is adjacent only to the tiles with letters 'B', 'N', and 'O'. A tile is not adjacent to itself.

    A sequence of tiles is called a path if each tile in the sequence is adjacent to the tile which follows it (except for the last tile in the sequence, which of course has no successor). In this example, "ABC" is a path, and so is "KXWIHIJK". "MAB" is not a path because 'M' is not adjacent to 'A'. A single tile can be used more than once by a path (though the tile cannot occupy two consecutive places in the path because no tile is adjacent to itself).

    You’re given a string s which consists of 27 upper-case English letters. Each English letter occurs at least once in s. Find a grid that contains a path whose tiles, viewed in the order that the path visits them, form the string s. If there’s no solution, print "Impossible" (without the quotes).

    Input

    The only line of the input contains the string s, consisting of 27 upper-case English letters. Each English letter occurs at least once in s.

    Output

    Output two lines, each consisting of 13 upper-case English characters, representing the rows of the grid. If there are multiple solutions, print any of them. If there is no solution print "Impossible".

    Examples
    input
    ABCDEFGHIJKLMNOPQRSGTUVWXYZ
    output
    YXWVUTGHIJKLM
    ZABCDEFSRQPON
    input
    BUVTYZFQSNRIWOXXGJLKACPEMDH
    output
    Impossible

       题目大意: 啊!!!!这个C题让我非常的蛋疼, 字符串构造题, 这里网上有很多讲的比我好太多的, 但是我还是想谈谈这题自己的想法, 首先输入是27个字符, 这27个字符有26个英文字母,

    有一个重复, 构造一个2 * 13 的字母表, 使得输入的字符串可以构成一个通路。 注意这里只有相邻就可达 , 但是自己和自己不可达。  

       题目分析: 首先考虑不可达的情况, 很容易想到当两个重复的字母相邻的时候就是无解, 这里要先求出两次重现的下标的差, 将差除以2分别放到重复字符的右边(紧贴右边界), 由此可知两个之间的字母一定是两行!!!(因为当相差为1的时候输出无解,所以坐标之差/2一定>= 1!), 然后就简单了, 顺着往前接就行了, 这里就不再赘述了。。。。

      然后代码就不附, 没AC, 有个BUG怎么也解决不了,, , 很惭愧啊, 今天下午看看能不能把把DEF补了。 

      最后说一下感想, 自己还是太弱了, 但是在图书馆写代码开场虚拟赛真的很爽啊!!!!!!

      人一我十, 人十我万!!!!!!

  • 相关阅读:
    TortoiseSVN和VisualSVN-下载地址
    asp.net mvc输出自定义404等错误页面,非302跳转
    IIS7如何显示详细错误信息
    关于IIS7.5下的web.config 404 配置的一些问题
    MVC 错误处理1
    后台获取视图对应的字符串
    HTML5 ArrayBuffer:类型化数组 (二)
    Web 前沿——HTML5 Form Data 对象的使用(转)
    HTML5 File 对象
    HTML5 本地裁剪图片并上传至服务器(转)
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/6007228.html
Copyright © 2011-2022 走看看