codeforces 782B The Meeting Place Cannot Be Changed+hdu 4355+hdu 2438 (三分)

B. The Meeting Place Cannot Be Changed

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

37 1 31 2 1

Output

2.000000000000

Input

45 10 3 22 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.

题意:x轴上有n个人  坐标为xi 最大行驶速度为vi   让这n个人走到相同一点的最短时间上多少

三分坐标  每次看到达这个坐标的最大时间 相互比较

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<map>
 5 #include<cstdlib>
 6 #include<vector>
 7 #include<set>
 8 #include<queue>
 9 #include<cstring>
10 #include<string.h>
11 #include<algorithm>
12 #define INF 0x3f3f3f3f
13 typedef long long ll;
14 typedef unsigned long long LL;
15 using namespace std;
16 const double eps=0.0000001;
17 const int N=60000+100;
18 double a[N],b[N];
19 int n;
20 double fun(double x){
21     double ans=0;
22     for(int i=0;i<n;i++)ans=max(ans,fabs(x-a[i])/b[i]);
23     return ans;
24 }
25 int main(){
26     while(scanf("%d",&n)!=EOF){
27         double maxx=-1.0*INF;
28         double minn=1.0*INF;
29         for(int i=0;i<n;i++){
30             scanf("%lf",&a[i]);
31             maxx=max(maxx,a[i]);
32             minn=min(minn,a[i]);
33         }
34         for(int i=0;i<n;i++)scanf("%lf",&b[i]);
35         double high=maxx;
36         double low=minn;
37         while(low+eps<high){
38             double mid=(high+low)/2.0;
39             double midd=(mid+high)/2.0;
40             if(fun(mid)<fun(midd))high=midd;
41             else
42                 low=mid;
43         }
44         printf("%.12f\n",fun(low));
45     }
46 }

hdu 4355

Party All the Time

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5384    Accepted Submission(s): 1679

Problem Description

In
the Dark forest, there is a Fairy kingdom where all the spirits will go
together and Celebrate the harvest every year. But there is one thing
you may not know that they hate walking so much that they would prefer
to stay at home if they need to walk a long way.According to our
observation,a spirit weighing W will increase its unhappyness for S3*W units if it walks a distance of S kilometers.
Now
give you every spirit‘s weight and location,find the best place to
celebrate the harvest which make the sum of unhappyness of every spirit
the least.

Input

The
first line of the input is the number T(T<=20), which is the number
of cases followed. The first line of each case consists of one integer
N(1<=N<=50000), indicating the number of spirits. Then comes N
lines in the order that x[i]<=x[i+1] for all i(1<=i<N). The i-th line contains two real number : Xi,Wi, representing the location and the weight of the i-th spirit. ( |xi|<=106, 0<wi<15 )

Output

For
each test case, please output a line which is "Case #X: Y", X means the
number of the test case and Y means the minimum sum of unhappyness
which is rounded to the nearest integer.

Sample Input

1

4

0.6 5

3.9 10

5.1 7

8.4 10

Sample Output

Case #1: 832

Author

[email protected]_Goldfinger

Source

2012 Multi-University Training Contest 6

我感觉这题和上面的其实很像 只是判断函数不一样而已

三分 这个 S3*W和 取最小值

