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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

uva 120——Stacks of Flapjacks

發布時間:2023/11/30 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 uva 120——Stacks of Flapjacks 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:一個非常有趣的問題,就是給一摞煎餅,然后從下面拿起來一張,然后把該張上面的所有餡餅反轉,求最后使得餡餅從小到大的最小的步數。

?

思路:貪心。每次都把沒排好序的最大數反轉到最上面,然后在一次反轉到最下面,也就是最多需要2n步就能夠把所有的餡餅排好。

?

Code:

?

#include <iostream> #include <cstdio> #include <algorithm> #include <string> #include <sstream> #include <cstring> #include <cmath> #include <map> #include <vector> #include <queue> #include <set> using namespace std;typedef long long ll; typedef unsigned long long ull; const int N=1000000; const int M=105; const int mod=10000007; const int INF=0x3f3f3f3f; const ll LINF=0x3f3f3f3f3f3f3f3f; const double eps=1e-9; const double pai=acos(-1.0); #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define cls(x,c) memset(x,c,sizeof(x)) #define fr(i,n) for (int i=0;i<n;i++)int a[35],len; int tran(int j) {int t=j;for (int i=0;i<j;i++)if (a[i]>a[t]) t=i;return t; } int main() {string s;int i,j;while (getline(cin,s)){if (s=="") break;cout<<s<<endl;stringstream ss;ss<<s;len=0;while (ss>>a[len]) len++;//fr (i,len) cout<<"bug2"<<a[i]<<endl;for (int i=len-1;i>=0;i--){j=tran(i);//cout<<"bug "<<j<<endl;if (j==i) continue;if (j!=0){printf("%d ",len-j);reverse(a,a+j+1);}reverse(a,a+i+1);printf("%d ",len-i);}puts("0");} }

總結

以上是生活随笔為你收集整理的uva 120——Stacks of Flapjacks的全部內容,希望文章能夠幫你解決所遇到的問題。

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