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
- Codeforces Round #367 (Div. 2) A、B
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #185 (Div. 2)--A,B
- Codeforces Round #216 (Div. 2) A.B
- Codeforces round #236Div.2--A;B
- Codeforces Round #236 (Div. 2)------A,B
- Codeforces Round #237 (Div. 2) A & B
- Codeforces Round #247 (Div. 2) A B
- Codeforces Round #251 (Div. 2) A~B
- Codeforces Round #249 (Div. 2) A B
- Codeforces Round #271 (Div. 2)-A.B
- Codeforces Round #202 (Div. 2) A,B
- Codeforces Round #277 (Div. 2) A B
- Codeforces Round #278 (Div. 2) A B
- Codeforces Round #278 (Div. 2) A, B
- Codeforces Round #281 (Div. 2) A B
- Codeforces Round #283 (Div. 2) A B
- Codeforces Round #282 (Div. 2) A B
- AIDL(续)
- Android Binder机制原理(史上最强理解,没有之一)
- C语言实现计算文件和字符串md5值
- 2016.08.17【初中部 NOIP提高组 】模拟赛C题目
- RTC(实时时钟)和BKP(备份寄存器)
- Codeforces Round #367 (Div. 2) A、B
- TCP知识1
- 快速排序
- Longest Common Prefix解题报告
- Git(二)-Git实战操练
- HDU 1166再来一个基础线段树
- 909422229__Mysql全部精华总结
- 【NOIP模拟】Matrix
- c++继承经典案例