hdu 2492 树状数组 Ping pong
Ping pong
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4589 Accepted Submission(s): 1681
Each
player has a unique skill rank. To improve their skill rank, they often
compete with each other. If two players want to compete, they must
choose a referee among other ping pong players and hold the game in the
referee's house. For some reason, the contestants can’t choose a referee
whose skill rank is higher or lower than both of theirs.
The
contestants have to walk to the referee’s house, and because they are
lazy, they want to make their total walking distance no more than the
distance between their houses. Of course all players live in different
houses and the position of their houses are all different. If the
referee or any of the two contestants is different, we call two games
different. Now is the problem: how many different games can be held in
this ping pong street?
first line of the input contains an integer T(1<=T<=20),
indicating the number of test cases, followed by T lines each of which
describes a test case.
Every test case consists of N + 1
integers. The first integer is N, the number of players. Then N distinct
integers a1, a2 … aN follow, indicating the skill rank of each player,
in the order of west to east. (1 <= ai <= 100000, i = 1 … N).
3 1 2 3
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct node{
int u,v,m,h;
}que[];
bool cmp(struct node t1,struct node t2){
if(t1.m==t2.m)
return t1.u<t2.u;
else
return t1.m<t2.m;
}
int main(){
int n;
while(scanf("%d",&n)!=EOF){
if(n==)
break;
for(int i=;i<n;i++){
scanf("%d%d",&que[i].u,&que[i].v);
que[i].h=(que[i].v-que[i].u)/+;
que[i].m=que[i].u+que[i].h;
}
sort(que,que+n,cmp);
int flag=;
for(int i=;i<n-;i++){
if(que[i].m>=que[i+].m){
flag=;
break;
}
if(que[i].m<que[i+].u)
continue;
double temp=que[i].m-que[i+].u;
que[i+].m=temp+que[i+].h+que[i+].u;
}
if(flag)
printf("NO\n");
else
printf("YES\n"); }
return ;
}
hdu 2492 树状数组 Ping pong的更多相关文章
- LA 4329 (树状数组) Ping pong
第一次写树状数组,感觉那个lowbit位运算用的相当厉害. 因为-x相当于把x的二进制位取反然后整体再加上1,所以最右边的一个1以及末尾的0,取反加一以后不变. 比如1000取反是0111加一得到10 ...
- HDU 2492 树状数组
DES:按照位置编号给你选手的rank值.每场比赛要有一个裁判,位置和rank在两个选手之间.两场比赛裁判不同 或有一个选手不同则可以说 两场比赛不同.问你一共可以有多少场比赛. 思路是遍历每个人当裁 ...
- hdu 4638 树状数组 区间内连续区间的个数(尽可能长)
Group Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- hdu 4777 树状数组+合数分解
Rabbit Kingdom Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 2852 (树状数组+无序第K小)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2852 题目大意:操作①:往盒子里放一个数.操作②:从盒子里扔掉一个数.操作③:查询盒子里大于a的第K小 ...
- HDU 4911 (树状数组+逆序数)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4911 题目大意:最多可以交换K次,就最小逆序对数 解题思路: 逆序数定理,当逆序对数大于0时,若ak ...
- hdu 5792(树状数组,容斥) World is Exploding
hdu 5792 要找的无非就是一个上升的仅有两个的序列和一个下降的仅有两个的序列,按照容斥的思想,肯定就是所有的上升的乘以所有的下降的,然后再减去重复的情况. 先用树状数组求出lx[i](在第 i ...
- HDU 1934 树状数组 也可以用线段树
http://acm.hdu.edu.cn/showproblem.php?pid=1394 或者是我自己挂的专题http://acm.hust.edu.cn/vjudge/contest/view. ...
- 2018 CCPC网络赛 1010 hdu 6447 ( 树状数组优化dp)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6447 思路:很容易推得dp转移公式:dp[i][j] = max(dp[i][j-1],dp[i-1][j ...
随机推荐
- git中Bash基本操作命令
).cd : 改变目录. ).cd . . 回退到上一个目录,直接cd进入默认目录 ).pwd : 显示当前所在的目录路径. ).ls(ll): 都是列出当前目录中的所有文件,只不过ll(两个ll)列 ...
- Apache 负载均衡 端口转发 配置
转载自:https://blog.csdn.net/snihcel/article/details/38844323 [端口转发配置] 通过http_proxy做tomcat的端口转发: ...
- CentOS7密码忘记解决方法&&GRUB菜单加密
CentOS7的root密码忘记怎么办 注意:该方法只适用于Linux7版本,可以用cat /redhat-release 查看 这里这里只介绍一种方法 1.启动的时候,在启动界面,相应启动项,内核名 ...
- 协议 - DNS
目录 1 DNS 1.1 域名解析的历史:/etc/hosts, DNS, FQDN 1.2 域名解析流程: 域名架构 查询流程, DNS端口 1.3 合法 DNS :申请域查询授权 1.4 主机名交 ...
- HTML+CSS : 笔记整理(1)
meta:页面描述信息(可以在里面加入作者信息等,如: <meta name="description"content="HTML examples"&g ...
- TCP/IP协议之http和https协议
一.TCP/IP协议 TCP/IP 是不同的通信协议的大集合. 1.TCP - 传输控制协议 TCP 用于从应用程序到网络的数据传输控制. TCP 负责在数据传送之前将它们分割为 IP 包,然后在它们 ...
- json_encode 的小技巧
做了一个 API 文档自动生成,解析的是每个 控制器类 的注释 json 数据,在做测试工具的时候,多层的 json 只有通过一个 textarea 把数据弄进去.如下图 怎么格式化 Json 数据并 ...
- Spark机器学习之推荐引擎
一. 最小二乘法建立模型 关于最小二乘法矩阵分解,我们可以参阅: 一.矩阵分解模型. 用户对物品的打分行为可以表示成一个评分矩阵A(m*n),表示m个用户对n各物品的打分情况.如下图所示: 其中,A( ...
- windows禁用/启用hyper-V,解决hyper-V与模拟器同时启用时造成冲突
- 3437: 小P的牧场
3437: 小P的牧场 思路 斜率优化. dp[i]表示到第i个点(第i个点按控制台)的最小代价. 代码 #include<cstdio> #include<iostream> ...