Boring meetings.

Source: Internet
Author: User

"Title description"

There is a N-edged table, and N cadres sit on each vertex of the N-edged shape.

The definition of "complete" isosceles triangle is that the three vertices of this isosceles triangle are all positive n-edged vertices, and the cadres on the three vertices have the same gender.

Now ask how many "full" isosceles triangle there are in this N-side shape.

"Input description"

The first line inputs a number T (T <= 1000), representing a total of T-group data;

Next T line, each line enters a string of length n, which represents n vertices on a positive n-shape, 1 is male and 0 is female.

"Output description"

For group I data, output "Case I:ans", Ans indicates the number of "full" isosceles triangle.

"Sample Input"

5

0001

01

10001

1101010

111010

"Sample Output"

Case 1:1

Case 2:0

Case 3:1

Case 4:3

Case 5:2

"Data range and Tips"

For 40% of data, n <= 20;

For 100% of data, N <= 106.

The following: Law One: it can be assumed that men are black spots and females are white dots. Enumerates the vertices of a isosceles triangle, and then enumerates a bottom point. The triangle is determined. To find the number of triangles of the same color. N2 practices. Law II: Number of all isosceles triangle-the number of all different color isosceles triangle = The number of all same-color triangles. enumerates the vertices, and then enumerates the number of different color edges in an enumeration of any bottom point that differs from his color (that is, the number O (1) of all points on the polygon that are different from its color). So there is a triangle (vertex and two bottom point one is the same color, one is a different color) number once, there is a triangle (vertex and two bottom point are different colors) number two times. You can make it all count two times. calculates the vertex with one edge point one for the same color, and one for the number of triangle rows with a different color: enumerates two bottom points to ensure their color is different. When n is odd, any two points can form the bottom edge. When n is even, the same point of parity can form the bottom edge. Different color edges are calculated two times, divided by 2, is the bottom of the number of different colors. is the number of triangles.

Boring meetings.

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.