codeforces 782/problem/B [二分]

B. The Meeting Place Cannot Be Changed
time limit per test
5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.

At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north.

You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate.

Input

The first line contains single integer n (2 ≤ n ≤ 60 000) — the number of friends.

The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 109) — the current coordinates of the friends, in meters.

The third line contains n integers v1, v2, ..., vn (1 ≤ vi ≤ 109) — the maximum speeds of the friends, in meters per second.

Output

Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road.

Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if  holds.

Examples
input
3
7 1 3
1 2 1
output
2.000000000000
input
4
5 10 3 2
2 3 2 4
output
1.400000000000
Note

In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.


对时间二分搜索即可

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;

const int MAXS = 60*1024*1024;
char buf[MAXS],*ch;

void read(int &x){
	for(++ch;*ch<=32;++ch);
	for(x=0;*ch>='0';++ch) x=x*10+*ch-'0';
}

void std_init(){
	ch=buf-1;
	fread(buf,1,MAXS,stdin);
}

/*---------------------------------------------------------------*/

const int MAXN=60005;

struct node{
	int x,v;
}cs[MAXN];
int n;


bool check(double t){
	double low=-1e9,top=1e9;
	for(int i=0;i<n;i++){
		low=max(low,cs[i].x-t*cs[i].v);
		top=min(top,cs[i].x+t*cs[i].v);
		if(top<low) return false;
	}
	return true;
}

int main()
{
	std_init();
	read(n);
	for(int i=0;i<n;i++) read(cs[i].x);
	for(int i=0;i<n;i++) read(cs[i].v);
	
	double low=0.0,top=1e9+10.0;
	while(top-low>0.0000001){
		double mid=(top+low)/2;
		if(check(mid))
			top=mid;
		else
			low=mid;
	}
	printf("%0.6lf\n",top);
	return 0;
}




<think>嗯,用户想要寻找适合Codeforces新手的题目列表推荐。首先,我需要回忆一下Codeforces的题目分类和难度分级。通常,Codeforces的题目难度从A开始递增,A题通常是最简单的,适合新手。但可能用户需要更具体的指导,比如按主题或技巧分类的题目列表。 然后,我应该考虑用户可能的真实需求。作为新手,他们可能需要先掌握基本的数据结构、算法和编程基础,比如循环、条件语句、数组处理、字符串操作等。因此,推荐的题目应该覆盖这些基础内容,并且难度适中,避免太复杂的问题导致挫败感。 接下来,我需要回忆或查找一些经典的适合新手的题目。比如,Problem 4C Registration system,这是一个处理字符串和哈希映射的题目,非常适合练习基本的数据结构应用。另外,Problem 71A,处理字符串缩写,也是一个常见的入门题。其他像Problem 1A(数学计算)、Problem 158A(数组处理)、Problem 118A(字符串处理)都是常见的新手题。 还要考虑到不同知识点的覆盖,比如数学问题、贪心算法、简单动态规划等。例如,Problem 50A(棋盘覆盖问题)涉及数学和贪心策略,Problem 266B(队列操作)涉及模拟和基本算法思路。 然后,我需要验证这些题目的难度是否确实适合新手。比如,查看这些题目的通过率和标签,确认它们通常被归类为Div.2 A或B题,或者是教育轮次的早期题目。此外,可能需要推荐一些在线资源或整理好的题单,比如Codeforces的官方分类或用户整理的入门列表,这样用户可以系统地练习。 用户可能还需要一些学习建议,比如如何逐步提升,如何利用题解和讨论区,或者如何参加比赛。因此,在回答中加入这些建议会更有帮助。同时,要确保推荐的具体题目都有正确的编号和链接,方便用户查找。 最后,确保回答结构清晰,分点列出推荐的题目,并简要说明每个题目的考察点和难度,让用户一目了然。还要检查是否有遗漏的重要知识点,比如排序、搜索等基础算法,如果有的话需要补充进去。同时,提醒用户多练习和参加比赛,这是提升的关键。</think>### Codeforces新手题目推荐指南 #### 一、基础编程能力训练 1. **Problem 4C: Registration system** 考察哈希表应用,学习处理字符串计数问题。题目要求为重复用户名自动添加序号,适合练习`map`容器的使用[^1]。 2. **Problem 71A: Way Too Long Words** 练习字符串基本操作,规则简单:长度超过10的单词缩写为首字母+中间字母数+尾字母。 ```python n = int(input()) for _ in range(n): s = input() print(s[0] + str(len(s)-2) + s[-1] if len(s)>10 else s) ``` 3. **Problem 1A: Theatre Square** 基础数学题,计算铺地砖数量,涉及向上取整运算: $$ \text{数量} = \lceil \frac{n}{a} \rceil \times \lceil \frac{m}{a} \rceil $$ #### 二、算法思维入门 4. **Problem 158A: Next Round** 数组处理经典题,理解条件判断与边界值处理,注意并列分数的情况。 5. **Problem 50A: Domino piling** 贪心策略应用,通过数学推导直接得出公式: $$ \text{最大骨牌数} = \lfloor \frac{m \times n}{2} \rfloor $$ 6. **Problem 266B: Queue at the School** 模拟题,学习时间步进和队列状态更新,适合理解算法实现流程。 #### 三、数据结构专项 7. **Problem 118A: String Task** 字符串处理综合练习,需完成大小写转换、元音删除和字符插入操作。 8. **Problem 112A: Petya and Strings** 比较字符串的字典序,重点练习ASCII码处理和大小写统一方法。 #### 四、推荐练习路径 - **第一阶段**:优先完成1A、71A、266B,掌握输入输出和基础逻辑 - **第二阶段**:尝试4C、158A、118A,学习数据结构和字符串处理 - **进阶路线**:挑战动态规划入门题如Problem 189A(丝带切割问题) #### 五、学习资源推荐 1. Codeforces官方标签筛选:使用`tags`功能选择`brute force`/`math`标签的800-1000分题目 2. 知名训练清单:参考[Errichto的入门题单](https://codeforces.com/blog/entry/77173),包含分类训练指引 3. 虚拟参赛:通过Practice功能参与旧比赛的Div.2场次,重点关注A-B题
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值