51nod 修改数组
第1行:一个数N表示序列的长度(1 <= N <= 100000)。
第2 - N + 1行:每行1个数,对应数组元素。(0 <= A[i] <= 10^9)
输出最少需要修改几个数使得整个数组是严格递增的。
5
1
2
2
3
4
3 分析:a[i]-i<=a[j]-j(i<j),并且a[i]-i>=0,在此基础上对他求最长不降子序列即可;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t;
multiset<int>p;
multiset<int>::iterator it;
void add(int x)
{
if(x<)return;
it=p.upper_bound(x);
if(it!=p.end())p.erase(it);
p.insert(x);
}
int main()
{
int i,j;
scanf("%d",&n);
rep(i,,n)scanf("%d",&j),add(j-i);
printf("%d\n",n-p.size());
//system("Pause");
return ;
}
51nod 修改数组的更多相关文章
- 51Nod 1294 修改数组 —— LIS
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1294 1294 修改数组 题目来源: HackerRank ...
- 51nod 1294 :修改数组 && HDU 5256:序列变换
1294 修改数组 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 160 难度:6级算法题 收藏 取消关注 给出一个整数数组A,你可以将任何一个数修 ...
- Java修改数组长度
java中没有关于修改数组长度的api,在此本人提供了修改数组长度的两个函数:arrayAddLength()和arrayReduceLength().详细见代码. [java] view plai ...
- 51nod1294 修改数组
看题解的...就是将必须要修改的数去掉后求最长的不递减子序列. upper_bound+lower_bound要理解.有时候-1有时候不用是有原因的. #include<cstdio> # ...
- 51nod 1270 数组的最大代价
1270 数组的最大代价题目来源: HackerRank基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 数组A包含N个元素A1, A2......AN.数组B包含N ...
- js递归遍历多维数组并在修改数组的key后返回新的多维数组
我司最近正在用VUE做一个基于用户权限显示不同左侧菜单的后台管理系统,接口会根据用户的权限不同返回不同的菜单名称.URL等,前端要将这些菜单名称及URL动态添加到系统的左侧,这里就用到了vue-rou ...
- 【Java】 剑指offer(2) 不修改数组找出重复的数字
本文参考自<剑指offer>一书,代码采用Java语言. 更多:<剑指Offer>Java实现合集 题目 在一个长度为n+1的数组里的所有数字都在1到n的范围内,所以数组中至少 ...
- PHP 中如何创建和修改数组?
PHP中使用array来创建一个数组:array( key=>value , key=>value …… )用方括号的语法来修改数组:$arr[] = value 例如:$arr = ar ...
- 《剑指offer》第三_二题(不修改数组找出重复的数字)
// 面试题3(二):不修改数组找出重复的数字 // 题目:在一个长度为n+1的数组里的所有数字都在1到n的范围内,所以数组中至 // 少有一个数字是重复的.请找出数组中任意一个重复的数字,但不能修改 ...
随机推荐
- VBS脚本合集(自制脚本)
一.视频搜索器选择: Selectitem() '######################################### Function Selectitem() 'Set Vedio ...
- 关于LR监视Windows和linux的说明
一.监控windows系统: 1.监视连接前的准备工作 1)进入被监视windows系统,开启以下二个服务Remote Procedure Call(RPC) 和Remote Registry Ser ...
- Chapter 2 Open Book——4
I walked to Biology with more confidence when, by the end of lunch, he still hadn't showed. 经过中午饭之后我 ...
- js 放大镜用法bug解决
<img id="zoom_02" src='img/zhang5.jpg' data-zoom-image="img/zhang5p.jpg" /> ...
- centos 命令行 连接无线网卡
ifconfig wlan0 up 1 ifconfig wlan0 iwlist wlan0 scan wpa_passphrase naizhongnai naizhong >> /e ...
- differences between null pointer and void pointer.
These are two different concepts, you cannot compare them. What the difference between the skunk and ...
- 给table加边框的两种方法
<!DOCTYPE html><html><head><style>.a { border-spacing: 1px; background-color ...
- 缩放系列(三):一个可以手势缩放、拖拽、旋转的layout
弄了一个下午,终于搞出来了,PowerfulLayout 下面是一个功能强大的改造的例子: 可以实现以下需求: 1.两个手指进行缩放布局 2.所有子控件也随着缩放, 3.子控件该有的功能不能丢失(像b ...
- SQL添加表字段以及SQL查询表,表的所有字段名
通用式: alter table [表名] add [字段名] 字段属性 default 缺省值 default 是可选参数 增加字段: alter table [表名] add 字段名 smalli ...
- 关于cin.getline和cin.get
<C++ Primer Plus(第六版)> P124 第8题 #include <iostream> using namespace std; struct Pizza ...