CF1832C Contrast Value
题目传送门
题面
For an array of integersYou are given an array of integers
is not empty, i.e there is at least one element; is a subsequence of , i.e can be produced by deleting some elements from (maybe zero);- the contrast of
is equal to the contrast of .
What is the minimum possible size of the array
Input
The first line contains a single integer
The first line of each test case contains a single integer
The second line contains
The sum of
Output
For each test case, print a single integer — the minimum possible size of the array
题目大意
对于一个由整数
给你一个整数数组
不是空数组。 是 的子序列。 的对比度等于 的对比度。
数组
思路
观察
- 如果区间
单调递增,这一区间所贡献的对比度 ; - 如果区间
单调递减,这一区间所贡献的对比度 。
也就是说,当区间
代码
#include <bits/stdc++.h> #define int long long #define endl '\n' using namespace std; void solve() { int n, b = 0, ans = 1; cin >> n; vector<int> a(n); cin >> a[0]; for (int i = 1; i < n; i++) { cin >> a[i]; if (a[i] > a[i - 1] && b != 1) { ans++; b = 1; } if (a[i] < a[i - 1] && b != 2) { ans++; b = 2; } } cout << ans << endl; } signed main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { solve(); } return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】