C. Day at the Beach---cf559

http://codeforces.com/problemset/problem/599/C

题目大意: 有n个城堡的高度   让你最多分成几个块   每个块排过序之后 整体是按照升序来的

分析:  i之前的最大值只要小于等于i之后的最小值  ans++

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <math.h>
#include <ctype.h>

using namespace std;
#define memset(a,b) memset(a,b,sizeof(a))
#define N 500100
typedef long long  ll;
const double ESP = 1e-8;
#define INF 0xfffffff

int a[N];
int l[N],r[N];

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        memset(l,0);
        memset(r,0);
        memset(a,0);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            l[i]=max(l[i-1],a[i]);
        }
        r[n]=a[n];
        for(int i=n-1;i>0;i--)
        {
            r[i]=min(r[i+1],a[i]);
        }
        int sum=0;
        for(int i=1;i<=n;i++)
        {
            if(l[i]<=r[i+1])
                sum++;
        }
        printf("%d\n",sum+1);
    }
    return 0;
}
时间: 2024-07-28 15:46:22

C. Day at the Beach---cf559的相关文章

[Codeforces599C] Day at the Beach (贪心)

题目概述: One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles. At the end of the day there were

Codeforces 599C Day at the Beach(想法题,排序)

C. Day at the Beach One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles. At the end of the

codeforces 553 D Nudist Beach

题意大概是,给出一个图,保证每个点至少有一条边以及任意两点间最多一条边.很显然这个图有众多点集,若我们给每个点定义一个权值,那每个点集都有一个最小权值点,现在要求出一个点集,这个点集的最小权值点尽可能的大. 某个子集中,点的权值是这样算的,在该子集中这个点的度除以该点在图中的度. 乍看上去似乎无从下手. 可以显然知道的是,每个点在图中的权值是很容易算出来的,那我们尝试从图中进行删点,使得当前图的最小权值点的权值变大,显然可以知道要删除最小权值点,为什么呢?因为若删除次小权值点,若次小权值点跟最小

Codeforces 553D Nudist Beach(图论,贪心)

Solution: 假设已经选了所有的点. 如果从中删掉一个点,那么其它所有点的分值只可能减少或者不变. 如果要使若干步删除后最小的分值变大,那么删掉的点集中肯定要包含当前分值最小的点. 所以每次删掉一个点都记录一次最大值.取最大的情况输出就好. #include <bits/stdc++.h> using namespace std; const int N = 100009; vector<int> E[N], out; set<pair<double, int&g

CodeForces 599C Day at the Beach

预处理一下i到n的最小值. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int n; int a[100000+10]; int Min[100000+10]; int ans; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) sca

codeforce 599C Day at the Beach

Bi表示第i个块,那么就是说Bi max ≤ Bi+1 min,又因为Bi min ≤ Bi max, 因此只要判断前缀的最大值是否小于等于后缀. #include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e5+1; int h[maxn], n; int mn[maxn]; //#define LOCAL int main() { #ifdef LOCAL freopen(&quo

深度复数网络 Deep Complex Networks

转自:https://www.jiqizhixin.com/articles/7b1646c4-f9ae-4d5f-aa38-a6e5b42ec475  (如有版权问题,请联系本人) 目前绝大多数深度学习模型中的数学都是实数值的,近日,蒙特利尔大学.加拿大国家科学院-能源/材料/通信研究中心(INRS-EMT).微软 Maluuba.Element AI 的多名研究者(其中包括 CIFAR Senior Fellow Yoshua Bengio)在 arXiv 上发布了一篇 NIPS 2017(

Lingo 做线性规划 - Revenue Management

Reference: <An Introduction to Management Science Quantitative Approaches to Decision Making, Revised 13th Edition> Leisure Air has two Boeing 737-400 airplanes, one based in Pittsburgh and the other in Newark. Both airplanes have a coach section wi

2015南阳CCPC A - Secrete Master Plan 水题

D. Duff in Beach Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Master Mind KongMing gave Fei Zhang a secrete master plan stashed in a pocket. The plan instructs how to deploy soldiers on the four corners of the city wall. Unfortunately, w

根据76大细分词性对单词进行归组(二)

词性的重要性不言而喻,尤其是对于自然语言处理来说,哪怕就是记单词,根据词性对单词进行归组也是非常有帮助的. superword是一个Java实现的英文单词分析软件,主要研究英语单词音近形似转化规律.前缀后缀规律.词之间的相似性规律等等. 各大词性及其包括的词: 32.N-COUNT-COLL(可数集合名词) (词数:50) 1 aristocracy army array audience band 2 cast chapter command commission committee 3 co