uva 434(邏輯),uva434邏輯

來源:互聯網
上載者:User

uva 434(邏輯),uva434邏輯

題意:有n×n的由邊長是1的正方體組成的正視圖和側視圖,問此時最少多少個正方體能組成這種正視圖和側視圖,還有在最少的基礎上最多添加多少個正方體同樣形成完全相同的正視圖和側視圖。

題解:之前有做過一個類似的題求最少個正方體分析在此,推最多個正方體也很簡單,就是先根據一種視圖填滿每一列,然後根據另一個視圖將多填的再減掉就可以了。

#include <stdio.h>#include <string.h>const int N = 10;int a1[N], a2[N], mp[N], n;int main() {int t;scanf("%d", &t);while (t--) {memset(mp, 0, sizeof(mp));scanf("%d", &n);int sum1 = 0, sum2 = 0;for (int i = 0; i < n; i++) {scanf("%d", &a1[i]);mp[a1[i]]++;sum1 += a1[i];sum2 += a1[i] * n;}for (int i = 0; i < n; i++) {scanf("%d", &a2[i]);mp[a2[i]]--;for (int j = 0; j < n; j++)if (a1[j] > a2[i])sum2 -= a1[j] - a2[i];}for (int i = 0; i < 9; i++)if (mp[i] < 0)sum1 -= (mp[i] * i);printf("Matty needs at least %d blocks, and can add at most %d extra blocks.\n", sum1, sum2 - sum1);}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.