zoukankan      html  css  js  c++  java
  • Toj Dominoes Game

     Dominoes Game

    描述

    Recently, my lovely daughter YuYu indulges in playing a game called dominoes. When the game starts, I first place some blocks with varying heights in a long row. I told her that she can select only one of them and topple it to fall either left or right. If the falling block hits another one, it will cause it to fall over too (if the top of a falling block just touches the bottom of another one, that block still stays standing). YuYu is so gready that she wants to knock over as many blocks as possible. Now, your task is to write a program and help YuYu to find the maximum number of blocks she can knock over.

    输入

    There will be multiple test cases. Each test case starts with an integer n indicating the number of blocks.
    The next line contains n(1<=n<=10000) pairs of integers. Each pair, x h, indicates the position x of a block of height h (x>=0, h>0 and all numbers will be no larger than 32767).
    You must help YuYu to select the block to initially knock over (and in what direction) so as to knock over as many blocks as possible.
    Input will terminate with an integer 0 on a line.

    输出

    For each input test case, output a line containing an integer m indicating the maximum number of blocks that can be knocked over.

    样例输入

     

    2
    0 2 3 3
    3
    1 2 2 3 3 2
    0

    样例输出

     

    1
    3

    // 可以跨着推倒 1 1 3 1 5 5 的话虽然3 1 不能推倒 1 1 但是5 5可以所以结果应该是3

    所以只要现在牌的高度=max(前一个牌的高度减去前一个牌到现在牌的距离),(现在牌的高度)就可以了因为有正推和反推所以用两个数组避免影响。

    #include<bits/stdc++.h>
    using namespace std;
    struct jilu
    {
        int x,h;
    }node[10001],node1[10001];
    
    bool cmp(jilu a,jilu b)
    {
        return a.x<b.x;
    }
    int main()
    {
       std::ios::sync_with_stdio(false);
       int n;
       while(cin>>n)
       {
           if(n==0)break;
           int max1=1;
           for(int i=0;i<n;i++)
           {
            cin>>node[i].x>>node[i].h;
            node1[i].x=node[i].x;
            node1[i].h=node[i].h;
           }
            sort(node,node+n,cmp);
            sort(node1,node1+n,cmp);
          int sum=1;
           for(int i=1;i<n;i++)
           {
               if(node[i].x-node[i-1].x<node[i-1].h)
               {
                   sum++;
                   node[i].h=max(node[i-1].h-(node[i].x-node[i-1].x),node[i].h);
               }
    
               else
                sum=1;
               if(sum>max1)
                    max1=sum;
           }
           sum=1;
            for(int i=n-1;i>0;i--)
           {
               if(node1[i].x-node1[i-1].x<node1[i].h)
               {
                  sum++;
                  node1[i-1].h=max(node1[i].h-(node1[i].x-node1[i-1].x),node1[i-1].h);
               }
               else
                sum=1;
               if(sum>max1)
                    max1=sum;
           }
           cout<<max1<<endl;
       }
    }

     

  • 相关阅读:
    readelf的使用,看函数地址
    Linux 打印堆栈和crash地址转换
    Android mk 添加打印信息
    Linux make file文件中常用的一些定义CPP CXX
    关于Android中RemoveView的错误理解
    Android悬浮窗注意事项
    在有EditText控件的AlertDialog对话框中自动弹出输入法
    联系旭日150安装CentOS5.X版本手记
    ListView配合CheckBox出现position位置错误的解决
    在Android中让Preference的宽度占满整个屏幕的宽度
  • 原文地址:https://www.cnblogs.com/sjhhh/p/11563491.html
Copyright © 2011-2022 走看看