Educational Codeforces Round 15 套题
这套题最后一题不会,然后先放一下,最后一题应该是大数据结构题
A:求连续最长严格递增的的串,O(n)简单dp
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
const int N = 1e5+;
const int INF = 0x3f3f3f3f;
int n,dp[N],a[N],cnt,mx;
int main(){
scanf("%d",&n);a[]=INF;
for(int i=;i<=n;++i){
scanf("%d",&a[i]);
dp[i]=;
if(a[i]>a[i-])dp[i]=dp[i-]+;
mx=max(mx,dp[i]);
}
printf("%d\n",mx);
return ;
}
B:水题,map乱搞
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
const int N = 1e5+;
const int INF = 2e9;
map<int,int>mp;
int a[],cnt;
int main(){
for(int i=;;++i){
if((1ll<<i)>INF)break;
a[++cnt]=(<<i);
}
LL ret=;
int x,n;scanf("%d",&n);
for(int i=;i<=n;++i){
scanf("%d",&x);
for(int j=cnt;j>;--j){
if(a[j]<=x)break;
int tmp=a[j]-x;
if(mp.find(tmp)!=mp.end())
ret+=mp[tmp];
}
if(mp.find(x)==mp.end())mp[x]=;
++mp[x];
}
printf("%I64d\n",ret);
return ;
}
C:一个典型的二分题,judge如何判断全被覆盖?只要用一下离线求和数组非0就好
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
const int N = 1e5+;
const int INF = 2e9;
LL a[N],b[N];
int n,m,c[N];
bool judge(LL r){
memset(c,,sizeof(c));
for(int i=;i<=m;++i){
int x=lower_bound(a+,a++n,b[i]-r)-a;
int y=upper_bound(a+,a++n,b[i]+r)-a;
++c[x];--c[y];
}
for(int i=;i<=n;++i){
c[i]+=c[i-];
if(!c[i])return false;
}
return true;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;++i)
scanf("%I64d",&a[i]);
sort(a+,a++n);
n=unique(a+,a++n)-a-;
for(int i=;i<=m;++i)
scanf("%I64d",&b[i]);
sort(b+,b++m);
m=unique(b+,b++m)-b-;
LL l=,r=INF;
while(l<r){
LL mid=(l+r)>>;
if(judge(mid))r=mid;
else l=mid+;
}
printf("%I64d\n",(l+r)>>);
return ;
}
D:一个简单的分类讨论,因为最多走k,以k为周期即可
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
const int N = 1e5+;
const int INF = 2e9;
LL d,k,a,b,t;
int main(){
scanf("%I64d%I64d%I64d%I64d%I64d",&d,&k,&a,&b,&t);
if(d<=k){
printf("%I64d\n",d*a);
return ;
}
LL ret=k*a;d-=k;
if(d<=k){
ret+=min(d*a+t,d*b);
printf("%I64d\n",ret);
return ;
}
LL t1=k*a+t,t2=k*b;
if(t2<=t1){
printf("%I64d\n",ret+d*b);
return ;
}
else {
ret+=d/k*t1;
d-=d/k*k;
if(d==){printf("%I64d\n",ret);return ;}
t1=t+d*a,t2=d*b;
ret+=min(t1,t2);
printf("%I64d\n",ret);
}
return ;
}
E:求从每个点出发路径长度为k的边权和以及边权最小值,刚开始还以为是快速幂,结果发现发现这条路唯一确定,直接倍增即可
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
const int N = 1e5+;
const int INF = 2e9;
struct Node{
int v,mn;
LL sum;
}f[N][];
LL retsum[N],k;
int n,retmin[N],cur[N];
void solve(){
for(int j=;(1ll<<j)<=k;++j)if(k&(1ll<<j)){
for(int i=;i<n;++i){
retsum[i]+=f[cur[i]][j].sum;
if(retmin[i]==-)retmin[i]=f[cur[i]][j].mn;
else retmin[i]=min(retmin[i],f[cur[i]][j].mn);
cur[i]=f[cur[i]][j].v;
}
}
for(int i=;i<n;++i)
printf("%I64d %d\n",retsum[i],retmin[i]);
}
int main(){
scanf("%d%I64d",&n,&k);
for(int i=;i<n;++i)scanf("%d",&f[i][].v),cur[i]=i,retmin[i]=-;
for(int i=;i<n;++i)scanf("%d",&f[i][].mn),f[i][].sum=f[i][].mn;
for(int j=;(1ll<<j)<=k;++j){
for(int i=;i<n;++i){
f[i][j].v=f[f[i][j-].v][j-].v;
f[i][j].sum=f[i][j-].sum+f[f[i][j-].v][j-].sum;
f[i][j].mn=min(f[i][j-].mn,f[f[i][j-].v][j-].mn);
}
}
solve();
return ;
}
F:不会,看了看别人的代码,并不能看懂,还是太弱
Educational Codeforces Round 15 套题的更多相关文章
- 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 ...
- 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 (A - E)
比赛链接:http://codeforces.com/contest/702 A. Maximum Increase A题求连续最长上升自序列. [暴力题] for一遍,前后比较就行了. #inclu ...
- Educational Codeforces Round 27 补题
题目链接:http://codeforces.com/contest/845 A. Chess Tourney 水题,排序之后判断第n个元素和n+1个元素是不是想等就可以了. #include < ...
- cordforce Educational Codeforces Round 47 补题笔记 <未完>
题目链接 http://codeforces.com/contest/1009 A. Game Shopping 直接模拟即可,用了一个队列来存储账单 #include <iostream> ...
- Educational Codeforces Round 15 [111110]
注意一个词:连续 #include<stdio.h> #include<stdlib.h> #include<string.h> #include<bits/ ...
- 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 ...
随机推荐
- POJ1328Radar Installation
http://poj.org/problem?id=1328 题的大意就是说在海里有小岛,坐标位置会给出,需要岸边的雷达覆盖所有的小岛,但雷达的覆盖范围有限,所以,需要最少的雷达覆盖所有的小岛,但若是 ...
- sql语句面试总结
1.用一条SQL语句 查询出每门课都大于80分的学生姓名 name kecheng fenshu 张三 语文 81张三 数学 75李四 语文 ...
- Qt4升级Qt5注意问题
Qt4升级Qt5注意问题 Qt4过渡到Qt5的项目一开始就受阻,记录一下遇到的下面的问题 --->编译遇到类似错误: error: QCalendarWidget: No such file o ...
- NSDictionary 遍历
NSDictionary *dic1=[NSDictionary dictionaryWithObjectsAndKeys: @"1",@"a", ...
- long和Long的区别
Java中数据类型分两种:1.基本类型:long,int,byte,float,double2.对象类型:Long,Integer,Byte,Float,Double其它一切java提供的,或者你自己 ...
- MariaDB10.2.X-新特性1-支持分析函数
前言:前段时间看到MariaDB10.2出测试版本了,心想有什么新特性玩玩,大家都知道MySQL不支持分析函数,但是MariaDB10.2.X支持分析函数了, 1.表结构 CREATE TABLE ` ...
- css控制UL LI 的样式详解
用<ul>设置导航 <style> #menu ul {list-style:none;margin:0px;} #menu ul li {float:left;} </ ...
- Android Studio Gradle
http://blog.zhaiyifan.cn/2016/03/14/android-new-project-from-0-p2/
- 概述什么是OSGi框架
现 在越来越多的Java开发人员在谈论OSGi是有其道理的.在几年前上学的时候我进行了比较多的Eclipse插件开发,当时就亲身感觉到Eclipse 插件体系的灵活与强大,而该体系与OSGi也可谓一脉 ...
- HDU 1710 Binary Tree Traversals
题意:给出一颗二叉树的前序遍历和中序遍历,输出其后续遍历 首先知道中序遍历是左子树根右子树递归遍历的,所以只要找到根节点,就能够拆分出左右子树 前序遍历是按照根左子树右子树递归遍历的,那么可以找出这颗 ...