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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

A. A Prank

發布時間:2025/4/16 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 A. A Prank 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題鏈接:A. A Prank

題意:給定一個長度為n的遞增序列數組,你可以進行刪除任意連續序列的操作,要求刪除之后還可以還原該數組,輸出最大刪除數。

? ? ? ? ?? 例如:n = 6

? ? ? ? ? ? ? ? ? ?? 數組 = {1,3,4,5,6,9}

? ? ? ? ? ? ? ? ? ?? 可以刪除數字4,5,此時可以還原

數據范圍:? n <= 100 ? ? ? ? ? ? ? ? ?? 1 <= a[i] <= 1000

自我理解:此題很坑,細節也很多,如果只用純模擬的話,必須考慮很多種情況。有結果為0的情況,結果為連續數組個數 - 2,

? ? ? ? 結果為連續數組個數 - 1的情況

?

題解:如果三個三個為一組判斷是否連續,就可避免很多種判斷。

? ? ? ? ? 數組從1位置開始到位置。a[0] = 0, ?? a[n+1] = 1000, ? 循環從0到n+1。

?

純模擬

#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<string>using namespace std;int a[110];int n;int main() {scanf("%d", &n);for(int i = 0; i < n; i++) scanf("%d", &a[i]);int l = 0, r;int t = 0;int res = 0;int ans = 0;for(int i = 1; i <= n; i++){if(a[i] - a[i-1] == 1){ans++;} else{res = ans + 1;int temp;r = i - 1;l = r - res + 1;if(res <= 1||(res == 2&&a[n-1] < 1000&&a[0] > 1)) temp = 0;else if((l == 0&&r == n-1&&a[r] == n)||(l == 0&&r == n-1&&a[r] == 1000)||(l == 0&&r < n-1&&l != r&&a[r] == res)||(l > 0&&r == n-1&&a[r] == 1000)) temp = res - 1;else temp = res - 2;t = max(t, temp);ans = 0;}}printf("%d\n", t);return 0; }

?

思維,技巧(三個三個判斷模擬)

#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<string>using namespace std;int a[110];int n;int main() {scanf("%d", &n);for(int i = 1; i <= n; i++) scanf("%d", &a[i]);a[n+1] = 1001;int c = 0;int ans = 0;for(int i = 1; i <= n+1; i++){if(a[i+1] - a[i-1] == 2){c++;//printf("******* %d\n", c);} else{ans = max(ans, c);c = 0;} }printf("%d\n", ans);return 0; }

?

總結

以上是生活随笔為你收集整理的A. A Prank的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。