AOJ 803.魔方

Time Limit: 5000 ms   Case Time Limit: 5000 ms   Memory Limit: 64 MB
Total Submission: 181   Submission Accepted: 71
 
Description
西瓜很喜欢玩魔方,现在西瓜想知道,一个N阶魔方在表面一共有多少个立方体能被看见?
Input
包含多组数据,EOF结束。
对于每组输入,包含一个数字N(1 <= N <= 1000),表示魔方的阶数。
Output
对于每组输入,输出一行,表示N阶魔方能看见的立方体数。
Sample Input
Original Transformed
1
2
3
4
Sample Output
Original Transformed
1
8
26
56

数学题

对于n阶魔方,如果n=1,那么就是1,否则ans=n3-(n-2)3=6n2-12n+8

 1 /*
 2 By:OhYee
 3 Github:OhYee
 4 Email:oyohyee@oyohyee.com
 5 */
 6 #include <cstdio>
 7 #include <algorithm>
 8 #include <cstring>
 9 #include <cmath>
10 #include <string>
11 #include <iostream>
12 #include <vector>
13 #include <list>
14 #include <stack>
15 using namespace std;
16  
17 #define REP(n) for(int o=0;o<n;o++)
18  
19  
20 int main() {
21     int n;
22     while(scanf("%d",&n) != EOF)
23         printf("%d
",n==1?1:6*n*n-12*n+8);
24     return 0;
25 }
原文地址:https://www.cnblogs.com/ohyee/p/5313762.html