Day2 B - Stones

  • 题目正文
  • 翻译
  • 题意
    • 代码
  • 总结

题目正文

Because of the wrong status of the bicycle, Sempr begin to walk east to west every morning and walk back every evening. Walking may cause a little tired, so Sempr always play some games this time.
There are many stones on the road, when he meet a stone, he will throw it ahead as far as possible if it is the odd stone he meet, or leave it where it was if it is the even stone. Now give you some informations about the stones on the road, you are to tell me the distance from the start point to the farthest stone after Sempr walk by. Please pay attention that if two or more stones stay at the same position, you will meet the larger one(the one with the smallest Di, as described in the Input) first.
Input
In the first line, there is an Integer T(1<=T<=10), which means the test cases in the input file. Then followed by T test cases.
For each test case, I will give you an Integer N(0<N<=100,000) in the first line, which means the number of stones on the road. Then followed by N lines and there are two integers Pi(0<=Pi<=100,000) and Di(0<=Di<=1,000) in the line, which means the position of the i-th stone and how far Sempr can throw it.
Output
Just output one line for one test case, as described in the Description.

翻译

由于自行车的错误状态,Sempr开始每天早上从东向西走,每天晚上再往回走。走路可能会让人有点累,所以Sempr这次总是玩一些游戏。

路上有很多石头,当他遇到一块石头时,如果他遇到的是奇数的石头,他会把它扔到尽可能远的地方,如果是偶数的石头,他会把它留在原来的地方。现在给你一些关于路上石头的信息,你要告诉我从起点到Sempr经过后最远石头的距离。请注意,如果两个或两个以上的石头停留在同一位置,您将首先遇到较大的石头(输入中描述的Di最小的石头)。

输入

在第一行中,有一个整数T(1<=T<=10),表示输入文件中的测试用例。然后是T检验案例。

对于每个测试用例,我将在第一行给您一个整数N(0<N<=100000),这意味着道路上的石头数量。接着是N行,行中有两个整数Pi(0<=Pi<=100000)和Di(0<=Di<=1000),这意味着第i块石头的位置和Sempr可以扔多远。

输出

只需为一个测试用例输出一行,如描述中所述。

题意

遇到第偶数次不扔石头,当遇到奇数石头,往前扔,一直到前面没有石头为止,最后求最远一块石头到起点的距离

代码

代码:

