【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 题意 ...
随机推荐
- ajax 的 promise
$.when().done().fail() $.when($.ajax("test1.html"),$.ajax("test2.html")).done(fu ...
- 【前端_js】js中数字字符串之间的比较
js中字符串间的比较是按照位次优先,比较各字符的ASCII大小,包括数字字符串之间的比较. 1.console.log("1"<"3");//true 2 ...
- Linux 系统性能
Linux:PS命令详解与使用 要对进程进行监测和控制,首先必须要了解当前进程的情况,也就是需要查看当前进程,ps命令就是最基本进程查看命令.使用该命令可以确定有哪些进程正在运行和运行的状态.进程 ...
- Python9-MySQL-MySQL-ORM框架-day48
ORM框架:AQLAlchemy-作用: 1.提供简单的规则 2.自动转换成SQL语句 -DB first: 手动创建数据库以及表 -> ORM框架 -> 自动生成类 code first ...
- 初识java,编写hello world语句
JDK: Java Develpment Kit - java开发工具包 JRE: Java Runtime Environment - java运行环境 JVM: Java Virtual Mach ...
- Storm: 遇到问题总结
1.没有ack : kafkaspout id 重复导致每次读最新没有数据. 2.由于storm提供的读取kafka的enternal工具存在bug,导致重复读取数据,致使数据不准确.storm bu ...
- [网站公告]又拍云API故障造成图片无法上传(已恢复)
大家好,18:00左右开始,又拍云API出现故障,调用图片上传API时出现错误:“The remote server returned an error: (403) Forbidden.”,造成图片 ...
- 非常全的API接口查询
http://www.apix.cn/services/category/3 https://www.showapi.com/ https://www.juhe.cn/docs http://deve ...
- IOS开发---菜鸟学习之路--(十四)-将BASE64图片转换成Image
本文基本全部都是代码 首先是.H文件 #import <Foundation/Foundation.h> @interface Base64AndImageHelp : NSObject ...
- 【Copy List with Random Pointer】cpp
题目: A linked list is given such that each node contains an additional random pointer which could poi ...