codeforces 630 I(规律&&组合)

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;
}

  

时间: 2024-10-18 22:09:12

codeforces 630 I(规律&&组合)的相关文章

[2016-04-14][codeforces][630][C][ Lucky Numbers]

时间:2016-04-14 23:12:27 星期四 题目编号:[2016-04-14][codeforces][630][C][ Lucky Numbers] 题目大意: 问n位数字以内的幸运数字有多少个 幸运数字:只含有7,8的数字 分析: 长度为i 的幸运数字,每一位有两种可能,7 , 8,那么长度为i的幸运数字总共有 $2^i$中可能 那么长度为n 以内的所有幸运数字 就是 $2^1 + 2^2 + - + 2^n$, #include<cstdio> using namespace

[2016-04-14][codeforces][630][D][Hexagons!]

时间:2016-04-14 23:54:07 星期四 题目编号:[2016-04-14][codeforces][630][D][Hexagons!] 题目大意:如题目的图,问最外层为n的时候,总共有多少格子 分析: 观察可以得到,an表示第n圈的格子数,则an=6×n(n>0),a0=1an表示第n圈的格子数,则an=6×n(n>0),a0=1 所以最终ans=1+6+12+-+6×n=(3+3n)n+1ans=1+6+12+-+6×n=(3+3n)n+1; 遇到的问题:用累加的方法会T #

[2016-04-14][codeforces][630][A][Again Twenty Five!]

时间:2016-04-14 15:04:48 星期四 题目编号:[2016-04-14][codeforces][630][A][Again Twenty Five!] 题目大意:问5n5n后面两位是啥,注意n特别大 分析:n为1的时候是5,其他都是25 #include<cstdio> using namespace std; int main(){ long long n; scanf("%I64d",&n); if(n == 1) puts("5&q

CodeForces 776E 数学规律,欧拉

CodeForces 776E 题意:定义f(n)为(x,y)的对数,x和y要满足 x>0, y>0, x+y=n, x与y互质. 定义g(n)为f(x1)+f(x2)+......+f(xk),xi为n的因子. 再定义Fk(n)为     给定n和k,求Fk(n). tags: 好假的题..推理或者找规律,f(n)=phi(n), g(n)=n... #include<bits/stdc++.h> using namespace std; #pragma comment(link

816D.Karen and Test 杨辉三角 规律 组合

LINK 题意:给出n个数,每个数对间进行加或减,结果作为下一层的数,问最后的值为多少 思路:首先我们发现很像杨辉三角,然后考虑如何计算每个数对结果的贡献值,找规律可以发现当数的个数为偶数时,其所在层表达式即为二项式定理,且其中的数下标差都为2,故倒数第二层就是将第一层的数分为系数相同的两组,最后相减或相加.注意取模问题,使用逆元.注意n<=2的特殊情况 /** @Date : 2017-07-01 13:43:26 * @FileName: 816D 组合 杨辉三角.cpp * @Platfo

CodeForces 131C C (组合)

There are n boys and m girls attending a theatre club. To set a play "The Big Bang Theory", they need to choose a group containing exactly t actors containing no less than 4 boys and no less than one girl. How many ways are there to choose a gro

codeforces——思路与规律

codeforces 804B     http://codeforces.com/problemset/problem/804/B /* 题意:给定一个只含ab的序列,每次操作可将ab变为bba 问至少变换多少次使序列不含形式为"ab"的子串 这题没想出来......唉. 思路:从后往前处理,每次经过一个a,都要将它移到最后, 共经过x个b,将ans+=x,同时b的个数翻倍x += x:每经过一个b,x++. */ #include<iostream> #include&

2017-03-19 codeforces 664C 找规律,水

C. International Olympia 题意:从1989年起,每一年记作IAO'y,其中y为该年份的第一个没有被占用过的后缀,比如1989记作IAO'9,1990记作IAO'0,1991记作IAO'1 ,给出n个IAO'y,求它们分别代表的年份. tags:好纠结的题,要理清楚.. 可以发现一开始的10年(1989-1998)会缩成一位数,接下来100年(1999-2098)会缩成两位数,接下来1000年(2099-3098)会缩成三位数,接下来10000年(3099-13098)会缩

CodeForces - 964A(找规律)

原题 题意:给你个数N,问你能得到多少种权重不同的分解(权重指将数分解成一个不上升的正整数序列后,序列中等于序列第一个数的个数) 思路:看到题感觉就是规律题,但是开始一直没搞懂输入8为啥出来5,如果能够简单将前几个数模拟一下,就会发现规律 n ans 1 1 2 2 3 2 4 3 5 3 6 4 7 4 所以 ans=n/2-1 代码: #include<iostream> #include<cstdio> using namespace std; int main() { in