HDU 1896 Stones
来源:互联网 发布:xyz域名 co 编辑:程序博客网 时间:2024/06/06 09:04
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896
题目意思:一条路上放了很多石头,小明(虽然原题不是小明,但不要在意这些细节,都是人名嘛)在遇到第奇数块石头的时候,他可以将石头扔到前面去,如果同时又很多石头,那扔能仍得最近的那个,遇到第偶数块石头的时候就跳过。
题目分析:直接用优先队列维护离小明最近的石头呀。即用优先队列模拟这个过程。
下面是AC代码;
#include"stdio.h"#include"queue"#include"string.h"using namespace std;int d[100011];struct node{ int dis; int d; friend bool operator<(node n1,node n2) { if(n1.dis!=n2.dis) return n2.dis<n1.dis; return n2.d<n1.d; }};int MAX(int a,int b){ return a>b?a:b;}int main(){ int T; node cur,next; int num; int i; int n; int ans; scanf("%d",&T); while(T--) { priority_queue<node>q; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d%d",&cur.dis,&cur.d); q.push(cur); } num=0; ans=0; while(!q.empty()) { num++; cur=q.top(); q.pop(); ans=MAX(ans,cur.dis); if(!(num%2)) continue; next.dis=cur.dis+cur.d; next.d=cur.d; q.push(next); } printf("%d\n",ans); } return 0;}
0 0
- HDU 1896 Stones
- HDU 1896 Stones
- hdu 1896 Stones
- HDU 1896 Stones
- HDU 1896 Stones
- hdu 1896 Stones
- hdu 1896 stones 队列
- hdu 1896 stones
- HDU 1896 Stones
- HDU-1896-Stones
- HDU 1896 Stones (Priority_queue)
- HDU 1896 Stones
- HDU 1896 Stones
- hdu 1896 Stones
- HDU 1896 Stones
- hdu 1896 Stones
- HDU-1896-Stones
- HDU 1896 Stones
- 手机App的商业模式有哪些
- 快速视频图像上采样
- Struts2.3.16.1Hibernate4.3.4Spring4.0.2_框架 学习笔记
- JVM-GC总结-配置实战--第三发
- 理解JNDI中 java:comp/env/jdbc/datasource 与 jdbc/datasource 的不同之处
- HDU 1896 Stones
- android自动设置当前ImageView控件的颜色与其背景色相反
- [python]urllib与urllib2的常用函数
- 父页面操作iframe内的html元素
- hdu 3519 快速幂矩阵(7)+找规律
- Stanford机器学习---第三讲. 逻辑回归和过拟合问题的解决 logistic Regression & Regularization
- Java中计算百分比的方式以及js中
- Java 类的热替换 —— 概念、设计与实现
- Stanford机器学习---第四讲. 神经网络的表示 Neural Networks representation