1002: Flowers
Time Limit: 1 Sec Memory Limit: 128 MB 64bit IO Format: %lld
Submitted: 105 Accepted: 61
[Submit][Status][Web Board]
Description
Spring is the season of flowers!
Flowerful ahm002 is a girl who loves flowers so much. She also collects a lots of lo dress(which costs ahm001 too much). One day ahm001 picked a brunch of flowers to ahm002. She notices that each of these flowers is unique, and she wants to decorate her dress by putting flower onto the round skirt.
ahm001 needs to calculate, how many ways there are to decorate ahm002’s dress?
Note that two ways are same if they are identical after rotation or reflection.
Input
The first line of input contains the number of test cases T. The descriptions of the test cases follow:
The only line of each test case contains a single integer, the number of the flowers, n(0 < n <= 20).
Output
For each test case, output the number of the ways.
Sample Input 4
1
2
3
4
Sample Output
1
1
1
3
HINT
123 is same as 321 after reflection.
1234 is same as 4123 after rotation.
问题描述:
Flowerful ahm002很喜欢花,Flowerful ahm001一天摘了一束花给她,每束花都不一样,Flowerful ahm002想把这束花围在裙子上一圈,顺序和逆序相同为一种方法,问总共有多少种方法?
分析:
一看就知道这是一个签到的水题,每多一束花n,它可选取的位子就是在前n-1束花围成的圈的中间共n-1种。
AC代码:
using namespace std;
long long D[25];
int main()
{
int n,x;
scanf("%d",&n);
D[1]=1;
D[2]=1;
D[3]=1;
for(int i=4;i<=20;i++)
D[i]=D[i-1]*(i-1);
while(n--)
{
scanf("%d",&x);
cout <<D[x]<<endl;
}
return 0;
}