Educational Codeforces Round 15 (A - E)
比赛链接:http://codeforces.com/contest/702
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int N = 1e5 + ;
int a[N]; int main()
{
int n;
scanf("%d" , &n);
int temp = , res = ;
scanf("%d" , a + );
for(int i = ; i <= n ; ++i) {
scanf("%d" , a + i);
if(a[i] > a[i - ]) {
temp++;
res = max(res, temp);
}
else {
temp = ;
}
}
printf("%d\n" , res);
return ;
}
B题求有多少对数的和等于2的幂(即a[i] + a[j] = 2的幂)。
[map乱搞] 先用map存a[i]出现的次数。因为2的幂的个数也就30多个,那我们可以for一遍a数组,然后枚举2的幂。
统计mp[2的幂 - a[i]]的大小。要是2的幂-a[i]等于a[i],统计的时候减一就好了。
最后答案除以2,因为每对重复统计了两次。
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef __int64 LL;
typedef pair <int, int> P;
const int N = 1e5 + ;
map <LL , LL> mp;
LL num[];
LL a[N]; int main()
{
mp.clear();
num[] = ;
for(int i = ; i <= ; ++i) {
num[i] = num[i - ] * ;
}
int n;
scanf("%d" , &n);
for(int i = ; i <= n ; ++i) {
scanf("%lld" , a + i);
mp[a[i]]++;
}
LL res = ;
for(int i = ; i <= n ; ++i) {
for(int j = ; j <= ; j++) {
if(num[j] < a[i])
continue;
res += mp[num[j] - a[i]];
if(num[j] == * a[i])
res--;
}
}
printf("%lld\n" , res / );
return ;
}
C题题意是给你n个城市和m个塔的坐标,问你塔的信号半径最少是多少能够覆盖所有的城市。
[二分答案] 二分半径,每次二分一下 然后判断半径的可行性,可行性的话for一遍就好了。
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef __int64 LL;
typedef pair <int, int> P;
const int N = 1e5 + ;
LL a[N] , b[N];
int n , m; bool check(LL r) {
int index = , cnt = ;
for(int i = ; i <= n , index <= m; ++i) {
if(a[i] >= b[index] - r && a[i] <= b[index] + r) {
cnt++;
continue;
}
else {
index++;
i--;
}
}
if(cnt >= n)
return true;
return false;
} int main()
{
scanf("%d %d", &n , &m);
for(int i = ; i <= n ; ++i) {
scanf("%lld" , a + i);
}
for(int i = ; i <= m ; ++i) {
scanf("%lld" , b + i);
}
LL l = , r = *1e9+;
while(l < r) {
LL mid = (l + r) / ;
if(check(mid)) {
r = mid;
}
else {
l = mid + ;
}
}
printf("%lld\n" , r);
return ;
}
D题条件是:d代表路程长度,k代表车子每行驶k长度就会坏,a代表车行驶单位长度的时间,b代表人走路单位长度的时间,t代表坏的车修好时间。
车好像一开始没坏,问你最少需要多少时间能到终点。
[分类讨论] 一开始肯定要开车。后来我是比较车的平均速度(k/(k*a+t))和人的平均速度(1/b)。
要是人的速度大于等于车的速度,那走路到终点就好了。
不然的话就开车,但是开车开了k的整数倍,剩下路程(d')要是不到k的话,那讨论剩下的路 人和车谁话的时间最少(min(d'*a+k, d'*b))。
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef __int64 LL;
typedef pair <int, int> P;
const int N = 1e5 + ; int main()
{
LL d , k , a , b , t , res = ;
cin >> d >> k >> a >> b >> t;
LL ans = d;
d -= k;
res = k*a;
if(d <= ) { //一开始k < d的情况
cout << a * ans << endl;
return ;
}
double car = k*1.0 / (a*k + t) , peo = 1.0 / b; //车和人的速度
if(peo >= car) { //人的速度大于等于车的速度
res += d * b;
cout << res << endl;
return ;
}
LL temp = d;
d -= d / k * k; //车后来开了k的整数倍
res += temp / k * (k*a + t);
if(d > ) { //剩下的路 车和人 取最小的时间
LL temp1 = t + d * a , temp2 = d * b;
res += min(temp1 , temp2);
}
cout << res << endl;
return ;
}
E. Analysis of Pathes in Functional Graph
E题题意是有n个点(编号0 ~ n - 1),n条单向边,i和a[i]相连并指向a[i],然后给你每条边的权值。
问你从每个点出发,走k条边,走的路径权值和是多少,还有求其中最小的边是多少。
[倍增法] n条边 所以成环,单向 所以每条路径是唯一的。 可以想象成每个数开头之后的都是循环下去的数组。
可以用倍增法 类似RMQ的做法解,先预处理一下,par[i][j]表示从i点开始2^i后的点的编号,sum[i][j]表示i点开始2^j条边的路径权值和,min[i][j]表示i点开始2^j条边中最小的边权。
查询的时候利用k的二进制性质就行了,也是倍增。
//#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef __int64 LL;
typedef pair <int, int> P;
const int N = 1e5 + ;
int par[N][];
LL min_val[N][];
LL sum[N][]; void init(int n) {
for(int k = ; k < ; ++k) {
for(int i = ; i < n; ++i) {
par[i][k] = par[par[i][k - ]][k - ];
min_val[i][k] = min(min_val[i][k - ], min_val[par[i][k - ]][k - ]);
sum[i][k] = sum[i][k - ] + sum[par[i][k - ]][k - ];
}
}
} void solve(int root, LL x) {
LL res_min = 1e8 + , res_sum = ;
for(int k = ; k < ; ++k) {
if(x & (1LL << k)) {
res_sum += sum[root][k];
res_min = min(res_min, min_val[root][k]);
root = par[root][k];
}
}
printf("%lld %lld\n", res_sum, res_min);
} int main()
{
int n;
LL m;
scanf("%d %lld", &n, &m);
for(int i = ; i < n; ++i)
scanf("%d", &par[i][]);
for(int i = ; i < n; ++i) {
scanf("%lld", &min_val[i][]);
sum[i][] = min_val[i][];
}
init(n);
for(int i = ; i < n; ++i) {
solve(i, m);
}
return ;
}
F题不会
Educational Codeforces Round 15 (A - E)的更多相关文章
- Codeforces Educational Codeforces Round 15 C. Cellular Network
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Educational Codeforces Round 15 A. Maximum Increase
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 15 C. Cellular Network(二分)
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 15 C 二分
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 15 A dp
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph
E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...
- Codeforces Educational Codeforces Round 15 D. Road to Post Office
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Educational Codeforces Round 15 A, B , C 暴力 , map , 二分
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 15 [111110]
注意一个词:连续 #include<stdio.h> #include<stdlib.h> #include<string.h> #include<bits/ ...
随机推荐
- 配置IIS服务器,APK文件下载
解决方法:在IIS的MIME类型中添加扩展名.apk,MIME类型application/vnd.android即可
- ActivityManager: Warning: Activity not started, its current task has been brought to the front 的的问题
运行android程序的时候提示:ActivityManager: Warning: Activity not started, its current task has been brought t ...
- RecyclerView 结合 CardView 使用
准备工作:导入 1.activity_mian.xml <android.support.v7.widget.RecyclerView android:id="@+id/recycle ...
- 【转】JAVA之动态代理
转自:像少年啦飞驰 代理设计模式 定义:为其他对象提供一种代理以控制对这个对象的访问. 代理模式的结构如下图所示. 动态代理使用 java动态代理机制以巧妙的方式实现了代理模式的设计理念. 代理模式示 ...
- 自学了三天的SeaJs学习,解决了前端的一些问题,与小伙伴们一起分享一下!
我为什么学习SeaJs? [第一]:为了解决项目中资源文件版本号的问题,以及打包压缩合并等问题. [第二]:好奇心和求知欲.[我发现很多知名网站也都在使用(qq空间, msn, 淘宝等等),而且 Se ...
- UVALive 5713 Qin Shi Huang's National Road System(次小生成树)
题意:对于已知的网络构建道路,使城市两两之间能够互相到达.其中一条道路是可以免费修建的,问需要修建的总长度B与免费修建的道路所连接的两城市的人口之和A的比值A/B最大是多少. 因为是求A/B的最大值, ...
- 《SPFA算法的优化及应用》——姜碧野(学习笔记)
一.核心性质:三角不等式.最短路满足d[v]<=d[u]+w(u,v) 二.SPFA两种实现: 常见的是基于bfs的,这是直接对bellman-ford用队列维护.根据最短路的长度最长为(n-1 ...
- C扩展Python
基本想法: 先看中文小介绍,再看英文详细文档. 1. 参考 首先参考THIS, IBM的工程师好像出了好多这样的文章啊,而且每次看到时间戳,我都想戳自己- -! 2. ERROR 可能遇到错误: fa ...
- [端API] 控件在一个页面里open了,但其他页面打开这个控件怎么关闭
加在控件的参数里<script type="text/javascript" src="../script/api.js"></script& ...
- 【转】匹配dll(exe)和pdb方法
1. 静态检查windbg 调试工具包中有一个工具symchk.exe, 选项很多, 下面一个简单的用法可以检查一个 test.exe能不能找到与它匹配的PDB: 这是成功的情形. 下面来个失败的作为 ...