CodeForces 599C Day at the Beach
来源:互联网 发布:jquery 对象数组 编辑:程序博客网 时间:2024/05/17 07:22
FAQ | About Virtual Judge | Forum | Discuss | Open Source Project
题意:给你n个数字,然后让你求可以最大把他们分成几块。每块按照从小到大排序之后,这n个数就是有序的。
思想:比如前面有k个数位一块,那么这k个数满足的性质:这k个数的最大值<=后面的数的最小值(为了让所有的块排完序之后是有序的),也就是说最小的数一定为分在第一块中,以此类推。现在我们就要实现找出最大值和最小值,最大值应该为前面k个数的最大值,ma[i]表示前面i个数的最大值,最小值应该为后面开始算,mi[i]表示从i到n所有数的最小值
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<cctype>#include<stdio.h>#define min(a,b)(a<b?a:b)#define max(a,b)(a>b?a:b)#define INF 0x3f3f3f3ftypedef long long ll;#define N 110000int h[N],mi[N],ma[N];int main(){ int n,i; while(scanf("%d",&n)!=EOF) { for(i=0;i<n;i++) scanf("%d",&h[i]); ma[0]=h[0]; for(i=1;i<n;i++) { ma[i]=max(ma[i-1],h[i]); } mi[n-1]=h[n-1]; for(i=n-2;i>=0;i--) { mi[i]=min(mi[i+1],h[i]); } int ans=1; for(i=1;i<n;i++) { if(ma[i-1]<=mi[i]) ans++; } printf("%d\n",ans); } return 0;}
0 0
- codeforces 599C Day at the Beach
- Codeforces 599 C. Day at the Beach
- CodeForces 599C Day at the Beach
- Codeforces 599 C Day at the Beach
- Codeforces 599C Day at the Beach
- CodeForces 599C Day at the Beach
- codeforces 559C Day at the Beach
- Codeforces 599C Day at the Beach 【思维】
- CodeForces 599C Day at the Beach(RMQ)
- codeforces 599 C. Day at the Beach【思维】
- CodeForces 599 C. Day at the Beach(贪心)
- Codeforces 599C Day at the Beach【思维+优先队列】
- codeforce 599C Day at the Beach
- Codeforces #332 C. Day at the Beach (贪心)
- Codeforces Round #332 (Div. 2) C. Day at the Beach
- Codeforces Round #332 (Div. 2) C. Day at the Beach
- Codeforces Round #332 (Div. 2) C. Day at the Beach
- Codeforces Round #332 (Div. 2) C. Day at the Beach
- Linux 文件系统剖析
- 读取与解析XML数据
- Js判断参数(String,Array,Object)是否为undefined或者值为空
- Swift 学习2
- 第二章:快速入门
- CodeForces 599C Day at the Beach
- Android开发笔记之ViewPage实现导航页原理
- sort之结构体排序2
- codevs线段树练习5(双重标记)
- Java和C语言,C++语言主要差别
- mybatis分页插件
- HTML 5实现图像走马灯效果
- C++builder Property属性
- 为什么 Git 比 SVN 好