比赛链接:http://codeforces.com/contest/702

A题求连续最长上升自序列。
[暴力题] 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 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. Powers of Two

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. Cellular Network

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. Road to Post Office

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)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Educational Codeforces Round 15 C. Cellular Network(二分)

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  4. Educational Codeforces Round 15 C 二分

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  5. Educational Codeforces Round 15 A dp

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. Educational Codeforces Round 15 [111110]

    注意一个词:连续 #include<stdio.h> #include<stdlib.h> #include<string.h> #include<bits/ ...

随机推荐

  1. Android中LayoutInflater的使用

    Inflater英文意思是膨胀,在Android中应该是扩展的意思吧. LayoutInflater 的作用类似于 findViewById(),不同点是LayoutInflater是用来找layou ...

  2. Struts2注解配置之@Namespace(四)

    今天开始学习@Namespace注解. 还是先看一段代码: package com.example.actions; import org.apache.struts2.convention.anno ...

  3. Oracle的rownum原理和使用(整理几个达人的帖子)

    整理和学习了一下网上高手关于rownum的帖子: 参考资料:  http://tech.ddvip.com/2008-10/122490439383296.html 和 http://tenn.jav ...

  4. 关于<img>标签与文字垂直居中

    要让左边的图片与后面的文字居中,如下效果 HTML代码: <img class="iconCls" alt="最新客户端" src="${bas ...

  5. BMP图像格式

    BMP(全称Bitmap)是Window操作系统中的标准图像文件格式,可以分成两类:设备相关位图(DDB)和设备无关位图(DIB),使用非常广.它采用位映射存储格式,除了图像深度可选以外,不采用其他任 ...

  6. msssql 用numberic(38)替代int去解决int不够的问题

    发现ms sql server的问题int(-2^31 ~ 2 ^ 31 -1)与程序中的UINT有时会对不上的时候, 发现如果用numberic(32)来做判断好像解决, 暂时就现在的插入操作来看, ...

  7. 值班问题:insert语句插入了两条数据?

    上周值班,碰到这样的一个客户问题,表结构简化如下: CREATE TABLE `aa` (`c1` int(10) unsigned NOT NULL AUTO_INCREMENT,`c2` int( ...

  8. Redis常用命令手册:服务器相关命令

    Redis提供了丰富的命令(command)对数据库和各种数据类型进行操作,这些command可以在Linux终端使用.在编程时,比如各类语言包,这些命令都有对应的方法.下面将Redis提供的命令做一 ...

  9. CCMoveTo 等函数理解

    CCMoveTo: 使用CCMoveTo action来让对象从右侧屏幕外移动到屏幕左侧.注意可以通过指定duration参数控制这一过程需要多久,这里我们随机给他2-4秒的时间. CCCallFun ...

  10. 酷派8150S(移动定制版)可用的第三方Recovery备份数据、刷机并精简系统内置APK经验

    希望使用的第三方Recovery下载地址: ClockworkMod ROM Manager - Recoveries http://clockworkmod.com/rommanager 适配的型号 ...