设为首页 加入收藏

TOP

poj2431(优先队列)
2015-07-20 17:18:56 来源: 作者: 【 】 浏览:2
Tags:poj2431 优先 队列

注意题目给的是到终点的距离,需要转成到起点的距离,还有就是将终点也看成是加油站,这样写起来方便很多,不必要单独考虑最后一个加油站不在终点以后的情况

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        using namespace std; int N,P,L; pair
       
         d[10100]; bool cmp(pair
        
          a, pair
         
           b) { return a.first > b.first; } void solve() { priority_queue
          
            que; sort(d,d+N,cmp); d[N].first = L, d[N++].second = 0; int ans = 0, pos = 0, tank = P; for(int i = 0; i < N; i++) { if(i != N - 1) d[i].first = L - d[i].first; int dis = d[i].first - pos; while(tank < dis) { if(!que.empty()) { tank += que.top(); que.pop(); ans++; } else { cout<<"-1"<
           
            >N) { for(int i = 0; i < N; i++) { cin>>d[i].first>>d[i].second; } cin>>L>>P; solve(); } return 0; }
           
          
         
        
       
      
     
    
   
  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇UVA - 11646 - Athletics Track .. 下一篇Leopard Jdbc:简化Spring Jdbc使用

评论

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

·MySQL 基础入门视频 (2025-12-26 23:20:22)
·小白入门:MySQL超详 (2025-12-26 23:20:19)
·关于 MySQL 数据库学 (2025-12-26 23:20:16)
·SOLVED: Ubuntu 24.0 (2025-12-26 22:51:53)
·Linux 常用命令最全 (2025-12-26 22:51:50)