日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Most socially-distanced subsequence CodeForces - 1364B(贪心)

發(fā)布時間:2023/12/15 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Most socially-distanced subsequence CodeForces - 1364B(贪心) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Given a permutation p of length n, find its subsequence s1, s2, …, sk of length at least 2 such that:

|s1?s2|+|s2?s3|+…+|sk?1?sk| is as big as possible over all subsequences of p with length at least 2.
Among all such subsequences, choose the one whose length, k, is as small as possible.
If multiple subsequences satisfy these conditions, you are allowed to find any of them.

A sequence a is a subsequence of an array b if a can be obtained from b by deleting some (possibly, zero or all) elements.

A permutation of length n is an array of length n in which every element from 1 to n occurs exactly once.

Input
The first line contains an integer t (1≤t≤2?104) — the number of test cases. The description of the test cases follows.

The first line of each test case contains an integer n (2≤n≤105) — the length of the permutation p.

The second line of each test case contains n integers p1, p2, …, pn (1≤pi≤n, pi are distinct) — the elements of the permutation p.

The sum of n across the test cases doesn’t exceed 105.

Output
For each test case, the first line should contain the length of the found subsequence, k. The second line should contain s1, s2, …, sk — its elements.

If multiple subsequences satisfy these conditions, you are allowed to find any of them.

Example
Input
2
3
3 2 1
4
1 3 4 2
Output
2
3 1
3
1 4 2
Note
In the first test case, there are 4 subsequences of length at least 2:

[3,2] which gives us |3?2|=1.
[3,1] which gives us |3?1|=2.
[2,1] which gives us |2?1|=1.
[3,2,1] which gives us |3?2|+|2?1|=2.
So the answer is either [3,1] or [3,2,1]. Since we want the subsequence to be as short as possible, the answer is [3,1].
思路:根據(jù)數(shù)組,可以發(fā)現(xiàn),選取峰值就是最優(yōu)的。

代碼如下:

#include<bits/stdc++.h> #define ll long long using namespace std;const int maxx=1e5+100; int a[maxx]; int vis[maxx]; int n;int main() {int t;scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%d",&a[i]),vis[i]=0;vis[1]=1;int cnt=1;for(int i=2;i<=n;){int j=i;if(a[i]>a[i-1]) while(j<=n&&a[j]>a[j-1]) j++;else while(j<=n&&a[j]<a[j-1]) j++;vis[j-1]=1;cnt++;i=j;}cout<<cnt<<endl;for(int i=1;i<=n;i++) if(vis[i]) cout<<a[i]<<" ";cout<<endl;}return 0; }

努力加油a啊,(o)/~

總結(jié)

以上是生活随笔為你收集整理的Most socially-distanced subsequence CodeForces - 1364B(贪心)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲欧美综合久久 | av成人动漫| 日日操夜夜操天天操 | 香蕉视频在线免费看 | 色一情一伦一子一伦一区 | 国产精品www在线观看 | 成人乱码一区二区三区 | 久久桃色| 国产精品一区三区 | 久久丝袜视频 | 超碰丝袜 | 国产精品久久久久久免费观看 | 波多野结衣中文字幕久久 | 欧美性xxxxx极品少妇 | 国产欧美精品一区二区色综合朱莉 | 国产精品高潮呻吟久久aⅴ码 | 日少妇av | 日韩av一区二区在线观看 | 胖女人做爰全过程 | 成人免费视频免费观看 | 欧美丰满美乳xxⅹ高潮www | 中文字幕国内自拍 | 黄色一级片毛片 | 波多野结衣潜藏淫欲 | 国产人妻人伦精品1国产丝袜 | 蜜桃av噜噜一区二区三区网址 | 超碰免费在线播放 | 久久久亚洲精品无码 | 韩国日本欧美一区 | 亚洲视频一二三四 | 亚洲成人免费视频 | а√天堂8资源在线官网 | 9色视频在线观看 | 欧美日韩第一页 | av电影一区二区三区 | 亚洲精品中文字幕在线播放 | 中出 在线| 日韩中文字幕一区 | 91日批| 日韩精品一线二线三线 | 无码国产精品96久久久久 | 日本后进式猛烈xx00动态图 | 在线a| 午夜av免费 | 小柔的裸露日记h | 日本在线观看视频网站 | 亚洲特黄特色 | 欧美影院在线 | caopeng在线| 美女主播福利视频 | 日韩av午夜| 久久久久久婷婷 | 91少妇丨porny丨 | 巨乳动漫美女 | jizz中国少妇高潮出水 | 五月天开心网 | 狠狠操一区二区 | 日本性欧美 | 欧美日韩中文一区 | 日韩激情床戏 | 亚洲黄色在线视频 | 久久99色| 婷婷操| 欧美中文字幕视频 | 成年人免费大片 | 日韩精品综合 | 成人国产在线观看 | 日韩免费观看一区二区 | 成人做受视频试看60秒 | 成人免费视频网站在线看 | 手机看片一区二区 | 老女人丨91丨九色 | 国产又粗又黄又爽的视频 | 五月天中文字幕在线 | 日本久久久久久 | 国内精品二区 | 538在线精品 | 波多野结衣一区二区三区 | 国产色网 | 黄片毛片 | 波多野结衣一区二区在线 | 能看的av | 国产福利精品在线观看 | 久久看片 | 亚洲伊人久久久 | 久久深夜视频 | 娇妻高潮浓精白浆xxⅹ | 丰满放荡岳乱妇91ww | 玖玖玖国产精品 | 国模精品一区 | 性欧美ⅴideo另类hd | 亚洲男人第一网站 | 久久久久久久一区二区 | 人人爱人人艹 | 成人福利在线播放 | 福利片网址 | 国产白浆一区二区 | 亚洲av永久无码精品一百度影院 | 2025av在线播放 |