CCF 201604-1 折点计数 (水题,暴力)
给定n个整数a1, a2, …, an表示销售量,请计算出这些天总共有多少个折点。
为了减少歧义,我们给定的数据保证:在这n天中相邻两天的销售量总是不同的,即ai-1≠ai。注意,如果两天不相邻,销售量可能相同。
第二行包含n个整数,用空格分隔,分别表示a1, a2, …, an。
5 4 1 2 3 6 4
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define frer freopen("in.txt", "r", stdin)
#define frew freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e3 + 5;
const int mod = 1e9 + 7;
const char *mark = "+-*";
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int a[maxn]; int main(){
while(scanf("%d", &n) == 1){
int ans = 0;
for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
if(n < 3) printf("0\n");
else{
bool ok = a[1] > a[0] ? true : false;
for(int i = 2; i < n; ++i)
if(a[i] < a[i-1] && ok) ++ans, ok = false;
else if(a[i] > a[i-1] && !ok) ++ans, ok = true; printf("%d\n", ans);
}
}
return 0;
}
CCF 201604-1 折点计数 (水题,暴力)的更多相关文章
- CCF认证考试——折点计数
描述:简单题 #include<iostream> using namespace std; int main() { ], n, count = ; cin >> n; ; ...
- CCF CSP 201604-1 折点计数
题目链接:http://118.190.20.162/view.page?gpid=T42 问题描述 试题编号: 201604-1 试题名称: 折点计数 时间限制: 1.0s 内存限制: 256.0M ...
- CCF 201409-1 相邻数对 (水题)
问题描述 给定n个不同的整数,问这些数中有多少对整数,它们的值正好相差1. 输入格式 输入的第一行包含一个整数n,表示给定整数的个数. 第二行包含所给定的n个整数. 输出格式 输出一个整数,表示值正好 ...
- POJ 1013 小水题 暴力模拟
Counterfeit Dollar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 35774 Accepted: 11 ...
- zzulioj--1707--丧心病狂的计数(水题)
1707: 丧心病狂的计数 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 237 Solved: 105 SubmitStatusWeb Board ...
- AcWing 230. 排列计数 水题(组合数+错排)打卡
题目:https://www.acwing.com/problem/content/232/ #include<bits/stdc++.h> #define ll long long #d ...
- [hdu5203]计数水题
思路:把一个木棍分成3段,使之能够构成三角形的方案总数可以这样计算,枚举一条边,然后可以推公式算出当前方案数.对于已知一条边的情况,也用公式推出.用max和min并维护下,以减少情况数目. #prag ...
- [Usaco2008 Feb]Line连线游戏[暴力][水题]
Description Farmer John最近发明了一个游戏,来考验自命不凡的贝茜.游戏开始的时 候,FJ会给贝茜一块画着N (2 <= N <= 200)个不重合的点的木板,其中第i ...
- CCF 2016-04-1 折点计数
CCF 2016-04-1 折点计数 题目 问题描述 给定n个整数表示一个商店连续n天的销售量.如果某天之前销售量在增长,而后一天销售量减少,则称这一天为折点,反过来如果之前销售量减少而后一天销售量增 ...
随机推荐
- 微信热补丁 Tinker 的实践演进之路
http://dev.qq.com/topic/57ad7a70eaed47bb2699e68e http://dev.qq.com/topic/57a30878ac3a1fb613dd40eb ht ...
- C递归算法与栈的分析,非全然二叉树遍历分析---ShinePans
对于递归,这里面的分析最好当然是用图形的方式来分析了.这里来总结一下 1.首先对于栈的理解: 先进后出,后进先出 先进后出 2.在进行非全然二叉树的存储之后,我们要做的是对其 ...
- ios开发动物园管理 继承多态的实现
// // main.m // 继承 // // #import <Foundation/Foundation.h> #import "Animal.h" #impor ...
- C语言预处理条件语句的 与或运算
1.#ifdef 与或运算 #ifdef (MIN) && (MAX) ----------------------------错误使用 #if defined(MIN) & ...
- Discuz系列1:安装
http://www.discuz.net/forum.php 官网,点击“Discuz! 程序发布” 代码库: https://git.oschina.net/ComsenzDiscuz/D ...
- IOS UIScrollView滚动到指定位置
[mScrollView setContentOffset:CGPointMake(0,200) animated:YES];
- MVC入门——删除页
添加Action DeleteUserInfo using System; using System.Collections.Generic; using System.Linq; using Sys ...
- java内部类和静态内部类的区别
1 相同点 使用的时候,import的时候,除了包名,还要带外部类. 2 不同点 2.1 对象创建的方式不同 静态内部类创建对象的时候,独立于外部类及其对象,就好像它是一个独立的类,可以和外部类一样使 ...
- contentprovider基础
程序启动后,只要再manifest当中注册上,就会执行PersonProvider()创建一个对象
- 【bzoj2809】dispatching
这题的最优解法是可并堆,从上往下合并及删点,标准的O(nlogn)解法. 为了练习主席树,特用主席树写一发,可以按dfs序建立主席树,对每个子树进行查询. 总时间5232毫秒,要垫底了... 看来需要 ...