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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Codeforces Round #441 D. Sorting the Coins(模拟)

發布時間:2023/12/10 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #441 D. Sorting the Coins(模拟) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://codeforces.com/contest/876/problem/D

題意:
題意真是難懂,就是給一串序列,第i次操作會在p[x](1<=x<=i)這些位置放上硬幣,然后從左到右觀察,如果第i個位置有硬幣但第i+1個位置沒有硬幣,那么互換,然后繼續從第i+1個硬幣開始看。直到不需要交換,需要計算出到終極狀態需要多少步。

?

思路:

模擬。

1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 #include<cstdio> 5 #include<vector> 6 #include<stack> 7 #include<queue> 8 #include<cmath> 9 #include<map> 10 #include<set> 11 using namespace std; 12 typedef long long ll; 13 typedef pair<int,int> pll; 14 const int INF = 0x3f3f3f3f; 15 const int maxn = 300000+5; 16 17 int n; 18 int p[maxn]; 19 int a[maxn]; 20 vector<int> ans; 21 22 int main() 23 { 24 //freopen("in.txt","r",stdin); 25 while(~scanf("%d",&n)) 26 { 27 ans.clear(); 28 memset(a,0,sizeof(a)); 29 for(int i=1;i<=n;i++) scanf("%d",&p[i]); 30 int max_right=n; 31 int cnt=0; 32 for(int i=1;i<=n;i++) 33 { 34 a[p[i]]=1; 35 if(p[i]==max_right) 36 { 37 for(int j=max_right-1;j>=1;j--) 38 { 39 if(!a[j]) {max_right=j;break;} 40 else cnt--; 41 } 42 } 43 else 44 { 45 cnt++; 46 } 47 ans.push_back(cnt+1); 48 } 49 printf("1"); 50 for(int i=0;i<ans.size();i++) 51 printf(" %d",ans[i]); 52 printf("\n"); 53 } 54 return 0; 55 }

?

轉載于:https://www.cnblogs.com/zyb993963526/p/7679291.html

總結

以上是生活随笔為你收集整理的Codeforces Round #441 D. Sorting the Coins(模拟)的全部內容,希望文章能夠幫你解決所遇到的問題。

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