codeforces 559C Day at the Beach
来源:互联网 发布:linux查看端口 编辑:程序博客网 时间:2024/05/21 07:58
题意:
给你一个大小为n序列,要求该序列分解成若干块,这若干块升序排列的时候要和原来大小为n的升序序列相同,问你最多可以分成多少块。
题解:
想了一晚上,要分块并且保持升序的话,必须是下一块的最小值大于当前块的最大值,但是我不相信我的思路是不是对的,所以躺在床上不敢去写,然后看了题解。。才发现我的思路是对的,,所以说,不要怕错,最重要是肯写。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int MAXN=100000+7;int a[MAXN],MAX[MAXN];int main(){ int n; while(~scanf("%d",&n)) { MAX[0]=0; for(int i=0;i<n;i++){ scanf("%d",&a[i]); MAX[i+1]=max(MAX[i],a[i]);//向右边移动一位,就可以与下面的实现min[i+1]与max[i]进行比较 } int ans=0,MIN=1e9; for(int i=n-1;0<=i;i--)//为什么从后面算最小值,你想一下,这组数据:5 6 7 8 9 1,就知道了 { MIN=min(MIN,a[i]); if(MIN>=MAX[i]) ans++; } printf("%d\n",ans); }}
阅读全文
0 0
- codeforces 559C Day at the Beach
- 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 #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
- Codeforces 599C Day at the Beach 【思维】
- CodeForces 599C Day at the Beach(RMQ)
- codeforces 599 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 599 C. Day at the Beach(贪心)
- RocketMQ源码解析-Consumer启动(2)
- easyUI中datagrid的fitColumns:true不起作用
- 浏览器的渲染:过程与原理
- 【Cassandra】bloom 过滤器
- 最简单有效的关于linux下配置Git操作免登录ssh公钥
- codeforces 559C Day at the Beach
- 将一个项目打成一个jar包,导入到另一个项目中并调用
- 开发者和创业者需要知道的一些东西
- Redis数据库课题研究
- git 403
- [Android优化]跟内存泄漏说再见
- codeforces 595C Warrior and Archer(博弈)
- 居中文字,Bootstrap按钮
- POI 3.17 读取Excel(模板)