【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 题意 ...
随机推荐
- 32-3题:LeetCode103. Binary Tree Zigzag Level Order Traversal锯齿形层次遍历/之字形打印二叉树
题目 给定一个二叉树,返回其节点值的锯齿形层次遍历.(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行). 例如: 给定二叉树 [3,9,20,null,null,15,7], 3 ...
- find cat sed awk 简单组合使用
find:查找 // .表示当前目录: /表示根目录: | 管道符: xargs表示将前面的搜索接口作为参数传递到后面的命令中:grep 过滤 // xxxx表示文件名 1.查找指定文件名的文 ...
- 如何查看连接到手机热点的ip地址
因为最近玩树莓派,需要手机做热点,然后用树莓派连接到这个热点上,苦于不知道树莓派被分配了什么样的ip地址,经过一番探索,我发现了两种办法, 安装一个 android terminal( 安卓命令行), ...
- LED室内定位算法:RSS,TOA,AOA,TDOA(转载)
转载自:https://blog.csdn.net/baidu_38197452/article/details/77115935 基于LED的室内定位算法大致可以分为四类: 1. 几何测量法 这种方 ...
- 1、python的基础
一.python组成 python程序的内容主要由变量.数据.关键字.操作符组成. 二.变量 在python中,变量指的是其指向的数据是可变的. 首先我们要了解一下python的内存管理.数据创建后就 ...
- (ADO.NET)关于C#中“配置”sqlite问题
配置打引号,只是因为觉得只是一些小问题,在此记录一下,第一次遇到还真有点手足无措,昨天到今天~终于可以开始放肆的写sqlite了. 好,第一个问题是引用已下载的system.data.sqlite.d ...
- 云中Active Directory是如何工作的?
[TechTarget中国原创] 微软公司1999年在Windows Server 2000中引入Active Directory功能.后期的Windows Server版本中陆续进行改善提升,Win ...
- Careercup - Microsoft面试题 - 5672369481842688
2014-05-12 06:27 题目链接 原题: Find the max height of a binary tree. 题目:计算二叉树的最大高度. 解法:最大高度?高度不就是最深的叶子节点到 ...
- linux环境搭建系列之jdk安装
JDK是java软件开发包的简称,要想开发java程序就必须安装JDK.没有JDK的话,无法编译Java程序. 前提: linux centOS6.6 64位操作系统 ROOT账号 安装包的获取:官网 ...
- day05_10 作业
bug1.0版本 #购物车程序 salary = int(input("请输入你的工资")) item = ['iphone6s','macbook','coffee','pyth ...