#include<iostream>
#include<cstdio>
#include<cmath>
#include<map>
#include<cstdlib>
#include<vector>
#include<set>
#include<queue>
#include<cstring>
#include<string.h>
#include<algorithm>
#define INF 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const double eps=0.00000001;
const int N=100000+100;
int n;
struct node{
    double x;
    double w;
}a[N];
double fun(double x){
    double ans=0.0;
    for(int i=0;i<n;i++){
        double t=fabs(a[i].x-x);
        ans=ans+t*t*t*a[i].w;
    }
    return ans;
}
int main(){
    //cout<<eps<<endl;
    int t;
    scanf("%d",&t);
    for(int k=1;k<=t;k++){
        scanf("%d",&n);
        double minn=1.0*INF;
        double maxx=-1.0*INF;
        for(int i=0;i<n;i++){
            scanf("%lf%lf",&a[i].x,&a[i].w);
            maxx=max(maxx,a[i].x);
            minn=min(minn,a[i].x);
        }
        double low=minn;
        double high=maxx;
        double ans=low;
        while(low+eps<high){
            double mid=(low+high)/2.0;
            double midd=(mid+high)/2.0;
           // cout<<fun(mid)<<" "<<fun(midd)<<endl;
            if(fun(mid)<fun(midd)){
                high=midd;
            }
            else{
                low=mid;
                ans=low;
            }

        }
        printf("Case #%d: %.0f\n",k,fun(ans));
    }
}

hdu   2438

Turn the corner

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3181    Accepted Submission(s): 1289

Problem Description

Mr. West bought a new car! So he is travelling around the city.
One
day he comes to a vertical corner. The street he is currently in has a
width x, the street he wants to turn to has a width y. The car has a
length l and a width d.
Can Mr. West go across the corner?

Input

Every line has four real numbers, x, y, l and w.
Proceed to the end of file.

Output

If he can go across the corner, print "yes". Print "no" otherwise.

Sample Input

10 6 13.5 4

10 6 14.5 4

Sample Output

yes

no

Source

2008 Asia Harbin Regional Contest Online

其实这个是看别人的想法 后来自己画了下图

求f(a)=l*cos(a)-(x-w/cos(a))/tan(a);

只要f(a)<=y  就yes 否则 no

三分

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<map>
 5 #include<cstdlib>
 6 #include<vector>
 7 #include<set>
 8 #include<queue>
 9 #include<cstring>
10 #include<string.h>
11 #include<algorithm>
12 #define INF 0x3f3f3f3f
13 typedef long long ll;
14 typedef unsigned long long LL;
15 using namespace std;
16 const double PI=acos(-1.0);
17 const double eps=0.00000001;
18 double x,y,l,w;
19 double fun(double a){
20     double ans=l*cos(a)-(x-w/cos(a))/tan(a);
21     return ans;
22 }
23 int main(){
24     while(scanf("%lf%lf%lf%lf",&x,&y,&l,&w)!=EOF){
25         double low=0.0;
26         double high=PI/2.0;
27         if(x<w||y<w)
28         {
29             cout<<"no"<<endl;
30             continue;
31         }
32         while(low+eps<high){
33             double mid=(low+high)/2.0;
34             double midd=(mid+high)/2.0;
35             if(fun(mid)<=fun(midd)){
36                 low=mid;
37             }
38             else
39                 high=midd;
40         }
41         if(fun(low)<=y)cout<<"yes"<<endl;
42         else
43             cout<<"no"<<endl;
44     }
45 }
时间: 2024-08-02 11:02:50

codeforces 782B The Meeting Place Cannot Be Changed+hdu 4355+hdu 2438 (三分)的相关文章

codeforces 782B - The Meeting Place Cannot Be Changed

题意: 一条线上有n个人,每个人一个坐标值xi,每个人有一个最大行走速度vi,问如果要让这n个人走到线上某一个点,最少需要多少时间. 分析: 看起来是二分, 二分坐标. 二分区间变化的条件,一开始感觉是比较当前mid坐标左右人们用最快速度到达的平均时间, 后来具体写的时候感觉是比较当前mid坐标左右人们用最快速度到达的最大时间. 其实就是后者. 如果某一边的最大时间比较大的话,坐标就要向那一边偏移, 最后循环退出的条件就是在误差以内. 代码: 1 #include <set> 2 #inclu

【CodeForces - 238E】Meeting Her(图论+记忆化搜索)

