Codeforces Round #511 Div2 D. Little C Loves 3 II

來源:互聯網
上載者:User

標籤:clu   fine   +=   problem   sig   names   ret   多少   問題   

http://codeforces.com/contest/1047/problem/D

問題

有一個 \(N \times M\) 的棋盤,每次可以選擇兩個曼哈頓距離為 \(3\) 的未被佔領的點,並在這兩個點上放置棋子。問最多能放多少個旗子。

題解

建圖跑了一下最大流會發現基本都可以跑滿,只有部分小資料跑不滿,特判一下就好了。。。

#include <bits/stdc++.h>#ifdef LOCAL    #define debug(...) fprintf(stderr, __VA_ARGS__)#else    #define debug(...) 0#endifusing namespace std;typedef long long ll;typedef unsigned int uint;typedef unsigned long long ull;typedef pair<int, int> pii;int main() {    ll n, m;    while (cin >> n >> m) {        if (n > m) swap(n, m);        ll ans = 0;        if (n == 1) {            ll r = m % 6;            ans = ((m - r) / 6) * 3;            if (r == 4) ans += 1;            if (r == 5) ans += 2;            ans *= 2;        } else if (n == 2 && (m == 2 || m == 3 || m == 7)) {            if (m == 2) ans = 0;            if (m == 3) ans = 4;            if (m == 7) ans = 12;        } else {            ans = n * m - (n * m % 2);        }        cout << ans << endl;    }    return 0;}
總結

遇到不是很好想的數學題可以先打個表。

Codeforces Round #511 Div2 D. Little C Loves 3 II

聯繫我們

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