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

     

  • 相关阅读:
    kubernetes集群部署
    centos7通过yum安装mysql,并授权远程连接
    查看mysql主从配置的状态及修正 slave不启动问题
    ios 企业发布
    centos 安装 pip
    前端优化:DNS预解析提升页面速度
    apache mesos 安装
    Oboe 提升web 用户体验以及性能
    webpack 多entry 配置
    webpack es6支持配置
  • 原文地址:https://www.cnblogs.com/sjhhh/p/11563491.html
Copyright © 2011-2022 走看看