Codeforces Round #367 (Div. 2) A、B

来源:互联网 发布:d3.js 力学图 编辑:程序博客网 时间:2024/06/06 01:24

A
水题,给出一个人的位置,再给出若干个出租车的位置和速度,问最少需要等多久可以等到第一辆出租车。

#include <bits/stdc++.h>#define _ ios_base::sync_with_stdio(0);cin.tie(0);#define INF 0x3f3f3f3f#define eps 1e-6typedef long long LL;const double pi = acos(-1.0);const long long mod = 1e9 + 7;const long long Mod = 10001;using namespace std;int main(){    ios_base::sync_with_stdio(false); cin.tie(0);    //freopen("int.txt","r",stdin);    //freopen("out.txt","w",stdout);    double x,y;    cin >> x >> y;    int T;    cin >> T;    double a,b,c;    double ans = INF;    while(T--)    {        cin >> a >> b >> c;        double s = sqrt( (x - a) * (x -  a) + (y - b) * (y - b) );        if(s / c < ans)            ans = s / c;    }    printf("%.12f\n",ans);    return 0;}

B
题意:给你N个数,还有Q个询问,每次询问给你一个数,问你N个数中小于等于询问的这个数的有多少个。
做法:显然可以用前缀和来维护,首先读入N个数的时候,统计每个数的数量,然后对应做一次前缀和。
所得到的num[i]就代表了N个数中小于等于i的数的个数。

#include <bits/stdc++.h>#define _ ios_base::sync_with_stdio(0);cin.tie(0);#define INF 0x3f3f3f3f#define eps 1e-6typedef long long LL;const double pi = acos(-1.0);const long long mod = 1e9 + 2015;using namespace std;int a;int num[100005];int main(){    ios_base::sync_with_stdio(false); cin.tie(0);    //freopen("int.txt","r",stdin);    //freopen("out.txt","w",stdout);    int N;    cin >> N;    int Max = -INF;    memset(num,0,sizeof(num));    for(int i = 0;i < N;i++)    {        cin >> a;        num[a]++;        Max = max(Max,a);    }    num[0] = 0;    for(int i = 1;i <= Max;i++)        num[i] += num[i - 1];    int T;    cin >> T;    int k;    while(T--)    {        cin >> k;        if(k > Max)        {            cout << N << endl;            continue;        }        cout << num[k] << endl;    }    return 0;}
0 0