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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

C. Dominant Piranha(思维) Codeforces Round #677 (Div. 3)

發布時間:2023/12/20 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C. Dominant Piranha(思维) Codeforces Round #677 (Div. 3) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原題鏈接: https://codeforces.com/contest/1433/problem/C


測試樣例

input
6
5
5 3 4 4 5
3
1 1 1
5
4 4 3 4 4
5
5 5 4 3 2
3
1 1 2
5
5 4 3 5 5
output
3
-1
4
3
3
1

Note

The first test case of the example is described in the problem statement.

In the second test case of the example, there are no dominant piranhas in the aquarium.

In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4,4,5,4], then it can eat any other piranha in the aquarium.

題意: 在一個魚缸中有nnn條食人魚,它們從111nnn依次編號排列,其中尺寸為aia_iai?,有這樣的規則,若食人魚的尺寸大于旁邊的一條食人魚的尺寸,那么這條食人魚就可以吃了它并尺寸+1+1+1。請你找到一個優勢食人魚。(即經過一系列操作,這條食人魚是最終活下來的食人魚。)

解題思路: 這道題千萬別被樣例騙了。我們首先要知道什么時候無解,是不是當所有食人魚尺寸都相同時無解,那么其他情況是不是都有解呢?當然是,我們總能證明可以不斷使得一條尺寸最大的食人魚逐漸吃了其他的所有食人魚。那么我們關鍵要找到這一條食人魚。 那么為了答案的正確性,即通解,我們肯定是讓強者更強,試想:我們如果讓原先最大尺寸的食人魚再吃一條,它是不是要比其它的所有食人魚都要大了?那么結果是不是就出來了?我們只要找到一條最大尺寸的食人魚且它可以吃掉旁邊的任意一只食人魚即可。那么遍歷判斷即可得出答案。

AC代碼

/* *郵箱:unique_powerhouse@qq.com *blog:https://me.csdn.net/hzf0701 *注:文章若有任何問題請私信我或評論區留言,謝謝支持。 * */ #include<bits/stdc++.h> //POJ不支持#define rep(i,a,n) for (int i=a;i<=n;i++)//i為循環變量,a為初始值,n為界限值,遞增 #define per(i,a,n) for (int i=a;i>=n;i--)//i為循環變量, a為初始值,n為界限值,遞減。 #define pb push_back #define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) #define fi first #define se second #define mp make_pairusing namespace std;const int inf = 0x3f3f3f3f;//無窮大 const int maxn = 3e5+2;//最大值。 typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<int, int> pii; //*******************************分割線,以上為自定義代碼模板***************************************//int t,n; ll a[maxn]; int main(){//freopen("in.txt", "r", stdin);//提交的時候要注釋掉IOS;while(cin>>t){while(t--){cin>>n;rep(i,1,n){cin>>a[i];}ll maxx=a[1];int ans=1;//統計是不是所有的元素值相同。rep(i,2,n){maxx=max(maxx,a[i]);if(a[i]==a[1])ans++;}if(ans==n){cout<<-1<<endl;continue;}//接下來遍歷。rep(i,1,n){//對邊緣進行判斷。if(i==1&&a[i]==maxx&&a[i+1]<maxx){cout<<i<<endl;break;}else if(i==n&&a[i]==maxx&&a[i-1]<maxx){cout<<i<<endl;break;}else if(i!=1&&i!=n&&a[i]==maxx&&(a[i-1]<maxx||a[i+1]<maxx)){cout<<i<<endl;break;}}}}return 0; }

總結

以上是生活随笔為你收集整理的C. Dominant Piranha(思维) Codeforces Round #677 (Div. 3)的全部內容,希望文章能夠幫你解決所遇到的問題。

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