Description 题目链接:Codeforces Solution 因为路线随机,所以找出各路线最短路必须经过的点,在这个点必定能上车 直接floyd暴力找割点 然后不断用k条公交车路线来更新DP答案,直到更新不了为止,dp[i]表示从点i到终点的答案 Code #include <cstdio> #include <algorithm> #include <cstring> #define N 1100 using namespace std; int n,m,

CF782B The Meeting Place Cannot Be Changed

题意: 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 standi

Codeforces 853B Jury Meeting

题意 从城市1-n来的评审团到城市0商讨国家大事,离开和抵达的那一天不能讨论,飞机均当天抵达,给出所有飞机起飞抵达代价情况,问能否使所有评审员聚齐连续k天并返回,并求最小代价 思路 从前向后扫一遍,求每天的出发最小代价L[i],从后向前扫,求每天最小离开代价R[i] 从前向后扫一遍,每天的最小代价为L[i]+R[i+k+1] 将每天的默认大小设为1e12,因为最大代价不超过1e11,可以据此确定答案是否合法 代码 #include<bits/stdc++.h> using namespace

Codeforces Round #403 (Div. 1, based on Technocup 2017 Finals)

Div1单场我从来就没上过分,这场又剧毒,半天才打出B,C挂了好几次最后还FST了,回紫了. AC:AB Rank:340 Rating:2204-71->2133 Div2.B.The Meeting Place Cannot Be Changed 题目大意:n个人,第i个人位于xi,速度为vi,找到一个点使得所有人到这个点的耗时最小,输出耗时.(n<=60000) 思路:二分答案,知道耗时后可以求出每个人能到达的区间,如果所有区间有交则合法,复杂度O(nlog). #include<

差分简单题集

[一维差分]Codeforces 1000C Covered Points Count 题目大意: 给定$n$个线段,给定这些线段所在的区间($l,r\leq10^{18}$),这些线段能够覆盖它们所包含的点,问你被包含$[1,n]$次的点分别有多少个. 解题分析:用差分来高效的统计一下指定区间内所被覆盖的线段个数,同时,因为$l,r$的大小非常大,所以我们需要对所有的线段进行离散化. #include <bits/stdc++.h> using namespace std; template

算法入门(C++)

iostream,这个头文件里有很多常用的函数,比如swap交换两个变量的值,max求两个值的最大值等. cstdio头文件,这个头文件里包含C风格的输入输出.如果你之前学习过C++语言应该知道cin读入和cout输出的方法.那么我们为什么还要用C的scanf和printf呢?因为scanf和printf要比cin和cout的效率高得多. using namespace std 如果没这行的话,swap就要写成std::swap,代码写起来会麻烦些. main函数它的返回值是int类型的.那么它

近期打算及毕业前要补完的题

之前总是开玩笑的说“退竞了退竞了”,这次看来是真的退役了.想想这一年来的学习历程,有欢笑也有汗水.可能还是因为自己太菜,可能还是因为自己不够努力,最终还是滚去学文化课了. 辜负了教练(手动@aqx)和朋友的关心和帮助,在这里说一声,抱歉 看着群里的各位都在快速的成长,除了自己内心的愧疚之外,也由衷的替他们感到开心. NOIP2018还剩100多天了,小伙伴们加油!XTYZ加油!祝各位RP++ 那么既然退役就要完完整整地结束,近期先准备把luogu博客上的文章慢慢的搬过来,之后应该就是一点点的把之

DP &#215; KMP

几道用到KMP的DP题: hdu 5763    hdu 3689    hdu 3336    codeforces 494B    codevs 3945 一道一道来~ hdu 5763  Another Meaning 题意及样例:原题链接 设第一个串为A,长为n:第二个串为B,长为L 从1到n计算1~k能代表的意思的数量f[k] 如果A[k-L+1,k]==B 则f[k]=f[k-L]+f[k-1] 否则f[k]=f[k-1] 判断A[k-L+1,k]是否与B匹配就要靠KMP了 1 #i