HDOJ/HDU 2200 Eddy ' s AC puzzle (Find a regular topic)

Source: Internet
Author: User

Super Portal:

http://acm.hdu.edu.cn/showproblem.php?pid=2200

Main topic:

Eddy is a acmer, he not only like to do ACM problem, but also for each of the ranklist in the number of AC has a certain research, he is bored often on the paper on the ranklist of the number of each person's AC topic, and then select a part of the person (or all) Comparing the number of AC into two groups, he wanted to make the minimum AC number in the first group greater than the maximum AC number in the second group, but that would be a lot of things, smart you know how many of these things?

Special note: For the sake of simplification, we assume that the number of extracts under the excerpt is N, and that the number of AC for each person is not equal and the final result is within a 64-bit integer range.

Gee, this problem is simple, I will not translate, directly copied over ...

Topic Analysis:

The law of Shining ... But I've been looking for a long time ... = = Too much water ...

And then finally figured out a way

Suppose N =4

If 2 is the first group of the smallest, that must be 2 below in the second group, 2 above in the first group, and, can appear, can not appear, so the case for the first group * The second group (2^2) * (2^1-1) here minus 1 is because the second group cannot be completely empty

So if 2 is the first group the smallest case is (2^2) * (2^1-1)

Similarly, if 3 is the first group, the smallest case is (2^1) * (2^2-1)

Similarly, if 4 is the first group, the smallest case is (2^0) * (2^3-1)

See the rules, and then organize, combined with geometric series formula, the final formula is f (n) = 1+ (n-2) * 2^ (n-1)

The code is good to write:

#include <iostream>
using namespace std;

int main ()
{
	int i;
	int n;
	__int64 sum;
	while (scanf ("%d", &n)! = EOF)
	{
		sum = 1;
		sum<<=n-1;			
		Sum *= (n-2);
		sum + = 1;
		printf ("%i64d\n", sum);
	}
	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.