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:/ ...
随机推荐
- windows服务踩的坑
最近写了一个windows服务 有一些bug最后终于解决了还是写点经验把. 第一点.版本问题,因为是小白,第一次写windows服务,选择的是.net4.6.1的目标框架,因为我的电脑是windows ...
- 关于javascript中的内置函数
(1) parseInt()函数 语法:parseInt(string,[n]) 该函数主要将首位为数字的字符串转化为数字,若该字符串不是以数字开头,则返回NaN; n是用于指出字符串中的数据是几 ...
- disabled属性对form表单提交的影响
在form表单里,如果对input加入disabled="disabled"或disabled="true"等属性,form表单提交的时候,就不会传值到后台. ...
- linux 多并发 连接限制修改
1. 修改 ulimit -a 查看 open files 表示单个用户能打开的最大句柄 如果开发的高并发当个进程打开的句柄需要很大. 修改/etc/security/limits.conf 里面有 ...
- Apache Flink 任意 Jar 包上传致 RCE 漏洞复现
0x00 简介 Flink核心是一个流式的数据流执行引擎,其针对数据流的分布式计算提供了数据分布.数据通信以及容错机制等功能.基于流执行引擎,Flink提供了诸多更高抽象层的API以便用户编写分布式任 ...
- git文件冲突合并的报错:Your local changes to the following files would be overwritten by merge
记录一下在项目里使用git遇到代码冲突时的解决方法 问题:当我和我同事两个人改了相同的一个文件,他在我提交前提交了,这时候我就提交不了了,并且也pull不下来他的代码 会报错: Your local ...
- linux下安装setuptools
wget https://pypi.python.org/packages/07/a0/11d3d76df54b9701c0f7bf23ea9b00c61c5e14eb7962bb29aed866a5 ...
- springboot web - 建立路由
一. 测试代码 @RestController @RequestMapping("/book") public class BookController { @PostMappin ...
- Sass和Scss
Sass:https://www.sass.hk/ Sass是什么 Sass 是一款强化 CSS 的辅助工具,它在 CSS 语法的基础上增加了变量 (variables).嵌套 (nested rul ...
- 自定义结构体 Map
struct Hashmap{ ,maxe=; ],nxt[maxe+],w[maxe+]; ]; ;;} void Add(int x,int y){son[++E]=y;nxt[E]=lnk[x] ...