Codeforces Round #265 (Div. 2)

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   ar   for   div   

A.inc ARG

  感覺題意不是很清楚,看範例才看懂,就是一串位元,左邊是低位,就掃一遍記錄下改變的bit數

#include <iostream>#include <cstdio>#include <cstdlib>using namespace std;const int maxn = 200;int n, cnt;char lis[maxn];int main(void){#ifdef LOCAL    freopen("465A.in", "r", stdin);#endif    scanf("%d", &n);    getchar();    for(int i = 0; i < n; i++)        scanf("%c", lis+i);    int tmp = 1;    for(int i = 0; i < n; i++) {        if(tmp) cnt++;          if(tmp && lis[i] == ‘1‘)    tmp = 1;        else    tmp = 0;    }    printf("%d\n", cnt);    return 0;}

 

B.Inbox (100500)

  簡單類比題,已經開啟某封信的時候,如果下一封在下一個位置,那麼直接跳下一頁,否則回到首頁再跳轉過去,注意考慮特殊情況,比如全部都讀過

#include <iostream>#include <cstdio>#include <cstdlib>using namespace std;const int maxn = 1000+50;int n, ans;int st[maxn];int main(void){#ifdef LOCAL    freopen("465B.in", "r", stdin);#endif    scanf("%d", &n);    for(int i = 0; i < n; i++)        scanf("%d", st+i);    for(int i = 0; i < n; i++) {        if(st[i] == 0)  continue;        if(ans == 0 || i == 0)  ans++;        else    ans += (st[i-1] == 1? 1: 2);    }       printf("%d\n", ans);    return 0;}

 

C.No to Palindromes!

  我也是卡了很久...才摸索出正確思路

  關於迴文串的一個性質(LEN >= 2),中間一定aba型或者aa型,由此可以得到一個判定一個串是否有迴文字串的簡單方法,存在某個位置的字元滿足那兩種情況之一

這題是要輸出字典序最小的沒有迴文子串的串,那麼對於他的每一個位置都不滿足上述條件即可

  我構造的方法是:原字串已經滿足上述條件,要求答案字典序最小,那麼我們就從改變最右邊一邊,最右邊兩位....來構造答案:左邊是確定的,右邊只需要每個字元滿足條件,從左向右,對於每個位置,搜尋第一個不超過限制且不與前面兩個字元形成迴文串的字元(為什麼不是枚舉每一種情況?因為右邊部分是任意的???

  ...坑爹了,腦子有點亂 題解到此為此 = =  詳情見代碼吧!

#include <iostream>#include <cstdio>#include <cstdlib>using namespace std;const int maxn = 1000+50;const int dx[] = {-2, -1, 1, 2};int n, p;char upper;char lis[maxn], ban[4];bool ok;bool checkLeft(int x){    for(int i = 1; i <= 2; i++)        if(x - i >= 0 && lis[x] == lis[x-i])    return false;    return true;}bool fillRight(int x){    for(int i = x; i < n; i++) {        bool canfill = false;        for(char c = ‘a‘; c <= upper; c++) {            lis[i] = c;            if(checkLeft(i)) {                canfill = true;                break;            }        }        if(!canfill)    return false;    }    return true;}int main(void){#ifdef LOCAL    freopen("465C.in", "r", stdin);#endif    scanf("%d%d", &n, &p);    scanf("%s", lis);    upper = ‘a‘+p-1;    for(int i = n-1; i >= 0; i--) {        for(char c = lis[i]+1; c <= upper; c++) {            lis[i] = c; //          if(i == 2 && c == ‘d‘)  cout << checkLeft(2) << endl;               if(!checkLeft(i))   continue;            if(fillRight(i+1)) {                ok = true;                printf("%s\n", lis);                break;            }        }        if(ok)  break;    }    if(!ok) printf("NO\n");    return 0;}

 

Codeforces Round #265 (Div. 2)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.