uva1609 Foul Play

來源:互聯網
上載者:User

標籤:思路   cto   階段   hat   i++   ack   space   win   size   

思維 創造條件使一輪比賽之後仍滿足1號打敗至少一半,並剩下至少一個t‘

紫書上的思路很清晰
階段1,3保證黑色至少消滅1半

#include<cstdio>#include<vector>using namespace std;const int maxn = 1024 + 5;char table[maxn][maxn];int main() {  int n;  while(scanf("%d", &n) == 1) {    for(int i = 1; i <= n; i++) scanf("%s", table[i]+1);    vector<int> win, lose; // teams that team 1 win/lose against.    for(int i = 2; i <= n; i++)      if(table[1][i] == ‘1‘) win.push_back(i);      else lose.push_back(i);    int nt = n;    while(nt > 1) {      vector<int> win2, lose2, final; // phase 3/4      // Phase 1      for(int i = 0; i < lose.size(); i++) {        int tlose = lose[i];        bool matched = false;        for(int j = 0; j < win.size(); j++) {          int& twin = win[j];          if(twin > 0 && table[twin][tlose] == ‘1‘) {  //盡量通過配對消滅黑            printf("%d %d\n", twin, tlose);            win2.push_back(twin); // go to the next round            twin = 0; // not available   本輪已經配對            matched = true;            break;          }        }        if(!matched) final.push_back(tlose); // to phase 3/4      }      // Phase 2      bool first = true;      for(int i = 0; i < win.size(); i++) {        int twin = win[i];        if(twin > 0) {          if(first) { printf("1 %d\n", twin);first = false; }          else final.push_back(twin);        }      }      // Phase 3/4      for(int i = 0; i < final.size(); i += 2) {    //3,4階段可以一起處理        printf("%d %d\n", final[i], final[i+1]);        int keep = final[i];        if(table[final[i+1]][keep] == ‘1‘) keep = final[i+1];        if(table[1][keep] == ‘1‘) win2.push_back(keep);        else lose2.push_back(keep);      }      win = win2;      lose = lose2;      nt >>= 1;    }  }  return 0;}

 

uva1609 Foul Play

聯繫我們

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