zoukankan      html  css  js  c++  java
  • Weather

    Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet.

    Our hero Vasya is quite concerned about the problems. He decided to try a little experiment and observe how outside daily temperature changes. He hung out a thermometer on the balcony every morning and recorded the temperature. He had been measuring the temperature for the last n days. Thus, he got a sequence of numbers t1, t2, ..., tn, where the i-th number is the temperature on the i-th day.

    Vasya analyzed the temperature statistics in other cities, and came to the conclusion that the city has no environmental problems, if first the temperature outside is negative for some non-zero number of days, and then the temperature is positive for some non-zero number of days. More formally, there must be a positive integer k (1 ≤ k ≤ n - 1) such that t1 < 0, t2 < 0, ..., tk < 0 and tk + 1 > 0, tk + 2 > 0, ..., tn > 0. In particular, the temperature should never be zero. If this condition is not met, Vasya decides that his city has environmental problems, and gets upset.

    You do not want to upset Vasya. Therefore, you want to select multiple values of temperature and modify them to satisfy Vasya's condition. You need to know what the least number of temperature values needs to be changed for that.

    Input

    The first line contains a single integer n (2 ≤ n ≤ 105) — the number of days for which Vasya has been measuring the temperature.

    The second line contains a sequence of n integers t1, t2, ..., tn (|ti| ≤ 109) — the sequence of temperature values. Numbers ti are separated by single spaces.

    Output

    Print a single integer — the answer to the given task.

    Examples
    input
    Copy
    4
    -1 1 -2 1
    output
    Copy
    1
    input
    Copy
    5
    0 -1 1 2 -5
    output
    Copy
    2
    Note

    Note to the first sample: there are two ways to change exactly one number so that the sequence met Vasya's condition. You can either replace the first number 1 by any negative number or replace the number -2 by any positive number.


    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <unordered_set>
    #include <unordered_map>
    #include <xfunctional>
    #define ll long long
    #define mod 998244353
    using namespace std;
    int dir[4][2] = { {0,1},{0,-1},{-1,0},{1,0} };
    const int maxn = 16;
    const long long inf = 0x7f7f7f7f7f7f7f7f;
    
    int main()
    {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        int n;
        cin >> n;
        vector<int> t(n + 1), pos(n + 1,0), neg(n + 1,0);
        for (int i = 1; i <= n; i++)
        {
            cin >> t[i];
            pos[i] = pos[i - 1];
            neg[i] = neg[i - 1];
            if (t[i] >= 0)
                pos[i]++;
            if (t[i] <= 0)
                neg[i]++;
        }
        int minn = INT_MAX;
        for (int i = 1; i <= n - 1; i++)
        {
            minn = min(minn, neg[n] - neg[i] + pos[i]);
        }
        cout << minn;
        return 0;
    }
  • 相关阅读:
    转--安装11g oracle
    数据可视化分析(柱状图、饼图、折线图、雷达图)
    2021双十一自动刷淘宝喵糖Auto.js脚本(安卓适用)
    最近升级了一下小老婆(8核 2x8G DDR3 128G SSD)
    [Orchard CMS系列] 创建主题(Writing a new theme)
    百度,你家云管家能靠谱点不?替你脸红!Shame on you!
    [解决]ASP.NET MVC 4/5 源码调试(source code debug)
    [解决]Kali Linux DHCP自动获取IP失败 坑爹的VMWare桥接
    SSRS 页面默认显示英文
    3.2、OSPF
  • 原文地址:https://www.cnblogs.com/dealer/p/12360968.html
Copyright © 2011-2022 走看看