2020.12.20-Codeforces Round #105补题
The princess is going to escape the dragon's cave, and she needs to plan it carefully.
The princess runs at vp miles per hour, and the dragon flies at vd miles per hour. The dragon will discover the escape after t hours and will chase the princess immediately. Looks like there's no chance to success, but the princess noticed that the dragon is very greedy and not too smart. To delay him, the princess decides to borrow a couple of bijous from his treasury. Once the dragon overtakes the princess, she will drop one bijou to distract him. In this case he will stop, pick up the item, return to the cave and spend f hours to straighten the things out in the treasury. Only after this will he resume the chase again from the very beginning.
The princess is going to run on the straight. The distance between the cave and the king's castle she's aiming for is c miles. How many bijous will she need to take from the treasury to be able to reach the castle? If the dragon overtakes the princess at exactly the same moment she has reached the castle, we assume that she reached the castle before the dragon reached her, and doesn't need an extra bijou to hold him off.
Input
The input data contains integers vp, vd, t, f and c, one per line (1 ≤ vp, vd ≤ 100, 1 ≤ t, f ≤ 10, 1 ≤ c ≤ 1000).
Output
Output the minimal number of bijous required for the escape to succeed.
Examples
1
2
1
1
10
2
1
2
1
1
8
1
Note
In the first case one hour after the escape the dragon will discover it, and the princess will be 1 mile away from the cave. In two hours the dragon will overtake the princess 2 miles away from the cave, and she will need to drop the first bijou. Return to the cave and fixing the treasury will take the dragon two more hours; meanwhile the princess will be 4 miles away from the cave. Next time the dragon will overtake the princess 8 miles away from the cave, and she will need the second bijou, but after this she will reach the castle without any further trouble.
The second case is similar to the first one, but the second time the dragon overtakes the princess when she has reached the castle, and she won't need the second bijou.
一开始做的时候没读懂题意,没有理清他们之间的关系,就去看了其他题,然后又回来做这道题,真的是必须要写一写就可以弄清楚各个变量之间的关系了,但是我最后做了三次,前两次直接wa了,第三次在测试点44上超时,其实还是没有理清思路就下手写,然后就越来越乱。最后要注意变量类型要设为double型。
题解:公主以vp的速度逃跑,龙以vd的速度去追赶,公主出发t时间后龙才出发,如果龙追上了公主,公主便扔下一个珠宝使龙以原速度回到出发点,并且龙还需要f时间整理它的洞穴后才可以再次出发。公主与终点距离为c,只要公主到达终点龙就追不上公主,求公主需要使用多少次珠宝。
思路:如果龙的速度小于公主的速度就永远追不上,所以只需要计算每次龙追上公主的时间,再将距离和终点进行比较。
#include<bits/stdc++.h>
using namespace std;
int main()
{
double vd,vp,f,t,c,num=0; //注意类型要设为double
scanf("%lf%lf%lf%lf%lf",&vp,&vd,&t,&f,&c);
if(vd<vp)
{
cout<<"0"<<endl;
}
else
{
int ct=0;
double sum=vp*t;
while(1)
{
double tt=sum*1.0/(vd-vp);//龙追上公主所用的时间
sum+=vp*tt;//龙追上公主时公主所走的路程
if(sum>=c)break;
else
{
ct++;
sum+=vp*(f+tt);//公主扔下一枚珠宝,龙返回以及整理所用时间下公主所走的总路程
}
}
cout<<ct<<endl;
}
}
2020.12.20-Codeforces Round #105补题的更多相关文章
- cordforce Educational Codeforces Round 47 补题笔记 <未完>
题目链接 http://codeforces.com/contest/1009 A. Game Shopping 直接模拟即可,用了一个队列来存储账单 #include <iostream> ...
- Educational Codeforces Round 27 补题
题目链接:http://codeforces.com/contest/845 A. Chess Tourney 水题,排序之后判断第n个元素和n+1个元素是不是想等就可以了. #include < ...
- Educational Codeforces Round 23 补题小结
昨晚听说有教做人场,去补了下玩. 大概我的水平能做个5/6的样子? (不会二进制Trie啊,我真菜) A. 傻逼题.大概可以看成向量加法,判断下就好了. #include<iostream> ...
- Educational Codeforces Round 22 补题 CF 813 A-F
A The Contest 直接粗暴贪心 略过 #include<bits/stdc++.h> using namespace std; int main() {//freopen(&qu ...
- 水题 Codeforces Round #105 (Div. 2) B. Escape
题目传送门 /* 水题:这题唯一要注意的是要用double,princess可能在一个小时之内被dragon赶上 */ #include <cstdio> #include <alg ...
- Codeforces Round #456 B题
一.题意 给你一个n和一个k,让你从[1, n]区间内选k个数,这k个数异或和最大. 二.思路 我一开始看到这种题,不自觉地就想到,莫非又要搞很复杂的线段树.主席树?貌似还有些难搞啊.然而事实是:Co ...
- [每日一题2020.06.11]Codeforces Round #644 (Div. 3) H
A-E见 : 这里 题目 我觉得很有必要把H拿出来单独发( 其实是今天懒得写题了 ) problem H 一个从 1 到 $ 2^m - 1$ 的长度为m的连续二进制序列, 删去指定的n个数, 问剩余 ...
- [每日一题2020.06.10]Codeforces Round #644 (Div. 3) ABCDEFG
花了5个多少小时总算把div3打通一次( 题目链接 problem A 题意 : 两个x*y的矩形不能重叠摆放, 要放进一个正方形正方形边长最小为多少 先求n = min(2x, 2y, x+y) 再 ...
- codeforces水题100道 第四题 Codeforces Round #105 (Div. 2) A. Insomnia cure (math)
题目链接:http://www.codeforces.com/problemset/problem/148/A题意:求1到d中有多少个数能被k,l,m,n中的至少一个数整出.C++代码: #inclu ...
随机推荐
- Java反射的浅显理解
一.回顾反射相关的知识 1.在xml文件中使用反射的好处: 1)代码更加灵活,后期维护只需要修改配置文件即可 · 初学者一般习惯于在代码本身上直接修改,后期也可以修改配置文件达到相同的目的 · 修改配 ...
- 剑指 Offer 34. 二叉树中和为某一值的路径
剑指 Offer 34. 二叉树中和为某一值的路径 输入一棵二叉树和一个整数,打印出二叉树中节点值的和为输入整数的所有路径.从树的根节点开始往下一直到叶节点所经过的节点形成一条路径. 示例: 给定如下 ...
- adb 常用命令大全(3)- 查看手机设备信息
查看手机型号 adb shell getprop ro.product.model 查看电池状况 adb shell dumpsys battery 其中 scale 代表最大电量,level 代表当 ...
- lua中的sleep实现
这篇文章主要介绍了Lua中实现sleep函数功能的4种方法,本文讲解了在一个死循环中设置一个跳出条件方法.调用系统的sleep函数法.Windows下ping命令法.socket库中select函数法 ...
- Nginx:进程调度
Blog:博客园 个人 Nginx采用的是固定数量的多进程模型,由一个主进程(MasterProcess)和数量与主机CPU核数相同的工作进程协同处理各种事件. 主管理进程负责工作进程的配置加载.启停 ...
- 【PHP数据结构】线性查找与二分查找
欢迎来到查找的世界,在学习完各种数据结构之后,总算走到了这一步,不知道大家有什么感想呢?反正我是边学边忘,现在让我去说说图的那几个算法还是在蒙圈的状态中.不过学习嘛,就是一步一步的来,暂时搞不懂的东西 ...
- oracle 基础SQL语句 版本5.7.29
一.表与用户介绍 oracle安装完成后默认会有很多用户,大致分为2类用户:一类是必需的帐户,一类是存储各种应用的帐户,默认密码如下: oracle自带的也会有很多默认表存在: 二.创建用户.创建表空 ...
- javascript 字符串 数字反转 字母大小写互换
// 符串abcd123ABCD456 怎么转换为 ABCD321abcd654 // 数字要倒序 小写转大写, 大写转小写 Array.prototype.reverse = function() ...
- 一文让你彻底理解having和where的区别
having子句与where都是设定条件筛选的语句,有相似之处也有区别. having与where的区别: having是在分组后对数据进行过滤 where是在分组前对数据进行过滤 having后面可 ...
- Java集合框架总览
Java集合 Java 集合框架主要包括两种类型的容器,一种是集合(Collection),存储一个元素集合,另一种是图(Map),存储键/值对映射.Collection 接口有 3 种子类型,Lis ...