zoukankan      html  css  js  c++  java
  • BZOJ 1588 营业额统计 set

    题目链接:

    https://www.lydsy.com/JudgeOnline/problem.php?id=1588

    题目大意:

    营业额统计 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况。 Tiger拿出了公司的账本,账本上记录了公司成立以来每天的营业额。分析营业情况是一项相当复杂的工作。由于节假日,大减价或者是其他情况的时候,营业额会出现一定的波动,当然一定的波动是能够接受的,但是在某些时候营业额突变得很高或是很低,这就证明公司此时的经营状况出现了问题。经济管理学上定义了一种最小波动值来衡量这种情况: 该天的最小波动值 当最小波动值越大时,就说明营业情况越不稳定。 而分析整个公司的从成立到现在营业情况是否稳定,只需要把每一天的最小波动值加起来就可以了。你的任务就是编写一个程序帮助Tiger来计算这一个值。 第一天的最小波动值为第一天的营业额。

    思路:

    用set模拟即可。

     1 #include<bits/stdc++.h>
     2 #define IOS ios::sync_with_stdio(false);//不可再使用scanf printf
     3 #define Max(a, b) ((a) > (b) ? (a) : (b))//禁用于函数,会超时
     4 #define Min(a, b) ((a) < (b) ? (a) : (b))
     5 #define Mem(a) memset(a, 0, sizeof(a))
     6 #define Dis(x, y, x1, y1) ((x - x1) * (x - x1) + (y - y1) * (y - y1))
     7 #define MID(l, r) ((l) + ((r) - (l)) / 2)
     8 #define lson ((o)<<1)
     9 #define rson ((o)<<1|1)
    10 #pragma comment(linker, "/STACK:102400000,102400000")//栈外挂
    11 using namespace std;
    12 inline int read()
    13 {
    14     int x=0,f=1;char ch=getchar();
    15     while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
    16     while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    17     return x*f;
    18 }
    19 
    20 typedef long long ll;
    21 const int maxn = 1000000 + 10;
    22 const int MOD = 1000000007;//const引用更快,宏定义也更快
    23 const ll INF = 1e16;
    24 const double eps = 1e-6;
    25 
    26 set<int>s;
    27 set<int>::iterator it;
    28 int main()
    29 {
    30     int n, x;
    31     scanf("%d", &n);
    32     int ans = 0, first = 1;
    33     while(n--)
    34     {
    35         scanf("%d", &x);
    36         if(s.count(x))continue;
    37         s.insert(x);
    38         if(first)first = 0, ans = x;
    39         else
    40         {
    41             it = s.find(x);
    42             int tmp = 1e9 + 7;
    43             if(it != s.begin())
    44             {
    45                 it--;
    46                 tmp = min(tmp, x - (*it));
    47                 it++;
    48             }
    49             it++;
    50             if(it != s.end())
    51             {
    52                 tmp = min(tmp, (*it) - x);
    53             }
    54             ans += tmp;
    55             //cout<<ans<<endl;
    56         }
    57     }
    58     cout<<ans<<endl;
    59     return 0;
    60 }
  • 相关阅读:
    CF1438D Powerful Ksenia(构造题)
    AT5759 ThREE(构造)
    浏览器中上面三个字,下面两个字 两端对齐(转)
    luoguP3372 【模板】线段树 1
    大数据-linux实操篇-组管理和权限管理
    大数据-linux实操篇-解压和压缩类指令
    大数据-linux实操篇-搜索查找类指令
    大数据-linux实操篇-文件目录类指令
    大数据-linux实操篇-帮助指令
    大数据-linux实操篇-实用指令(七个级别、忘记root密码)
  • 原文地址:https://www.cnblogs.com/fzl194/p/9671831.html
Copyright © 2011-2022 走看看