ZOJ 十六届浙江省赛H.singing everywhere

大一萌新,多多关照,(ɔˆ ³(ˆ⌣ˆc)
第一次写博客,啥也不会,各位大佬多多包涵

H.Singing Everywhere

思路:一开始比较懵,细心思考发现,若要想减少voice crack ,那么就必须删除峰值(也就是voice crack),但是只会减少1个或者2个或者不变,因为只能删除至多一个点,想到这里就可以敲代码了,减少两个的情况就是有两个相邻的并且相等的峰值,比如样例中1 9 1 9 8 1 0,此时删除两个9之间的1即可,减少一个的情况就是删除一个峰值,并且峰值删除以后他左右两边的不会变成新的峰值,不变的情况就是删除一个峰值它左右两边的数有一个变成新的峰值,等于没删,好了分析完了敲代码(没想到一次就Ac了)

#include<iostream>
#include<stdio.h>
#include<string>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<stack>
#include<set>
#include<vector>
using namespace std;
double a[100005];
int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int n;
		scanf("%d", &n);
		int location[100005];
		int ans = 0;
		for (int i = 0; i < n; i++)
		{
			scanf("%lf", &a[i]);
			if (i>=2)
			{
				int j = i - 1;
				if (a[j]>a[j - 1] && a[j] > a[j + 1])
				{
					location[ans++] = j;
					//cout << "#" << location[ans - 1];
				}
			}
		}
		int t = ans;
		for (int i = 0; i < t; i++)
		{
			int tans = t;
			int t1 = t;
			int t2 = t;
			int pre = location[i];
			if (a[pre] == a[pre+2])
			{
				tans -= 2;
				ans = tans;
				//cout << "******\n";
				break;
			}
			if (a[pre - 1 - 1] < a[pre]){}
			else t1--;
			if (a[pre - 1] == a[pre + 1])
			{
				t2--;
			}
			else if (a[pre - 1]>a[pre + 1] && a[pre - 2]>a[pre-1])
			{
				t2--;
			}
			else if (a[pre - 1]<a[pre + 1] && a[pre + 2]>a[pre + 1])
			{
				t2--;
			}
			else{}
			tans = t1 < t2 ? t1 : t2;
			if (ans>tans)ans = tans;
		}
		cout << ans << "\n";
	}
	return 0;
}

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值