CodeForces 630I(规律题)
2016-03-14 20:27
302 查看
Parking Lot
Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces
630I
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
Output
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.
解体思路:在写这题时,肯定是排列组合方法,但是这题不是简单的排列组合,如果单纯的通过排列组合方法去列公式,显然情况是很复杂的,通过列出几个例子,我们发现结果是与4的个数,3的个数有关,那么我们再联系n,求可以找到规律,即结果为
(3*n-1)*3*4^(n-3);
代码如下:
Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces
630I
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.
解体思路:在写这题时,肯定是排列组合方法,但是这题不是简单的排列组合,如果单纯的通过排列组合方法去列公式,显然情况是很复杂的,通过列出几个例子,我们发现结果是与4的个数,3的个数有关,那么我们再联系n,求可以找到规律,即结果为
(3*n-1)*3*4^(n-3);
代码如下:
#include<stdio.h> #include<cmath> int main(){ int n; __int64 sum; while(scanf("%d",&n)!=EOF){ sum=pow(4,n-3); sum*=(3*n-1)*3; printf("%I64d\n",sum); } return 0; }
相关文章推荐
- bit和byte的关系
- 【WinterCamp 2013】模积和
- Java集合需要注意的地方
- Android 安全机制遗漏知识点
- 选择排序和冒泡排序
- MySQL安装配置教程
- 一些css、css3画的效果等,持续更新
- 3. Longest Substring Without Repeating Characters
- 【HDU】 1002 A + B Problem II
- 39. Combination Sum
- 目前流行的源程序版本管理软件有什么优缺点?
- 《Linux内核分析》 第四节 扒开系统调用的三层皮(上)
- [bzoj3202][SDOI2013]项链
- 经典SQL语句大全
- 1000搬桌子
- 2015湖南省选集训DAY5——work(BZOJ4177)
- magent编译安装及常见错误
- OpenSSL BN_CTX usage
- creation of element failed MALFROMED eclipse 创建类失败
- YTU:结构体---点坐标结构体