【CF1029B】Creating the Contest(贪心)
题意:
n<=2e5
思路:可以证明答案一定是极长的一段中取最大值
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define N 5100000
#define MOD 1e9+7
#define eps 1e-8
#define pi acos(-1) int a[],dp[],ans,t,w; int read()
{
int v=,f=;
char c=getchar();
while(c<||<c) {if(c=='-') f=-; c=getchar();}
while(<=c&&c<=) v=(v<<)+v+v+c-,c=getchar();
return v*f;
} void swap(int &x,int &y)
{
int t=x;x=y;y=t;
} int main()
{
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
int n;
scanf("%d",&n);
for(int i=;i<=n;i++) a[i]=read(); ans=;
w=;
t=;
dp[]=;
for(int i=;i<=n;i++)
{
dp[i]=;
while(w+<=n&&a[w]*<a[i]) w++;
while(w+<i&&w+<=n&&a[w+]*>=a[i]) w++;
if(w<i) dp[i]=max(dp[i],dp[w]+);
ans=max(ans,dp[i]);
//printf("%d %d %d\n",i,w,dp[i]);
}
printf("%d",ans);
return ;
}
【CF1029B】Creating the Contest(贪心)的更多相关文章
- codeforce1029B B. Creating the Contest(简单dp,简单版单调栈)
B. Creating the Contest time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces Round #506 (Div. 3)B.Creating the Contest(dp)
B. Creating the Contest time limit per test 1 second memory limit per test 256 megabytes input stand ...
- 【贪心/DP/单调队列】【CF1029B】Creating the Contest
Description 给你一个单调不下降的长度为n的序列,请你找出一个最长的子序列,满足找出的子序列中,\(A_i<=A_{i-1}~\times~2\),其中i为下标,A为找出的子序列.对于 ...
- CodeForces B. Creating the Contest
http://codeforces.com/contest/1029/problem/B You are given a problemset consisting of nn problems. T ...
- B. Creating the Contest(水题)
直接水过 #include<iostream> #include<algorithm> using namespace std; ; int a[maxn]; int n, u ...
- Codeforces 1029B. Creating the Contest 动态规划O(nlogn)解法 及 单调队列O(n)解法
题目链接:http://codeforces.com/problemset/problem/1029/B 题目大意:从数组a中选出一些数组成数组b,要求 b[i+1]<=b[i]*2 . 一开始 ...
- Codeforces Round #442 (Div. 2)A,B,C,D,E(STL,dp,贪心,bfs,dfs序+线段树)
A. Alex and broken contest time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #442 A Alex and broken contest【字符串/常量数组/string类】
A. Alex and broken contest time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #506 (Div. 3) 题解
Codeforces Round #506 (Div. 3) 题目总链接:https://codeforces.com/contest/1029 A. Many Equal Substrings 题意 ...
随机推荐
- SpringMVC URL模板模式映射
使用@RequestMaping和@PathVariable 组合使用 通过 @PathVariable 可以将 URL 中占位符参数绑定到控制器处理方法的入参中:URL 中的 {xxx} 占位符可 ...
- 二十九、MySQL 序列使用
MySQL 序列使用 MySQL 序列是一组整数:1, 2, 3, ...,由于一张数据表只能有一个字段自增主键, 如果你想实现其他字段也实现自动增加,就可以使用MySQL序列来实现. 本章我们将介绍 ...
- 本地已经存在的项目如何跟github发生关联
切换到本地项目地址 git init 初始化项目.该步骤会创建一个 .git文件夹是附属于该仓库的工作树. git add . git commit -am 'initial commit' git ...
- 网络编程-osi七层
一.操作系统基础 操作系统:(Operating System,简称OS)是管理和控制计算机硬件与软件资源的计算机程序,是直接运行在“裸机”上的最基本的系统软件,任何其他软件都必须在操作系统的支持下才 ...
- 12、python中的函数(高阶函数)
一.高阶函数 函数实际上也是一个对象,所以也能由变量指向一个函数对象,实际上函数名就是一个变量名.那么函数是传入变量作为参数的,如果传入的变量指向的是函数对象,这种函数就叫高阶函数. 高阶函数就是传入 ...
- 6、python中的元组
元组(tuple)是python中有序.不可变的数据结构.元组还是python四种数据结构中唯一一种不可变的数据结构. 一.前言 元组在很多方面都变现得跟列表一样,除了列表储存得对象是可变得,而元组储 ...
- Storm: 性能优化 (转载)
Storm 性能优化 原文地址:http://www.jianshu.com/p/f645eb7944b0 目录 场景假设 调优步骤和方法 Storm 的部分特性 Storm 并行度 Storm 消 ...
- hashlib加密模块
python hashlib密码加密 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/dss_dssssd/article/details/828 ...
- TCP/IP网络编程之进程间通信
进程间通信基本概念 进程间通信意味着两个不同进程间可以交换数据,为了完成这一点,操作系统中应提供两个进程可以同时访问的内存空间.但我们知道,进程具有完全独立的内存结构,就连通过fork函数创建的子进程 ...
- loj2058 「TJOI / HEOI2016」求和
推柿子 第二类斯特林数的容斥表达 fft卡精度就用ntt吧qwq. #include <iostream> #include <cstdio> using namespace ...