codeforces 582A. GCD Table 解題報告

來源:互聯網
上載者:User

標籤:

題目連結:http://codeforces.com/problemset/problem/582/A

  網上很多題解,就不說了,直接貼代碼= =

  官方題解:

  http://codeforces.com/blog/entry/20692

  

 1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 #include <algorithm> 6 #include <map> 7 #include <vector> 8 using namespace std; 9 10 const int maxn = 500 + 5;11 map<int, int> cnt;12 vector<int> ans;13 int a[maxn*maxn];14 15 int GCD(int a, int b)16 {17     return b == 0 ? a : GCD(b, a%b);18 }19 20 int main()21 {22     int n;23     #ifndef ONLINE_JUDGE24         freopen("in.txt", "r", stdin);25     #endif // ONLINE_JUDGE26 27     while (scanf("%d", &n) != EOF) {28         ans.clear();29         for (int i = 0; i < n*n; i++) {30             scanf("%d", &a[i]);31             cnt[a[i]]++;32         }33 34         sort(a, a+n*n);35         for (int i = n*n-1; i >= 0; i--) {36             if (cnt[a[i]] <= 0) {37                 continue;38             }39             cnt[a[i]]--;40 41             for (int j = 0; j < ans.size(); j++) {42                 cnt[GCD(ans[j], a[i])] -= 2;43             }44             ans.push_back(a[i]);45         }46         for (int i = 0; i < ans.size(); i++) {47             cout << ans[i] << (i == ans.size()-1 ? ‘\n‘ : ‘ ‘);48         }49     }50     return 0;51 }

 

codeforces 582A. GCD Table 解題報告

聯繫我們

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