Codeforces Round #367 (Div. 2) A、B
2016-08-17 18:48
393 查看
A
水题,给出一个人的位置,再给出若干个出租车的位置和速度,问最少需要等多久可以等到第一辆出租车。
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-6 typedef 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-6 typedef 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; }
相关文章推荐
- angularjs的使用:路由(4)
- 【zzuliOJ】1918 - 寻宝(二分图)
- hash解决冲突之---平方探测
- UIScrollViewDelegate 代理方法和表格的Delegate 方法冲突
- 桌面桌面虚拟化-Vmware horizon 7相关文件共享
- C++类与对象
- Android Binder机制原理(史上最强理解,没有之一)
- Android Studio中改变字体大小
- Android对话框大全
- AIDL(续)
- 自定义JSP标签入门
- firstTime
- DAY6
- UVALive 7457 Discrete Logarithm Problem
- OC-KVC/KVO
- C语言的良好编程习惯
- 一篇文章让你成为 NIO 大师 - MyCAT通信模型
- NSDateFormatter的格式串详解—将GMT格式转为NSDate
- React Native之React速学教程(下)
- c++面试题