zoukankan      html  css  js  c++  java
  • Codeforces 1300E. Water Balance

    给你一个数列,有一个操作,将一段数字变成其和除以个数,求字典序最小的那一个,分析知,求字典序最小,就是求一个不下降序列,但我们此时有可以更改数字的操作,已知已经不下降的序列不会因为操作而变的更小,只有右边的数比左边的数小的时候才需要操作,那我们可以维护一个单调栈,依次加入数字,栈顶就是当前最右的数字,再维护一个长度信息,这样,每次加入一个数就能判断是否需要操作了,若需要操作,就更新长度和数字进行即可

    #include<bits/stdc++.h>
    using namespace std;
    #define lowbit(x) ((x)&(-x))
    typedef long long LL;
    
    const int maxm = 1e6+5;
    double q[maxm];
    int buf[maxm], len[maxm];
    
    
    void run_case() {
        int n;
        cin >> n;
        int top = 0;
        for(int i = 1; i <= n; ++i) cin >> buf[i];
        q[++top] = buf[1], len[1] = 1;
        for(int i = 2; i <= n; ++i) {
            double now = buf[i];
            int nowlen = 1;
            while(q[top] > now) {
                now = (now*nowlen+q[top]*len[top])/(nowlen+len[top]);
                nowlen += len[top--];
            }
            q[++top] = now, len[top] = nowlen;
        }
        for(int i = 1; i <= top; ++i)
            for(int j = 0; j < len[i]; ++j)
                cout << q[i] << "
    ";
    }
    
    int main() {
        ios::sync_with_stdio(false), cin.tie(0);
        cout.setf(ios_base::showpoint);cout.precision(10);
        //int t; cin >> t;
        //while(t--)
        run_case();
        cout.flush();
        return 0;
    }
    View Code
  • 相关阅读:
    C++11并发——多线程std::thread (一)
    css属性操作
    mustache使用
    layer常用方法代码
    layer使用
    java后台获取和js拼接展示信息
    生成二维码
    循环体中去除一部分特定的数据
    eclipse工具maven项目打包文件不是最新修改的
    sql server数据库备份单个表的结构和数据生成脚本
  • 原文地址:https://www.cnblogs.com/GRedComeT/p/12296140.html
Copyright © 2011-2022 走看看