# 51nod algorithm marathon 18 A dyeing problem, 51nod marathon

Source: Internet
Author: User

51nod algorithm marathon 18 A dyeing problem, 51nod marathon

Dyeing Problems

Reference time limit: 1 second space limit: 10240 KB score: 40 a complete graph of n (3 <= n <= 100) points, now n, it is required that each side be colored with k (1 <= k <= n), so that all three points constitute the ring (C (n, 3) the color of the three sides and the combination of any three colors in all colors (C (n, 3) are one-to-one. You can give a dyeing scheme. Multiple groups of data Input
`The first line is an integer T, indicating the number of data groups. Next line is an integer n, indicating the number of points in the full graph.`
Output
`The output consists of T parts. The first line of each part is an integer n, indicating the number of points in the full graph. The second line indicates the construction result. If No solution is output, otherwise n * (n-1) is output) /start, end, and color of two edges`
Input example
`243`
Output example
`4No solution31 2 3 2 3 1 3 1 2`

At first, I thought it was very troublesome to look at this question as a ring, a diagram, and a combination. However, after reading the question, I found it was not that complicated. There is no need to worry about the example of a question. Input 3 can be output as a decent example, it can also be output in the desired color (the result of my program running 3 is 1 2 1 1 3 2 3, but it can be AC ). Then, let's look at the rule again, that is, to dye a color between the two points, and then the line with the two points as an endpoint can no longer dye this color, in this way, you can find the rule and see how to fill in the color. If the input is an even number, this cannot be done in any case, so the even number will directly output "No solution". If it is an odd number, find the rule again. I will first follow the entered color, finally, after filling out the number of colors, I checked the rule of the table I drew and wrote out the program.

The following is a table that I entered 7 as an example. The two sides represent two vertices, and the code inside is the color of the edges between the two vertices.

 1 2 3 4 5 6 7 1 \ 1 2 3 4 5 6 2 1 \ 3 4 5 6 7 3 2 3 \ 5 6 7 1 4 3 4 5 \ 7 1 2 5 4 5 6 7 \ 2 3 6 5 6 7 1 2 \ 4 7 6 7 1 2 3 4 \

There should be more than one way to fill in the color, just find one, and then I write the code according to the rules of my table. below is the AC code

`#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int a[1005];int main(){     int T;     int n;     int i,j;     int k,t;     scanf("%d",&T);     while(T--)     {          scanf("%d",&n);          cout<<n<<endl;          if(n%2==0)               cout<<"No solution"<<endl;          else          {               t=1;               for(i=1;i<n-1;i++)               {                    k=t;                    for(j=i+1;j<=n;j++)                    {                         cout<<i<<" "<<j<<" "<<k<<" ";                         k=(k+1)%n;                         if(k==0)                              k=n;                    }                    t=(t+2)%n;                    if(t==0)                         t=n;               }               cout<<n-1<<" "<<n<<" "<<k<<endl;          }     }     return 0;}`

Related Keywords:

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.