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;
       }
    }

     

  • 相关阅读:
    jython运行python文件
    jython查看帮助help和模块modules
    ubuntu 星际译王3.0.1-9.4隐藏主界面不能打开
    ubuntu火狐(firfox)浏览器安装视频插件
    ubuntu安装mp4播放器vlc & smplayer
    ubuntu+Windows双系统默认引导顺序
    notepad++ 各种颜色调整
    Linux绿色版软件expect
    aix下shell读取脚本文件并逐行执行
    AIX系统常用命令
  • 原文地址:https://www.cnblogs.com/sjhhh/p/11563491.html
Copyright © 2011-2022 走看看