UVA11039 Building Designing

Source: Internet
Author: User

Problem Link: UVA11039 Building designing. basic level exercises, written in C + + language program.

Test Instructions Description: Enter n absolute values of unequal 0 integers, select as many as possible, in a sequence, so that the positive and negative alternating and absolute value increment. Output its maximum length.

Problem analysis: After sorting by absolute value, look it over.

The AC C + + language program is as follows:

/* UVA11039 Building Designing * * #include <iostream> #include <cstdio> #include <algorithm>using namespace Std;const int maxn = 500000;int Val[maxn];int cmp (int& A, int& b) {    return abs (a) < ABS (b);} int main () {    int p, n, ans, I;    scanf ("%d", &p);    while (p--) {        scanf ("%d", &n);        for (i=0; i<n; i++)            scanf ("%d", &val[i]);        Sort (val, val+n, CMP);        ans = 1;        for (I=1; i<n; i++) {            if (Val[i-1] > 0 && val[i] < 0) | | (Val[i-1] < 0 && Val[i] > 0))                ans++;        }        printf ("%d\n", ans);    }    return 0;}


UVA11039 Building Designing

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.