2017 ICPCECIC Make cubes

題目描述

When he was a little boy, Jieba had always been interested in geometry. One time, he got many pieces of colored square cards. For each color, he had as many pieces as he wanted. At that time, he decided to make some cubes using these cards. He wanted to know how many kinds of cubes could he make? (if one kind of cube can rotate to another kind, they will be seen the same)

輸入

Every line of the input file defines a test case and contains one integer: the number of available colors n (0

題意

題意倒是很好懂,就是給一個六面體,然後給你n種顏色,問n種顏色可以塗成不同的六面體的個數。六面體可以旋轉,旋轉相同也算是相同。


思路

開始是直接暴力求幾個數找規律,但是吧,六層循環寫完了以後,在判重那裏出了點問題。
橫着轉,豎着轉。一開始只考慮了這兩者兩種情況,還落了一種斜着翻轉的情況,所以一直連兩種顏色都跑不對。
改進之後,暴力跑出一種到六種顏色的方案數分別是1,10,57,240,800,2226。
神TM看得出規律。
最後也沒寫出來,賽後學長說啊,六種以上就是n種顏色選一種乘上一種顏色的方案數,加上n種顏色選兩種顏色乘上兩種顏色的方案數,加上…以此類推,因爲六面體最多隻能塗六種顏色,所以,只要加到六種顏色就好了。
注意:
因爲數據範圍,所以要用long long 存ans和中間值。


代碼

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

long long solve (int n,int x)
{
     long long t,b;
     t=1;
     b=1;
     for(int i=n,j=0;j<x;j++,i--)
     {
         b*=j+1;
         t*=i;
     }
     return (t/b)%MOD;
}
int main() {

    int n;
    long long t,ans;
    int a[7]={1,8,30,68,75,30};
    int b[7]={1,10,57,240,800,2226};
    while(scanf("%d",&n)!=EOF)
    {
        if(n<=6)
            printf("%d\n",b[n-1]);
        else
        {
            ans=0;
            for(int i=0;i<6;++i)
            {
                t=solve(n,i+1);
                ans+=t*a[i];
                ans%=MOD;
            }
            printf("%lld\n",ans);
        }
    }
    return 0;
}
發佈了57 篇原創文章 · 獲贊 15 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章