I - Parking Lot
Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit Status
Description
To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes.
The parking lot before the office consists of one line of (2n - 2) parking spaces. Unfortunately the total number of cars is greater than the parking lot capacity. Furthermore even amount of cars of each make is greater than the amount of parking spaces! That‘s why there are no free spaces on the parking lot ever.
Looking on the straight line of cars the company CEO thought that parking lot would be more beautiful if it contained exactly nsuccessive cars of the same make. Help the CEO determine the number of ways to fill the parking lot this way.
Input
The only line of the input contains one integer n (3 ≤ n ≤ 30) — the amount of successive cars of the same make.
Output
Output one integer — the number of ways to fill the parking lot by cars of four makes using the described way.
Sample Input
Input
3
Output
24
Hint
Let‘s denote car makes in the following way: A — Aston Martin, B — Bentley, M — Mercedes-Maybach, Z — Zaporozhets. For n = 3there are the following appropriate ways to fill the parking lot: AAAB AAAM AAAZ ABBB AMMM AZZZ BBBA BBBM BBBZ BAAA BMMM BZZZ MMMA MMMB MMMZ MAAA MBBB MZZZ ZZZA ZZZB ZZZM ZAAA ZBBB ZMMM
Originally it was planned to grant sport cars of Ferrari, Lamborghini, Maserati and Bugatti makes but this idea was renounced because it is impossible to drive these cars having small road clearance on the worn-down roads of IT City.
题意:总共有四种类型的车,给一个数字n代表有n辆车 m=2*n-2个车位,总裁认为有n个一样的车相连停放看起来漂亮,问有多少种停车方法,
题解:列举出几组例子可以找到规律,因为n辆车是连续的(我们将其看做一个整体)所以我们应当对m-n+1个车位进行全排列
n=4时 有4*3*4+3*4*3+4*3*4 n=5时 4*3*4*4+3*4*3*4+4*3*4*3+4*4*4*3;
#include<stdio.h> #include<string.h> #include<cstdio> #include<string> #include<math.h> #include<algorithm> #define LL long long #define PI atan(1.0)*4 #define DD double #define MAX 30000 #define mod 100 #define dian 1.000000011 #define INF 0x3f3f3f using namespace std; int main() { LL n,m,j,i,t,k; LL sum,sum1,sum2; while(scanf("%lld",&n)!=EOF) { m=2*n-2; k=m-n; sum1=2*3*pow(4,k); sum2=(k-1)*3*3*pow(4,k-1); sum=sum1+sum2; printf("%lld\n",sum); } return 0; }