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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

付忠庆的练习小笔记-Codeforces #277 Div2 C

發布時間:2023/12/20 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 付忠庆的练习小笔记-Codeforces #277 Div2 C 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原題鏈接

http://codeforces.com/contest/486/problem/C

這個C題顯然更水一些

步數可以分為兩種 上下一種 左右一種

總步數最小 = 上下最小+左右最小

先討論上下最小 就是從兩個方向去由字母1到字母2 ?min(dis(A,B),26-dis(A,B));

然后討論左右最小 pos是起始指針的位置

1-統一在前半段操作,pos要是在后半段就“映射”到前半段,pos=n+1-pos;

2-若上下操作為0 那么左右直接也是0

3-找出左邊第一個操作l 右邊第一個操作r

? ? ? 一, 若是 pos<l<r ? 返回 r-pos

  二, ?若是 l<r<pos 返回 pos-l

  三,若是 l<pos<r ?返回 min(r-pos,pos-l);

?

?

結束

附代碼:

1 #include <iostream> 2 #include <cmath> 3 typedef long long LL; 4 using namespace std; 5 int a[110000],f[100000]; 6 7 int main() 8 { 9 int n,pos; 10 while (cin>>n>>pos) 11 { 12 if (pos>n/2) pos=n+1-pos; 13 LL ans=0; 14 char temp; 15 for (int i=1;i<=n;i++) 16 { 17 cin>>temp; 18 a[i]=temp-'a'+1; 19 } 20 for (int i=1;i<=n/2;i++) 21 { 22 int dis = abs(a[i]-a[n-i+1]); 23 f[i]=min(dis,26-dis); 24 ans+=f[i]; 25 } 26 if (ans==0) {cout<<0<<endl;continue;} 27 int l=1,r=n/2; 28 while(!f[l++]&&l<=r); 29 l--; 30 while(!f[r--]&&l<=r); 31 r++; 32 if (pos>r) ans+=pos-l; 33 if (pos<l) ans+=r-pos; 34 if (pos<=r&&pos>=l) ans+=(r-l)+min(r-pos,pos-l); 35 cout<<ans<<endl; 36 } 37 return 0; 38 }

?

轉載于:https://www.cnblogs.com/fuzhongqing/p/4093570.html

總結

以上是生活随笔為你收集整理的付忠庆的练习小笔记-Codeforces #277 Div2 C的全部內容,希望文章能夠幫你解決所遇到的問題。

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