codeforces 630I Parking Lot
2016-03-23 18:23
281 查看
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> /* 正如题目:对排列组合应用,有n个相同的车停在一起时,此时又2*n-2个停车位! 左 中 右 <当n==4>时 4*3*4 3*4*3 4*3*4 5 4*3*4*4 3*4*3*4+4*3*4*3 4*4*3*4 (1)当n辆车停在两端时: 左加右=2*(3*pow(4,n-2)); (2)当n辆车停在中间时:(n-3)*3*3*pow(4,n-3); */ using namespace std; /* I. Parking Lot time limit per test0.5 seconds memory limit per test64 megabytes inputstandard input outputstandard output 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 n successive 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. Examples input 3 output 24 Note Let's denote car makes in the following way: A — Aston Martin, B — Bentley, M — Mercedes-Maybach, Z — Zaporozhets. For n?=?3 there 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. */ int main() { __int64 sum1,sum2,sum,n; while(~scanf("%I64d",&n)) { sum1=2*3*(__int64)(pow(4,n-2)); sum2=(n-3)*3*3*(__int64)(pow(4,n-3)); sum=sum1+sum2; printf("%I64d\n",sum); } return 0; }
相关文章推荐
- Mysql 入门第二课
- 自定义AutoCompleteTextView
- 所有转义字符
- ubuntu 14.04 开机启动多个tomcat
- 所有转义字符
- python+selenium环境搭建
- [java]wordcount程序
- Call requires API level 11 (current min is 8): android.app.Activity#onCreateView
- 架构设计
- 第一篇博客——初来驾到
- 项目四,求四个数的最大公约数
- Scala、PHP、Golang 二分法查找
- <Introduction to Java Programming> Note 01
- declaration is incompatible with "__nounwind __interwork __softfp unsigned long __get_PSP(void)" IAR 编译报故障
- 程序员怎样才能写出一篇好的博客或者技术文章
- hdoj5200Trees
- 类型之间的转换、比较--数字、原始值、对象
- 去除Ubuntu文件夹有锁标志
- 一种TV(Android系统)通用焦点框的实现
- 编程学习