Uva434 logic (logical)

Source: Internet
Author: User

Uva434 logic (logical)

Question: There are n × n positive and lateral views composed of cubes with a side length of 1. Ask how many squares can constitute the front view and lateral view at this time, the number of cubes that can be added at most is the same as the number of cubes that can be added to form the same forward and lateral views.

Question: I have done a similar question before to find at least cube analysis here. It is very easy to push at most cubes, that is, to fill each column according to a view first, then, based on the other view, you can reduce the overfilled value.

# 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 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.