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 ...
随机推荐
- hdu 2065 "红色病毒"问题
指数型母函数的应用 求A B C D 在规定条件下n个元素的排列个数,先写出指数型母函数 G(X) = ( 1 + x + x^2/2! + x^3/3! +... )^2 * ( 1+ x^2/2! ...
- lintcode 中等题:N Queens N皇后问题
题目: N皇后问题 n皇后问题是将n个皇后放置在n*n的棋盘上,皇后彼此之间不能相互攻击.<不同行,不同列,不同对角线> 给定一个整数n,返回所有不同的n皇后问题的解决方案. 每个解决方案 ...
- Shell脚本的编写
筛选后统计总数 cat logs | grep IconsendRedirect | wc -l >> bb.log 筛选后分类统计并且排序 cat logs | grep Iconsen ...
- 汇编debug 截图
- Android:简单联网获取网页代码
设置权限,在AndroidManifest.xml加入 <uses-permission android:name="android.permission.INTERNET" ...
- C++:成员运算符重载函数和友元运算符重载函数的比较
5.2.4 成员运算符重载函数和友元运算符重载函数的比较 (1)对双目运算符而言,成员运算符重载函数参数表中含有一个参数,而友元运算符重载函数参数表中有两个参数:对于单目运算符而言,成员运算符重载函数 ...
- scrapy wiki资料汇总
See also: Scrapy homepage, Official documentation, Scrapy snippets on Snipplr Getting started If you ...
- poj 2411 Mondriaan's Dream(状态压缩dP)
题目:http://poj.org/problem?id=2411 Input The input contains several test cases. Each test case is mad ...
- hibernate 中id生成策略
数据库的设计和操作中,我们通常会给表建立主键. 主键,可以分为自然主键和代理主键. 自然主键表示:采用具有业务逻辑含义的字段作为表的主键.比如在用户信息表中,采用用户的身份证号码作为主键.但是这样一来 ...
- socket编程---一个简单例子
服务器端代码(单线程): import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamRe ...