FZU 2111 Min Number

來源:互聯網
上載者:User

標籤:style   blog   io   color   ar   os   sp   for   資料   

這題 沒有想到 是 貪心的演算法.

所以和隊友兩個人一直卡在這裡.

一直用其中一個隊友的方法,卡了一小時多,回來以後繼續寫,卡在另外一個地方.

感覺就是自己的思路太狹窄了...可能因為不是很認真吧..

或許比賽的時候就不一樣了..

福州OJ的測試資料太弱了..就不寫最佳化了.

最佳化就是拿到最小值,接下來就不比了..

 1 #include <iostream>   2 #include <cstdio>   3 #include <cstring>   4 using namespace std;   5 #define maxn 1005 6 char c[maxn];   7 int main()   8 {   9     int T,m,len,p,mi,t;10     //freopen("2111.txt","r",stdin);11     scanf("%d",&T);  12     while(T--)  13     {  14         scanf("%s%d",c,&m);  15         len=strlen(c);  16         for(int i=0;i<len&&m;i++)  17         {  18             p=-1;mi=c[i];  19            for(int j=i;j<len;j++)  20             if(mi>c[j]&&(c[j]!=‘0‘||i))  //i=0 不能換21             {  22                 mi=c[j];  23                 p=j;  24             }  25             if(p!=-1)  26            {  27             t=c[p]; 28             c[p]=c[i];  29             c[i]=t;  30             m--;  31            }  32         }  33         printf("%s\n",c);  34     }  35     return 0;  36 }  37         

 

FZU 2111 Min Number

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.