UVA - 434 Matty's Blocks

來源:互聯網
上載者:User

標籤:style   blog   os   2014   for   io   

題意:給你正視和側視圖,求最多多少個,最少多少個

思路:貪心的思想,求最少的時候:因為可以想象著移動,盡量讓兩個視圖的重疊,所以我們統計每個視圖不同高度的個數,然後計算,至於的話,就是每次拿正視圖的高度去匹配側視求最大

#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;const int MAXN = 1000;int k;int view[2][MAXN];int main() {int t;scanf("%d", &t);while (t--) {scanf("%d", &k);memset(view, 0, sizeof(view));for (int i = 0; i < 2; i++)for (int j = 0; j < k; j++) {int x;scanf("%d", &x);view[i][x]++;}int Min = 0, Max = 0;for (int i = 1; i < MAXN; i++) Min += i * max(view[0][i], view[1][i]);for (int i = 1; i < MAXN; i++)for (int j = 1; j < MAXN; j++) Max += min(i, j)*view[0][i]*view[1][j];printf("Matty needs at least %d blocks, and can add at most %d extra blocks.\n", Min, Max-Min);}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.