CodeForces 702 A Maximum Increase (贪心,高效算法)
题意:给定 n 个数,问你连续的最长的序列是几个。
析:从头扫一遍即可。
代码如下:
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 1e5 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int a[maxn]; int main(){
cin >> n;
for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
int ans = 1;
int s = 0, e = 2;
int cnt = 0;
a[0] = 0;
while(e <= n){
cnt = 1;
while(e <= n && a[e] > a[e-1]){ ++cnt; ++e; }
ans = max(ans, cnt);
++e;
} cout << ans << endl;
return 0;
}
CodeForces 702 A Maximum Increase (贪心,高效算法)的更多相关文章
- codeforces 702A A. Maximum Increase(水题)
题目链接: A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input sta ...
- 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 ...
- 深入N皇后问题的两个最高效算法的详解 分类: C/C++ 2014-11-08 17:22 117人阅读 评论(0) 收藏
N皇后问题是一个经典的问题,在一个N*N的棋盘上放置N个皇后,每行一个并使其不能互相攻击(同一行.同一列.同一斜线上的皇后都会自动攻击). 一. 求解N皇后问题是算法中回溯法应用的一个经典案例 回溯算 ...
- cf702A Maximum Increase
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- [Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
- CVPR2020论文介绍: 3D 目标检测高效算法
CVPR2020论文介绍: 3D 目标检测高效算法 CVPR 2020: Structure Aware Single-Stage 3D Object Detection from Point Clo ...
- Codeforces - 702A - Maximum Increase - 简单dp
DP的学习计划,刷 https://codeforces.com/problemset?order=BY_RATING_ASC&tags=dp 遇到了这道题 https://codeforce ...
- Codeforces 702A Maximum Increase(dp)
题目链接:http://codeforces.com/problemset/problem/702/A 题意: 给你N个数,a[0], a[1], a[2], ....., a[n-1],让你找出最长 ...
随机推荐
- 多个MapReduce作业相互依赖时,使用JobControl进行管理
要处理复杂关系的数据,一个工程里面绝对不止一个MapReduce作业,当有多个MapReduce作业时, 并且每个作业之间有依赖关系,所谓的依赖就是一个作业得到的结果是另外一个作业的输入, ...
- OE中admin的内置帐号
在OE中admin的内置帐号为SUPERUSER_ID,可以用来直接做判断登录用户是否admin from openerp import SUPERUSER_ID if uid == SUPERUSE ...
- Ubuntu中文输入法的安装
Ubuntu上的输入法主要有小小输入平台(支持拼音/二笔/五笔等),Fcitx,Ibus,Scim等.其中Scim和Ibus是输入法框架. 在Ubuntu的中文系统中自带了中文输入法,通过Ctrl+S ...
- ubuntu16.04 64位server安装php7
You can do the following: sudo apt-get install python-software-properties sudo LC_ALL=C.UTF-8 add-ap ...
- yaf框架流程三
路由的原理请看http://yaf.laruence.com/manual/yaf.routes.html这个链接 要点:路由的顺序是堆栈模式的,及最后添加的路由规则最优先.由上两篇可知,定义的第一条 ...
- phonegap 退出确认
实现 再按一次退出 ,这里只针对 主active继承 DroidGap 或者CordovaActive 以下有2种 方案1: 重写CordovaWebView类 新建类NobackWebView p ...
- $(function(){})和jQuery(function(){})
$(function(){})和jQuery(function(){})有没有区别,群里的屌丝争吵起来,各自讲着各种理论大道理.但还是有人给出了简而有力的证明: 区分大小写(jQuery) 但jQue ...
- mysql 查询随机条记录的sql语句和php计算概率
最近在网上找了下mysql查询随机的几个sql,我把最终的记录下来. SELECT * FROM uchome_mtag AS a JOIN (SELECT MAX(tagid) AS id FROM ...
- 常用的Oracle数据库语句 (待更新完毕)
一.常用的查询语句 1.1 常用查询 查表中有多少个字段 select count(*) from user_tab_columns where table_name=upper('表名') 或者 s ...
- OFBIZ安装
1. 安装SVN客户端,从Apache OFBiz Source Repository获取OFBIZ下载地址.此处以12.04为例,下载地址为http://svn.apache.org/repos/a ...