解题关键:对num进行排序,从前往后扫id,及时更新

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
#define maxn 50002
struct node{
ll num,id;
}a[maxn];
bool cmp(const node &a,const node &b){
return a.num<b.num||(a.num==b.num&&a.id<b.id);
}
int main(){
int n;
cin>>n;
for(int i=;i<n;i++) cin>>a[i].num,a[i].id=i;
sort(a, a+n, cmp);
ll mi=a[].id,ans=;
for(int i=;i<n;i++){
if(a[i].id>mi) ans=max(ans,a[i].id-mi);
else mi=a[i].id;
}
cout<<ans<<"\n";
return ;
}

[51nod1272]最大距离(贪心)的更多相关文章

  1. 51Nod 1272 最大距离 (栈或贪心)

    #include <cstdio> #include <queue> #include <cstring> #include <iostream> #i ...

  2. poj 3069 Saruman's Army (贪心)

    简单贪心. 从左边开始,找 r 以内最大距离的点,再在该点的右侧找到该点能覆盖的点.如图. 自己的逻辑有些混乱,最后还是参考书上代码.(<挑战程序设计> P46) /*********** ...

  3. poj 1328 贪心

    /* 贪心.... 处理处每个点按照最大距离在x轴上的映射 然后我们就有了一些线段 目的是选取尽量少的点 使得每个线段内都有点出现 我们按照左端点排序 然后逐一处理 假设第一个雷达安在第一个线段的右端 ...

  4. To Fill or Not to Fill (贪心)

    转自:https://www.cnblogs.com/XBWer/p/3866486.html With highways available, driving a car from Hangzhou ...

  5. 51Nod1367 完美森林 贪心

    原文链接https://www.cnblogs.com/zhouzhendong/p/51Nod1367.html 题目传送门 - 51Nod1367 题意 有一棵N个点的树,树中节点标号依次为0,1 ...

  6. PAT A1033 To Fill or Not to Fill (25 分)——贪心

    With highways available, driving a car from Hangzhou to any other city is easy. But since the tank c ...

  7. 【贪心】PAT 1033. To Fill or Not to Fill (25)

    1033. To Fill or Not to Fill (25) 时间限制 10 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 ZHANG, Gu ...

  8. 贪心(qwq)习题题解

    贪心(qwq)习题题解 SCOI 题解 [ SCOI2016 美味 ] 假设已经确定了前i位,那么答案ans一定属于一个区间. 从高位往低位贪心,每次区间查找是否存在使此位答案为1的值. 比如6位数确 ...

  9. PAT 1033. To Fill or Not to Fill (贪心)

    PAT-A的最后一题,最终做出来了... 是贪心,通过局部最优获得全局最优. 1. 将加油站按距离升序排序 2. 记录当前所在的加油站index,存有的汽油,花费.向后遍历全部 该站可抵达的加油站 3 ...

随机推荐

  1. 关于随机浏览头伪装fake-UserAgent

    使用: from fake_useragent import UserAgent ua = UserAgent() #ie浏览器的user agent print(ua.ie) Mozilla/5.0 ...

  2. IOS int NSInteger NSNumber区分

    1.NSNumber 是一个类继承于NSValue 即一个基本数据类型的集合 包括char a signed or unsigned char, short int, int, long int, l ...

  3. 【LeetCode】【找元素】Find First and Last Position of Element in Sorted Array

    描述: Given an array of integers nums sorted in ascending order, find the starting and ending position ...

  4. Data Structure Array: Find the minimum distance between two numbers

    http://www.geeksforgeeks.org/find-the-minimum-distance-between-two-numbers/ #include <iostream> ...

  5. 如何阻止form表单中的button按钮提交

    <form action="#" method="post"> <input type="text" name=" ...

  6. java语法糖---枚举

    java语法糖---枚举   在JDK5.0中提供了大量的语法糖,例如:自动装箱拆箱.增强for循环.枚举.泛型等.所谓“语法糖”就是指提供更便利的语法供程序员使用,只是在编译器上做了手脚,却没有提供 ...

  7. CentOS下查看文件和文件夹大小

    当磁盘大小超过标准时会有报警提示,这时如果掌握df和du命令是非常明智的选择. df可以查看一级文件夹大小.使用比例.档案系统及其挂入点,但对文件却无能为力. 当磁盘大小超过标准时会有报警提示,这时如 ...

  8. Java -- Swing 组件使用

    1. 示例1 public class Main { JFrame f = new JFrame(); Icon okIcon = new ImageIcon("/home/test/sta ...

  9. Codeforces 876C Classroom Watch:枚举

    题目链接:http://codeforces.com/contest/876/problem/C 题意: 定义函数:f(x) = x + 十进制下x各位上的数字之和 给你f(x)的值(f(x) < ...

  10. python自动化开发学习 进程, 线程, 协程

    python自动化开发学习 进程, 线程, 协程   前言 在过去单核CPU也可以执行多任务,操作系统轮流让各个任务交替执行,任务1执行0.01秒,切换任务2,任务2执行0.01秒,在切换到任务3,这 ...