博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces-234C Weather
阅读量:4629 次
发布时间:2019-06-09

本文共 2830 字,大约阅读时间需要 9 分钟。

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.
Sample test(s)
Input
4
-1 1 -2 1
Output
1
Input
5
0 -1 1 2 -5
Output
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.

题目意思:

给你一个n,输入n个数使 k (1≤kn-1) &&t1<0,t2<0,...,tk<0 and tk+1>0,tk+2>0,...,tn>0.

即前面为负数,后面为正。。但不能全为正 或 全为负。。。

刚开始自己写的时候,是进行遍历,依次计算出a为负数时,a前面有多少>=0的数,和多少<=0的数。。然后相加,存起来。。

后来看结题报告。。感觉自己的方法太俗了。。。。

仿照神人的思路写的。。

#include"stdio.h"#include"string.h"#define MAX 10001int main(){	int ans,i,n;	int a[MAX],sum1[MAX],sum2[MAX];	while(scanf("%d",&n)!=-1)	{		ans=MAX;		memset(sum1,0,sizeof(sum1));		memset(sum2,0,sizeof(sum2));		scanf("%d",&a[1]);		for(i=2;i
=0)sum1[i]++; } scanf("%d",&a[n]); for(i=n-1;i>=2;i--) { sum2[i]=sum2[i+1]; if(a[i]<=0)sum2[i]++; } ans=MAX*100; for(i=1;i
sum1[i]+sum2[i+1]) ans=sum1[i]+sum2[i+1]; } if(a[1]>=0)ans++; if(a[n]<=0)ans++; printf("%d\n",ans); } return 0;}

转载于:https://www.cnblogs.com/yyf573462811/archive/2012/11/15/6365152.html

你可能感兴趣的文章
ssh远程操作服务器
查看>>
树莓派Android Things物联网开发:创建一个Things项目
查看>>
GIT使用方法
查看>>
第三阶段 10_JavaWeb基础_
查看>>
裁员浪潮,互联网人该何去何从?
查看>>
Python Day 01
查看>>
Android5.0之CoordinatorLayout的使用
查看>>
U盘安装Ubuntu14.4时遇到分区问题记录
查看>>
servlet工作原理解析
查看>>
api工程IOS学习:在IOS开发中使用GoogleMaps SDK
查看>>
函数功能MATLAB
查看>>
Bzoj1123 Blockade
查看>>
Python之Mysql及SQLAlchemy操作总结
查看>>
数据库搜索与索引
查看>>
python3 面向对象(一)
查看>>
配件商城项目总结
查看>>
关于变量名前面加m的问题
查看>>
腾讯Bugly异常崩溃SDK接入
查看>>
安装centos后无法引导启动windows7的解决方法
查看>>
AutoMapper用法
查看>>