bitset+string+關閉流同步最佳化 Oleg and Little Ponies URAL - 2108__bitset

來源:互聯網
上載者:User

Think:
1知識點:【bitset+string+關閉流同步】
2題意:第1行輸入n、m,第2行至第m+1行輸入m對長度為n的01串bt[i][j],第m+2行輸入長度為n的01串bi,進行下述步驟:
(1)尋找bt[i][0]使得bt[i][0]為bt串的“子串”(bt[i][0]&bi == bt[i][0]),尋找不到則結束
(2)通過(1)已找到i,bi = bi | bt[i][1]
輸出最後狀態的bi即可
3解題思路:
(1)bitset枚舉判斷,string控制輸出格式,關閉流同步加快資料讀取、列印

vjudge題目連結

以下為Accepted代碼

#include <bits/stdc++.h>using namespace std;int vis[4014];bitset<1014> bt[4014][2], bi;int main(){  std::ios::sync_with_stdio(false);  int n, m, i, j;  while(cin >> n >> m){    for(i = 0; i < m; i++){      for(j = 0; j < 2; j++){        cin >> bt[i][j];      }    }    cin >> bi;    memset(vis, 0, sizeof(vis));    while(true){      bool flag = false;      for(i = 0; i < m; i++){        if(vis[i]) continue;        if((bi&bt[i][0]) == bt[i][0]){          vis[i] = 1, flag = true;          bi |= bt[i][1];        }      }      if(!flag) break;    }    string st = bi.to_string();    cout << st.substr(st.size()-n, st.size()) << endl;  }  return 0;}

聯繫我們

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