CCF 201604-1 折点计数 (水题,暴力)

问题描述

  给定n个整数表示一个商店连续n天的销售量。如果某天之前销售量在增长,而后一天销售量减少,则称这一天为折点,反过来如果之前销售量减少而后一天销售量增长,也称这一天为折点。其他的天都不是折点。如下图中,第3天和第6天是折点。

  给定n个整数a1, a2, …, an表示销售量,请计算出这些天总共有多少个折点。
  为了减少歧义,我们给定的数据保证:在这n天中相邻两天的销售量总是不同的,即ai-1≠ai。注意,如果两天不相邻,销售量可能相同。

输入格式

  输入的第一行包含一个整数n。
  第二行包含n个整数,用空格分隔,分别表示a1, a2, …, an

输出格式

  输出一个整数,表示折点出现的数量。

样例输入

7
5 4 1 2 3 6 4

样例输出

2

评测用例规模与约定

  所有评测用例满足:1 ≤ n ≤ 1000,每天的销售量是不超过10000的非负整数。

析:只要记录前面的趋势,然后判断后来的趋势就好。

代码如下:

#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;
}
时间: 2024-08-02 11:04:19

CCF 201604-1 折点计数 (水题,暴力)的相关文章

CCF认证考试——折点计数

描述:简单题 #include<iostream> using namespace std; int main() { int i, j, a[1000], n, count = 0; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 1; i < n-1; i++) { if (a[i-1] < a[i] ) { if (a[i] > a[i + 1]) { count++;

poj 1164 The Castle dp区域计数水题

水题,直接贴代码. //poj 1164 //sep9 #include <iostream> using namespace std; int a[64][64]; int dp[64][64]; int n,m; const int west=1,north=2,east=4,south=8; void dfs(int x,int y) { dp[x][y]=1; if((a[x][y]&north)==0&&dp[x-1][y]==-1){ dfs(x-1,y);

[hdu5203]计数水题

思路:把一个木棍分成3段,使之能够构成三角形的方案总数可以这样计算,枚举一条边,然后可以推公式算出当前方案数.对于已知一条边的情况,也用公式推出.用max和min并维护下,以减少情况数目. 1 #pragma comment(linker, "/STACK:10240000,10240000") 2 3 #include <iostream> 4 #include <cstdio> 5 #include <algorithm> 6 #include

HDU ACM 5224 Tom and paper 水题+暴力枚举

分析:因为长和宽都是整数,所以枚举判断是不是整数,再取最小的即可. #include<iostream> #include<cmath> using namespace std; int main() { int min; int a,i,T; ios::sync_with_stdio(false); cin>>T; while(T--) { cin>>a; min=1000000000; for(i=1;i<=sqrt(a);i++) if(a%i=

AcWing 230. 排列计数 水题(组合数+错排)打卡

题目:https://www.acwing.com/problem/content/232/ #include<bits/stdc++.h> #define ll long long #define mod 1000000007 using namespace std; const int maxn = 1000005; ll dp[maxn],inv[maxn],fac[maxn],inv_fac[maxn]; void init() { inv[0]=inv[1]=inv_fac[0]=f

刷水题 堆

题目背景 众所周知,熊本熊的洛谷大号是kakakaka.有的时候熊本熊会在洛谷上面刷水题,但是熊本熊并不知道该怎么计划好自己的时间,他想让你来帮他计划一下. 题目大意 熊本熊今天一时兴起想刷n道水题,熊本熊有m个大脑,每个大脑都只能独立工作,也就是说,熊本熊可以在同一时间做m道题.由于熊本熊刷的水题都是topcoder,codeforces,usaco,CCF上最新出的水题,所以在熊本熊刷一道水题时,下一道水题可能还没有出来.又因为熊本熊又不会什么奇技淫巧,所以他完成每一道题都有一个特定的时间.

[Usaco2008 Feb]Line连线游戏[暴力][水题]

Description Farmer John最近发明了一个游戏,来考验自命不凡的贝茜.游戏开始的时 候,FJ会给贝茜一块画着N (2 <= N <= 200)个不重合的点的木板,其中第i个点 的横.纵坐标分别为X_i和Y_i (-1,000 <= X_i <=1,000: -1,000 <= Y_i <= 1,000). 贝茜可以选两个点画一条过它们的直线,当且仅当平面上不存在与画出直线 平行的直线.游戏结束时贝茜的得分,就是她画出的直线的总条数.为了在游戏 中胜出,

CCF - 201604-1 - 折点计数

问题描述 试题编号: 201604-1 试题名称: 折点计数 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 给定n个整数表示一个商店连续n天的销售量.如果某天之前销售量在增长,而后一天销售量减少,则称这一天为折点,反过来如果之前销售量减少而后一天销售量增长,也称这一天为折点.其他的天都不是折点.如下图中,第3天和第6天是折点. 给定n个整数a1, a2, -, an表示销售量,请计算出这些天总共有多少个折点. 为了减少歧义,我们给定的数据保证:在这n天中相邻两天的销售量

CodeForces 589I Lottery (暴力,水题)

题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cma