Weather
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.
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.
Print a single integer — the answer to the given task.
4
-1 1 -2 1
1
5
0 -1 1 2 -5
2
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[][] = { {,},{,-},{-,},{,} };
const int maxn = ;
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 + ), pos(n + ,), neg(n + ,);
for (int i = ; i <= n; i++)
{
cin >> t[i];
pos[i] = pos[i - ];
neg[i] = neg[i - ];
if (t[i] >= )
pos[i]++;
if (t[i] <= )
neg[i]++;
}
int minn = INT_MAX;
for (int i = ; i <= n - ; i++)
{
minn = min(minn, neg[n] - neg[i] + pos[i]);
}
cout << minn;
return ;
}
Weather的更多相关文章
- [整理]Android开发(二)-Weather App
private class WeatherData{ private String _weatherDescription; private Integer _currentTemperature; ...
- Windows 10 Weather App无法正常显示解决方法
Weather动态磁贴显示Washington(不知是否和我的region设置有关系),打开应用却停留在输入需要搜索的天气.根据提示输入"Shanghai, China"并单击搜索 ...
- Java hour 52 Weather
采用jetty 后,默认的welcome-file-list 配置失效了,直接跳转到了struts2 的control 中去了. <welcome-file-list> <welco ...
- Java Hour 49 保存和查询历史的Weather
吾一直坚信,是需求的不断变化推动了架构的不断演变. 新的需求 能够查看指定日期的Weather,因为客户想要比较昨天和今天的天气情况,所以需要能够查询历史数据的功能. 1 能保存当前的天气到数据库 2 ...
- Java Hour 43 Weather ( 12 ) - 杭州 Show
终于从fastjson 的阴影中走出来了,接下去就是显示一个完整的天气信息了. 43.1 Weather Show 首先增加Model 中的属性. public class Weatherinfo { ...
- Java Hour 37 Weather ( 10 )
有句名言,叫做10000小时成为某一个领域的专家.姑且不辩论这句话是否正确,让我们到达10000小时的时候再回头来看吧. Hour 36 Weather 从失败的地方爬起来 在jsp 中,使用EL 表 ...
- Java Hour 32 Weather ( 5 ) struts2 – Action class
有句名言,叫做10000小时成为某一个领域的专家.姑且不辩论这句话是否正确,让我们到达10000小时的时候再回头来看吧. Hour 32 Struts2 Action 1 将action 映射到 ac ...
- Java Hour 29 Weather ( 2 ) Maven
有句名言,叫做10000小时成为某一个领域的专家.姑且不辩论这句话是否正确,让我们到达10000小时的时候再回头来看吧. Hour 29 Weather 界面 数据源采用上次取得的杭州天气的json. ...
- Java Hour 21 Weather
有句名言,叫做10000小时成为某一个领域的专家.姑且不辩论这句话是否正确,让我们到达10000小时的时候再回头来看吧. 本文作者Java 现经验约为21 Hour,请各位不吝赐教. 继续心情不佳,那 ...
- PYTHON WEATHER
小玩一下python强大的库文件,调api获取天气情况 #coding:utf-8 import urllib import json content = urllib.urlopen('http:/ ...
随机推荐
- 查看mysql是否锁表了
1.查看表是否被锁: (1)直接在mysql命令行执行:show engine innodb status\G. (2)查看造成死锁的sql语句,分析索引情况,然后优化sql. (3)然后show p ...
- word中模板的使用
新建一个word文档,修改样式库中的样式,比如各章节的标题正式格式.设计好后,将文件保存为word模板. 一般自定义的模板默认保存在”C:\Users\lizhe\Documents\自定义 Offi ...
- 搁置:vue-element-admin
初衷 了解桌面应用类前端搭建的解决方案 -------------------------------------------------------------------------------- ...
- Android_小账本_筛选功能的实现
昨天对小账本的相关功能做了完善,新增了筛选功能. 支持对类型.收支项.日期进行修改. 但暂时尚不完善,只能针对相关小项进行筛选,无法连续对小项的结果进行筛选.这一功能预计在本周三进行完善. 相关代码 ...
- Django中非视图函数获取用户对象
今天遇到了一个问题:在Django中怎么从非视图函数中获取用户对象?怎么保证不同的请求获取到不同的用户对象? 平常我们获取用户对象使用的是: request.user 不得不说,这确实很方便. 但是, ...
- php弱语言特性-计算科学计数法
php处理字符串时存在一个缺陷问题,如果字符串为“1e1”,本该是一个正常的字符串,但是php会将它认为是科学计数法里面的e: 也就是按照数学的科学计数法来说:1e1=10^1=10,因此php会把这 ...
- gitlab 备份和恢复
前言 gitlab这个代码托管工具真是强大,很多东西都是做好了直接用的. 这里就包括备份和恢复功能. 正文 备份 我们可以直接运行此命令,来进行备份. sudo gitlab-rake gitlab: ...
- 1级搭建类103-Oracle 12c 单实例 FS(12.2.0.1+RHEL 7)公开
项目文档引子系列是根据项目原型,制作的测试实验文档,目的是为了提升项目过程中的实际动手能力,打造精品文档AskScuti. 项目文档引子系列目前不对外发布,仅作为博客记录.如学员在实际工作过程中需提前 ...
- HBase Hive
Hbase数据管理 Hbase就是Hadoop database Hbase是列式数据库 因此Hbase特别适合寻找按照时间排序寻找Top n的场景 Hive数据管理 基于 Hadoop 文件系统的数 ...
- MATLAB用“fitgmdist”函数拟合高斯混合模型(一维数据)
MATLAB用“fitgmdist”函数拟合高斯混合模型(一维数据) 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 在MATLAB中“fitgmdis ...