zoukankan      html  css  js  c++  java
  • 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
    ");
            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
    ", ans);
            }
        }
        return 0;
    }
    
  • 相关阅读:
    ThinkPHP框架 做个简单表单 添加数据例子__ACTION__ __SELF__
    ThinkPHP框架 系统规定的方法查询数据库内容!!同时也支持原生的SQL语句!
    ThinkPHP框架 基础 链接数据库
    ThinkPHP框架 3.2.2 获取系统常量信息 连接数据库 命名空间的理解
    ThinkPHP框架 自定义 Empty 方法保护本地信息不被暴露!!!
    Smarty模板保留缓存
    this指向
    phpcms v9 的表单向导功能的使用方法 附多个案例
    phpcms标签整理_当前栏目调用
    转载]PhpCms V9调用指定栏目子栏目文章的两种方法
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5846906.html
Copyright © 2011-2022 走看看