LA 4123 Glenbow Museum Castle Museum

Source: Internet
Author: User

Test instructions: For a polygon with an edge parallel to an axis, we can use a sequence of R and O to describe it: starting from a vertex in a counterclockwise order, hitting a 90° internal angle of R; touching a 270° internal angle. Such sequences are called angular sequences. Defining a star polygon is a point in a polygon where you can see each point on the polygon boundary. Now given a positive integer n, how many angular sequences of length l can correspond to at least one star polygon. where each edge of the polygon is arbitrarily long.









It seems very difficult to start, a little abstract. We can actually assume that the polygon length is 1 and then construct:

First, it's easy to see that the polygon vertex number is n, and the number of edges is n. And because the edges of the polygons are parallel to the axes, L is at least 4 and must be an even number. To make a polygon a star polygon, the polygon must have a core. In this problem. The inner angle of the polygon is only 90 ° and 270°, so it is clear that if there are two adjacent internal angles are 270°, then this polygon is not nuclear. That is, the angle sequence can not have two o adjacent, and the tail can not be at the same time O.

Then we determine the number of R and O. The internal angles of the N-edged shape are (N-2) *180, and R represents the inner angle of 90,o for 270, so it is easy to calculate the number of R and O, respectively (N + 4)/2 and (n-4)/2. The problem is then converted to how many methods of placing (n-4)/2 O and any two nonadjacent are placed in n positions.

This is a very simple combinatorial problem. The bundling method is a good idea for the non-adjacent problem. We bundle each o with an R and make R on the left of O. This is bundled into a whole, equivalent to placing in N-(n-4)/2 positions (n-4)/2 O, that is, placing 4 R. The answer is C ((n + 4)/2,4). Notice that a situation is missing, that is, the sequence begins with O. Because I just put R on the left of O. So we make the first one for O, so the last one must be r, the remaining position will still bind each O and R and let R on the left of O. The answer is C ((n + 2)/2,4). So the final answer is C ((n + 4)/2,4) + C ((n + 2)/2,4). Be careful not to forget that L is an odd or less than 4 case with a special output of 0.







#include <iostream> #include <algorithm> #include <cstring> #include <cmath> #include < cstdio> #include <iomanip> #include <string>using namespace Std;long long L;int main () {    int case = 0;    while (scanf ("%lld", &l) && L)    {        printf ("Case%d:", ++case);        if (l&1 | | L < 4)        {            printf ("0\n");            Continue;        }        Long Long ans1 = (l + 4) >> 1, Ans2 = (l + 2) >> 1;        ans1 = ans1* (ans1-1) * (ans1-2) * (ans1-3)/24;        Ans2 = ans2* (ans2-1) * (ans2-2) * (ans2-3)/24;        printf ("%lld\n", ans1 + ans2);    }    return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

LA 4123 Glenbow Museum Castle Museum

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.