设为首页 加入收藏

TOP

CodeForces 520D Cubes
2015-07-20 17:14:06 来源: 作者: 【 】 浏览:2
Tags:CodeForces 520D Cubes

题意:

二维平面内有一个图形由n(10^5)个标有0~n-1的方块组成 保证它是稳定的 即每个方块要么落在地面上 要么下面(边或点相交)有至少一个方块支撑 现在两个人轮流拆这个图形 要求拆的过程中图形仍稳定 拆下的方块上的数字会形成一个n进制的数 先手想让这个数最大 后手想最小 问最后这个数字是几

思路:

简单的贪心思路 在不毁坏稳定性的前提下 先手拿大数字 后手拿小数字 程序写的暴力会n^2造成TLE

那么我们维护一个有序队列(set维护) 这里面装着可以拆的数字 每次从里面拿走想要的数字

注意的是进入set的数字在拆之前仍要检查可行性! 因为最开始可能是_-_这种形状 那么这3个都进入set 假设拆掉了右边 即变成了_-这样 那么这时左边就不能拆了 即使它在set里

每次拆完一个数字 检查它下面的3个位置 这三个位置也许具有拆掉的可能了

PS:

使用STL要小心点 一边遍历一遍删除元素是很危险的!!!

代码:

#include
  
   
#include
   
     #include
    
      #include
     
       #include
      
        #include
        #include
        
          #include
         
           #include
          
            #include
           
             #include
            
              #include
             
               using namespace std; typedef long long LL; #define N 100010 #define mod 1000000009 #define mp(x,y) (make_pair(x,y)) int n; int x[N],y[N]; map
              
               ,int> f; set
               
                 g; LL ans; bool yes(int tmp){ int X,Y; X=x[tmp]+1; Y=y[tmp]+1; if(f.count(mp(X,Y))){ if(!f.count(mp(X,Y-1))&&!f.count(mp(X+1,Y-1))){ return false; } } X=x[tmp]; Y=y[tmp]+1; if(f.count(mp(X,Y))){ if(!f.count(mp(X-1,Y-1))&&!f.count(mp(X+1,Y-1))){ return false; } } X=x[tmp]-1; Y=y[tmp]+1; if(f.count(mp(X,Y))){ if(!f.count(mp(X-1,Y-1))&&!f.count(mp(X,Y-1))){ return false; } } return true; } void add(int tmp){ int X,Y; X=x[tmp]-1; Y=y[tmp]-1; if(f.count(mp(X,Y))){ int u=f[mp(X,Y)]; if(yes(u)) g.insert(u); } X=x[tmp]; Y=y[tmp]-1; if(f.count(mp(X,Y))){ int u=f[mp(X,Y)]; if(yes(u)) g.insert(u); } X=x[tmp]+1; Y=y[tmp]-1; if(f.count(mp(X,Y))){ int u=f[mp(X,Y)]; if(yes(u)) g.insert(u); } } int main(){ scanf("%d",&n); for(int i=0;i
                
                 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇45. Jump Game II Leetcode Python 下一篇[Leetcode]Single Number

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·【C语言】动态内存管 (2025-12-27 06:23:20)
·C语言中的内存管理 - (2025-12-27 06:23:16)
·C语言指南:C语言内 (2025-12-27 06:23:14)
·Redis on AWS:Elast (2025-12-27 04:19:30)
·在 Spring Boot 项目 (2025-12-27 04:19:27)