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("in.txt","r",stdin);
#endif
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", h+i);
    }
    mn[n-1] = h[n-1];
    for(int i = n-2; i >= 0; i--){
        mn[i] = min(mn[i+1],h[i]);
    }
    int mx = h[0], ans = 1;
    for(int i = 1; i < n; i++){
        if(mx <= mn[i]) ans++;
        mx = max(h[i], mx);
    }
    printf("%d\n", ans);
    return 0;
}
时间: 2024-10-27 06:46:50

codeforce 599C Day at the Beach的相关文章

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 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 448C 木片填涂问题

题目大意:有多片木片需要填涂,可以每次横着涂一行,也可以一次涂一列,当然你涂一行时遇到中间长度不够高的木片,填涂到此中断 这题目运用dfs能更容易的解出,虽然还是十分不容易理解 1 #include <iostream> 2 3 using namespace std; 4 5 #define N 5010 6 int a[N],n; 7 8 int Min(int c,int d) 9 { 10 return c<d?c:d; 11 } 12 int dfs(int c,int d,i

Codeforce 水题报告(2)

又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数(n<=200). 首先很明显可能是区间dp,我们可以记f[i][j]为从i到j的这个多边形的三角剖分数,那么f[i][j]=f[i][k]*f[j][k]*(i,j,k是否为1个合格的三角形) CodeForces 438D:The Child and Sequence 描述:给一个序列,要求支持区

codeforce 285 div2 D 题解

codeforce 285 div2 D 题解 说明 这道题目是看了思路分析才知道的,关键问题在于数据量过大,需要快速检索的同时不能辅助空间过大. 因此利用了下面3种方法结合解决该问题 康拓展开与逆康拓展开 树状数组 二分查找 代码 /** * @brief Codeforces Round #285 (Div. 2) d * @file d.cpp * @author mianma * @created 2015/01/27 18:18 * @edited 2015/01/29 22:45 *

codeforce Pashmak and Buses(dfs枚举)

1 /* 2 题意:n个同学,k个车, 取旅游d天! 3 要求所有的学生没有两个或者两个以上的在同一辆车上共同带d天! 输出可行的方案! 4 5 对于d行n列的矩阵,第i行第j列表示的是第i天第j个同学所在的车号! 6 也就是保证所有行不全相同,即每一列都是不相同的! 7 如果每一列都不相同就是表示第j个同学(第j列)在这d天中不会和其他同学(列)在这d天中 都在同一辆车中! 8 9 思路:对于每一列我们枚举d天该学生所在的车号!它的下一列只保证有一个元素和它不同就行了!依次下去! 10 11

codeforce 605BE. Freelancer&#39;s Dreams

题意:给你n个工程,做了每个工程相应增长x经验和y钱.问你最少需要多少天到达制定目标.时间可以是浮点数. 思路:杜教思路,用对偶原理很简易.个人建议还是标准解题法,凸包+线性组合. 1 #include<iostream> 2 #include<string> 3 #include<algorithm> 4 #include<cstdlib> 5 #include<cstdio> 6 #include<set> 7 #include&

Codeforce 214 Div 2 B.Hometask

题目描述: Description Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? Y

[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