//优先队列1.先定义一个结构体,结构体中有位置,距离
//2.运用友元函数friend,运算符重载friend bool operator < (node a,node b) {//3.当两块石头的位置相同时,选择距离远的石头,用if语句,否则返回位置远的石头
//4.在主函数中先定义一个测试用例的变量,并输入
//5.whlie循环中,定义一个优先队列,定义一个石头的数量,并输入,定义一个遇见石头的次数
//定义一个节点
//6.循环定义两个变量,并输入,赋值给结构体的位置和距离,并把该节点进队列
//7.循环遍历队列是否为空,若不为空,取队列顶部元素,并出队列
//8.判断遇见石头的次数是奇数还是偶数,若为奇数,位置加上距离并进队列
//9.遇见石头的次数加加
//10.输出最后的位置结果
#include<stdio.h>
#include<iostream>
#include<queue>
using namespace std;
struct node
{int pos;int dis;friend bool operator<(node a,node b){if(a.pos==b.pos)return a.dis>b.dis;return a.pos>b.pos;}
};
int main()
{int T;cin>>T;while(T--){priority_queue<node> p;int n;cin>>n;int num=1;//遇见石块的次数node temp;for(int i=1;i<=n;i++){int a,b;cin>>a>>b;temp.pos=a;temp.dis=b;p.push(temp);}while(!p.empty()){temp=p.top();p.pop();if(num%2){temp.pos+=temp.dis;p.push(temp);}num++;}cout<<temp.pos<<endl;}
}

总结

主要采用优先队列的方法

Day2 B - Stones相关推荐

  1. Day2 - Python基础2作业【文件操作--购物车程序(用户操作及商户操作)】

    1 # ----user.txt---- 2 3 {'已购商品': '', '消费记录': '', '余额': 0} 4 5 6 # ----commodity.txt---- 7 8 iPhone, ...

  2. 【JAVA零基础入门系列】Day2 Java集成开发环境IDEA

    [JAVA零基础入门系列](已完结)导航目录 Day1 开发环境搭建 Day2 Java集成开发环境IDEA Day3 Java基本数据类型 Day4 变量与常量 Day5 Java中的运算符 Day ...

  3. UVA 1482 - Playing With Stones(SG打表规律)

    UVA 1482 - Playing With Stones 题目链接 题意:给定n堆石头,每次选一堆取至少一个.不超过一半的石子,最后不能取的输,问是否先手必胜 思路:数值非常大.无法直接递推sg函 ...

  4. DFS、栈、双向队列:CF264A- Escape from Stones

    题目: Squirrel Liss liv Escape from Stonesed in a forest peacefully, but unexpected trouble happens. S ...

  5. Alpha冲刺Day2

    冲刺Day2 一.站立式会议计划 分组讨论研究:较好的掌握MYSQL的使用,以及Android Studio图形化界面设计的学习同步进行. 完成设计数据库架构,进阶版. 登录.注册界面的设计. 能从同 ...

  6. ZJOI2019 Day2 游记

    emmm,一直没有更新不是因为退役了自闭什么的,只是单纯比较懒.写游记很累的. 这次余姚之旅中我似乎并没有怎样焦急和兴奋,回想起来,我甚至比一试时要平静得多. 是因为挫折让人有些长大了吗? 二试讲课时 ...

  7. Codeforces 768E:Game of Stones

    Codeforces 768E:Game of Stones 题目链接:http://codeforces.com/contest/768/problem/E 题目大意:给定$n$堆石子,初始每堆$s ...

  8. 【从零开始学BPM,Day2】默认表单开发

    [课程主题] 主题:5天,一起从零开始学习BPM [课程形式] 1.为期5天的短任务学习 2.每天观看一个视频,视频学习时间自由安排. [第二天课程] Step 1 软件下载:H3 BPM10.0全开 ...

  9. MyBatis-Plus Day2 Wapper 核心功能 条件构造器 测试

    MyBatis-Plus Day2 核心功能 条件构造器 之前搭建的在上一篇博客中已经写好了. 链接:https://blog.csdn.net/weixin_45821811/article/det ...

最新文章

  1. 【 FPGA 】认识关键BUFFER
  2. fedora下重用ssh连接 类似secureCRT的clone session功能
  3. 修改linux swap空间的swappiness,降低对硬盘的缓存
  4. OpenCV用thrust使用cv :: cuda :: GpuMat
  5. 步步为营VS 2008 + .NET 3.5(2) - VS 2008新特性之JavaScript Intellisense and Debugging
  6. string类用法Java_Java中String类的用法
  7. 云服务器远程连接的设置方法、安全组设置(外网可访问)
  8. Java面试必看的18个开源项目
  9. BOS v2.0后台管理系统 JQuery Easyui 相关知识讲解
  10. 图像处理:图像灰度化
  11. SQL根据身份证判断性别
  12. 如何下载企业微信上课直播回放
  13. android 杀死程序收不到推送_Android收不到推送解决方案
  14. Android从零开始:Google Play服务
  15. PMP考试重点难点汇总
  16. win10开机桌面壁纸位置
  17. 5.2 activiti任务监听器TaskListener
  18. Java8 stream特性之一:List转Map方案(返回某个属性或对象本身)
  19. python3设置编码格式_python3编码调整
  20. 激流勇进,数据库替代比预想要快得多

热门文章

  1. 鲸探发布点评:8月24日发售《LuLu猪西游》系列数字藏品
  2. JS实现简易ATM机
  3. 招聘 | 百度自然语言处理部-实习生
  4. [Python]链式赋值(Chained assignment)
  5. 【CSDN|每日一练】吃!吃!吃!
  6. android tv闹钟_Android 平台有哪些闹钟应用值得推荐?
  7. 伯克利分校研究生计算机排名及申请,加州大学伯克利分校研究生计算机专业排名及申请要求一览...
  8. EndNote丨关于英文文献多作者 et al 后面出现两个点 et al. .的问题
  9. 计算机在线给手机杀毒,怎么用电脑给手机杀毒(如果手机中病毒了怎么办)
  10. linux文件IO简述和内容整理