zoukankan      html  css  js  c++  java
  • 错误示范1

    http://codeforces.com/problemset/problem/936/D
    D. World of Tank
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vitya loves programming and problem solving, but sometimes, to distract himself a little, he plays computer games. Once he found a new interesting game about tanks, and he liked it so much that he went through almost all levels in one day. Remained only the last level, which was too tricky. Then Vitya remembered that he is a programmer, and wrote a program that helped him to pass this difficult level. Try do the same.

    The game is organized as follows. There is a long road, two cells wide and n cells long. Some cells have obstacles. You control a tank that occupies one cell. Initially, the tank is located before the start of the road, in a cell with coordinates (0, 1). Your task is to move the tank to the end of the road, to the cell (n + 1, 1) or (n + 1, 2).

    Every second the tank moves one cell to the right: the coordinate x is increased by one. When you press the up or down arrow keys, the tank instantly changes the lane, that is, the y coordinate. When you press the spacebar, the tank shoots, and the nearest obstacle along the lane in which the tank rides is instantly destroyed. In order to load a gun, the tank needs t seconds. Initially, the gun is not loaded, that means, the first shot can be made only after t seconds after the tank starts to move.

    If at some point the tank is in the same cell with an obstacle not yet destroyed, it burns out. If you press the arrow exactly at the moment when the tank moves forward, the tank will first move forward, and then change the lane, so it will not be possible to move diagonally.

    Your task is to find out whether it is possible to pass the level, and if possible, to find the order of actions the player need to make.

    Input

    The first line contains four integers n, m1, m2 and t, the length of the field, the number of obstacles in the first lane, the number of obstacles in the second lane and the number of tank steps before reloading, respectively (1 ≤ n ≤ 109; 0 ≤ m1, m2 ≤ n; 0 ≤ m1 + m2 ≤ 106; 1 ≤ t ≤ n).

    The next two lines contain a description of the obstacles. The first of these lines contains m1 numbers xi — the obstacle coordinates in the first lane (1 ≤ xi ≤ n; xi < xi + 1). The y coordinate for all these obstacles will be 1.

    The second line contains m2 numbers describing the obstacles of the second lane in the same format. The y coordinate of all these obstacles will be 2.

    Output

    In the first line print «Yes», if it is possible to pass the level, or «No», otherwise.

    If it is possible, then in the second line print the number of times the tank moves from one lane to another, and in the next line print the coordinates of the transitions, one number per transition: the coordinate x (0 ≤ x ≤ n + 1). All transition coordinates coordinates must be distinct and should be output in strictly increasing order.The number of transitions should not exceed 2·106. If the tank can pass the level, then it can do it using no more than 2·106 transitions.

    In the fourth line print the number of shots that the tank makes during the movement, in the following lines print two numbers, x and y coordinates of the point (1 ≤ x ≤ n, 1 ≤ y ≤ 2), from which the tank fired a shot, the number of shots must not exceed m1 + m2. Shots must be output in the order in which they are fired.

    If there are several solutions, output any one.

    Examples
    Input
    Copy
    6 2 3 2
    2 6
    3 5 6
    Output
    Yes
    2
    0 3
    2
    2 2
    4 1
    Input
    Copy
    1 1 1 1
    1
    1
    Output
    No
    Input
    Copy
    9 5 2 5
    1 2 7 8 9
    4 6
    Output
    Yes
    4
    0 3 5 10
    1
    5 2
    Note

    Picture for the first sample test.

    #include<iostream>
    #include<deque>
    #include<cstring>
    #include<cstdio>
    using namespace std;
    typedef long long ll;
    struct pos
    {
        int x;
        int y;
    };
    int a[3][100005];
    ll n,t,T;
    deque<int>swi;
    deque<pos>sho;
    void dfs(int x,int y)
    {
        ll i,k;
        if(y>n)
        {
            printf("Yes
    ");
            cout<<swi.size()<<endl;
            while(!swi.empty())
            {
                printf("%d ",swi.front());
                swi.pop_front();
            }
            printf("
    %d
    ",sho.size());
            while(!sho.empty())
            {
                printf("%d %d
    ",sho.front().y,sho.front().x);
                sho.pop_front();
            }
            exit(0);
        }
        else
        {
            if(y>=T)
            {
                k=T;
                T=y+t;
                for(i=y+1;!a[x][i];i++);
                a[x][i]=0;
                sho.push_back(pos{x,y});
                dfs(x,y);
                T=k;
                sho.pop_back();
                a[x][i]=1;
            }
            if(y==0&&swi.empty())
            {
                swi.push_back(0);
                dfs(2,0);
                swi.pop_back();
            }
            else if(y!=swi.back()&&!a[3-x][y])
            {
                swi.push_back(y);
                dfs(3-x,y);
                swi.pop_back();
            }
            if(!a[x][y+1])dfs(x,y+1);
        }
    }
    int main()
    {
        int m1,m2;
        ll m;
        cin>>n>>m1>>m2>>t;
        T=t;
        memset(a,0,sizeof(a));
        while(m1--)
        {
            cin>>m;
            a[1][m]=1;
        }
        while(m2--)
        {
            cin>>m;
            a[2][m]=2;
        }
        dfs(1,0);
        printf("No");
        return 0;
    }
  • 相关阅读:
    jQuery——能够编辑的表格
    最简单的Windows程序
    数据库分页查询
    Srvctl命令具体解释(10g)
    AT3912 Antennas on Tree
    使用GenericServlet实例
    Servlet接口、GenericServlet类、HttpServlet类
    Servlet简介
    MVC
    为JSP写的一套核心标签
  • 原文地址:https://www.cnblogs.com/sphreez/p/8613046.html
Copyright © 2011-2022 走看看