Tree array + fast and stupid watermelon planting (competition)

Source: Internet
Author: User

BACKGROUND Background

Stupid: small watermelon, small watermelon ~
Lu renjia: No, this watermelon is big ......
Stupid: That ...... Big watermelon, big watermelon ~
Passerby A: It's time to change ......
Stupid: Watermelon ~ Cute watermelon ~

Description

Stupid planting of a watermelon land, but the planting range of this watermelon land is a straight line ......
After some research, he came to M conclusion that the M conclusion can make him get the most watermelon.
The stupid conclusion is as follows:
At least t watermelon should be planted from B to E, and the harvest in this range can be maximized.
He doesn't want to work so hard, so he wants to plant as few watermelons as possible and satisfy every conclusion.

Input Format
The first line of two numbers n, m (0 <n <= 3000, 0 <= m <=), indicating the length of the stupid watermelon land N, stupid to draw M conclusions.
Next, the m rows indicate the stupid M conclusions. Each row contains three numbers: B, E, T (1 <= B <= e <= n, 0 <= T <= e-B + 1 ).

Output Format
Output how many watermelons are stupid to plant at least.

 

[Reference Program ]:
# Include <cstring>
# Include <cstdio>
# Include <iostream>
Using namespace STD;

Struct Node
{
Int B, E, T;
} A [3010];
Int f [5010], C [5010];
Int n, m;
Int CMP (const void * s, const void * t)
{
Node I = * (node *) s, j = * (node *) T;
Return I. e-j.e;
}
Int lowbit (int x)
{
Return x ^ (X & (x-1 ));
}
Void modify (int x)
{
While (x <= N)
{
C [x] ++;
X + = lowbit (X );
}
}
Int getsum (int x)
{
Int sum = 0;
While (X)
{
Sum + = C [x];
X-= lowbit (X );
}
Return sum;
}
Int main ()
{
Scanf ("% d", & N, & M );
For (INT I = 1; I <= m; I ++)
Scanf ("% d", & A [I]. B, & A [I]. E, & A [I]. t );
Qsort (a + 1, m, sizeof (node), CMP );
Memset (C, 0, sizeof (c ));
Memset (F, 0, sizeof (f ));
Int need, ANS = 0;
For (INT I = 1; I <= m; I ++)
{// Currently, this conclusion requires more than one watermelon to be planted.
Need = A [I]. T-(getsum (A [I]. e)-getsum (A [I]. b-1 ));
For (Int J = A [I]. E; j> = A [I]. B; j --)
{
If (need <= 0) break;
If (! F [J])
{
F [J] = 1; need --;
Modify (j); ans ++;
}
}
}
Printf ("% d/N", ANS );
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.