链接:

https://vjudge.net/problem/HDU-6669

题意:

度度熊在玩一个好玩的游戏。

游戏的主人公站在一根数轴上,他可以在数轴上任意移动,对于每次移动,他可以选择往左或往右走一格或两格。

现在他要依次完成 n 个任务,对于任务 i,只要他处于区间 [ai,bi] 上,就算完成了任务。

度度熊想知道,为了完成所有的任务,最少需要移动多少次?

度度熊可以任意选择初始位置。

思路:

刚开始以为是贪心,按y拍了个序,疯狂wa,找了个题解发现是要按顺序.....

维护当前所在区间,然后找从最近的跑来跑去就行.

代码:

#include <bits/stdc++.h>
using namespace std; const int MAXN = 1e3+10; struct Node
{
int x, y;
}node[MAXN];
int n; int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
cin >> n;
for (int i = 1;i <= n;i++)
cin >> node[i].x >> node[i].y;
int res = 0;
int l = node[1].x, r = node[1].y;
for (int i = 2;i <= n;i++)
{
if (node[i].x >= l && node[i].y <= r)
l = node[i].x, r = node[i].y;
else if (node[i].x >= l && node[i].x <= r && node[i].y > r)
l = node[i].x;
else if (node[i].x < l && node[i].y >= l && node[i].y <= r)
r = node[i].y;
else if (node[i].x > r)
{
res += (node[i].x-r+1)/2;
l = node[i].x, r += ((node[i].x-r+1)/2)*2;
r = min(r, node[i].y);
}
else if (node[i].y < l)
{
res += (l-node[i].y+1)/2;
r = node[i].y, l -= ((l-node[i].y+1)/2)*2;
l = max(l, node[i].x);
}
}
cout << res << endl;
} return 0;
}

HDU-6669-Game(模拟,贪心)的更多相关文章

  1. HDU 4903 (模拟+贪心)

    Fighting the Landlords Problem Description Fighting the Landlords is a card game which has been a he ...

  2. 2019 年百度之星·程序设计大赛 - 初赛一Game HDU 6669 (实现,贪心)

    Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...

  3. HDU 4442 Physical Examination(贪心)

    HDU 4442 Physical Examination(贪心) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4442 Descripti ...

  4. hdu 模拟 贪心 4550

    卡片游戏 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Su ...

  5. HDU 5835 Danganronpa (贪心)

    Danganronpa 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5835 Description Chisa Yukizome works as ...

  6. BZOJ1029: [JSOI2007]建筑抢修[模拟 贪心 优先队列]

    1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec  Memory Limit: 162 MBSubmit: 3785  Solved: 1747[Submit][Statu ...

  7. Codeforces Round #375 (Div. 2) A B C 水 模拟 贪心

    A. The New Year: Meeting Friends time limit per test 1 second memory limit per test 256 megabytes in ...

  8. Codeforces 452D [模拟][贪心]

    题意: 给你k件衣服处理,告诉你洗衣机烘干机折叠机的数量,和它们处理一件衣服的时间,要求一件衣服在洗完之后必须立刻烘干,烘干之后必须立刻折叠,问所需的最小时间. 思路: 1.按照时间模拟 2.若洗完的 ...

  9. HDU 5821 Ball (贪心)

    Ball 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5821 Description ZZX has a sequence of boxes nu ...

  10. HDU 4121 Xiangqi 模拟题

    Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...

随机推荐

  1. java:LeakFilling(面向对象)

    1.类的修饰符只能是:public,默认的.另外:final  ,abstract,(修饰符 (只有:public, 默认,)interface+类名 ). 2.在main函数中创建对象时,new哪个 ...

  2. 连接Xshell

    连xshell之前先进入[root@localhost zxj]# vim /etc/ssh/sshd_config, 将115行删除注释改为UseDNS  no, 保存重启sshd(xshell)的 ...

  3. P1551 亲戚

    这里是题面啊~ 这道题我就不多说了,基本(好吧没有基本)就是一道模板题,读入+并查集+输出,完美结束 #include<set> #include<map> #include& ...

  4. 2 Java中常见集合

    1)说说常见的集合有哪些吧? 答:集合有两个基本接口:Collection 和 Map. Collection 接口的子接口有:List 接口.Set 接口和 Queue 接口: List 接口的实现 ...

  5. USACO1.6 Healthy Holsteins【dfs/bfs 爆搜】

    题目传送门 饲料种数只有15 枚举每种选或不选一共也就只有$2^{15}=32768$ 爆搜可过觉得bfs要快一些? 但是dfs更方便处理字典序 只需要顺序遍历并且先搞选它的情况就可以了 而且在这种规 ...

  6. CentOS 上面 恢复 Oracle 数据库实例的简单操作流程

    1. 当获取了数据库的备份可以进行 oracle数据库的备份恢复操作 linux上面要复杂一些. 这里面简单描述一下. 2. 远程连接 linux 主要工具可以选择 xshell 如图示: 3. 建议 ...

  7. qDebug的用法

    qDebug用于在控制台输出调试信息,主要有以下几种用法. 1.类似c++的cout函数 QString str="world"; qDebug()<<"he ...

  8. homestead安装swoole扩展

    配置好ubuntu的国内镜像源并更新 查看php版本,并安装对应php版本的dev sudo apt install php7.2-dev 配置pecl sudo pecl channel-updat ...

  9. Mysql 表空间和 数据页空洞

    一.表空间1.表空间: innodb 引擎存储的最高层: 存放所有的数据2.独立表空间:Mysql 版本 5.6 后默认开启的单表单空间(1)Innodb 默认存储引擎页的大小为 16K :默认表空间 ...

  10. 十一、LaTex中的矩阵