HDU 1220 简单数学题

题目大意是

在魔方上找到有多少对小立方块它们之间连接的点不超过两个

因为任意两个立方块之间相连的点就只有0,1,2,4 这样4种情况

那么我们只需要考虑总共的组成立方块对数

sum = C(2 , n*n*n)  = (n*n*n*(n*n*n-1))/2  在n*n*n个立方块中任选两个组合

然后减去邻接4个点的情况

4个点邻接只会出现在两个立方块有公共平面的情况

我们可以考虑4种情况,用a[4]数组保存

8个角上的立方块 , 每个都有3个立方块和其邻接

12个棱上(除去顶角) , 共有12*(n-2) 个立方块 , 每个有4个立方块邻接

6个面上(除去棱) , 共有6*[n*n - 4(n-1)] 个立方块,每个有5个立方块和其邻接

内部,视野所不可到达的中心 , 共有(n-2)^3个立方块,每个有6个立方块邻接

把上述四种情况一加记得除以2,因为你和我邻接与我和你邻接是重复的

最后sum减去它就是结果

 1 #include <cstdio>
 2 #include <cstring>
 3
 4 using namespace std;
 5 int a[4] , sum;
 6
 7 int get(int n)
 8 {
 9     int t = n*n*n;
10     sum = t*(t-1) / 2;
11     a[0] = 8 * 3;
12     a[1] = 12 * (n-2) * 4;
13     a[2] = 6 * (n*n - 4*(n-1)) * 5;
14     a[3] = (n-2)*(n-2)*(n-2)*6;
15     sum -= (a[0]+a[1]+a[2]+a[3]) / 2;
16     return sum;
17 }
18
19 int main()
20 {
21     int n;
22     while(~scanf("%d" , &n)){
23         if(n == 1)
24             puts("0");
25         else{
26             int ans = get(n);
27             printf("%d\n" , ans);
28         }
29     }
30     return 0;
31 }
时间: 2024-08-03 17:34:27

HDU 1220 简单数学题的相关文章

HDU 6467 简单数学题 【递推公式 &amp;&amp; O(1)优化乘法】(广东工业大学第十四届程序设计竞赛)

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6467 简单数学题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 308    Accepted Submission(s): 150 Problem Description 已知 F(n)=∑i=1n(i×∑j=inCij) 求 F(n) m

HDU 5019 简单数学题

这道题是说给定A和B,求第C大的公约数. 我们最长求的就是最大公约数了,也就是通常用的GCD算法.但是现在要求第C大的公约数,我们可以想见如果令第C大的公约数为x,最大公约数为g的话,那么x|g的,为什么呢? 我们可以直观的理解,最大公约数其实就是A和B分别进行素因子分解之后,能取到公共素因子乘起来得到的.而对于任意A.B的公约数,那么肯定包含了部分的最大公约数所包含的素因子,因此x|g. 于是要求第C大的公约数,只需要枚举g的因子就行了,我们知道求一个数的因子情况,是可以进行O(sqrt(n)

hdu 2368 Alfredo&#39;s Pizza Restaurant(简单数学题)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2368 题目很简单,但是比较恶心,用sqrt WA到死也不过,不用秒过: 忍不住吐槽一下; Problem Description Traditionally after the Local Contest, judges and contestants go to their favourite restaurant,

hdu2374 A Game with Marbles(简单数学题)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2374 Problem Description There are n bowls, numbered from 1 to n. Initially, bowl i contains mi marbles. One game step consists of removing one marble from a bowl.

HDU 1253 (简单三维广搜) 胜利大逃亡

奇葩!这么简单的广搜居然爆内存了,而且一直爆,一直爆,Orz 而且我也优化过了的啊,尼玛还是一直爆! 先把代码贴上睡觉去了,明天再来弄 1 //#define LOCAL 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #include <queue> 6 #include <cmath> 7 using namespace std; 8 9 struct Poin

Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)

题目链接:http://codeforces.com/contest/460/problem/A A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put o

hdu 1087 简单dp

思路和2391一样的.. <span style="font-size:24px;">#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; const int inf=(0x7f7f7f7f); int main() { int a; int s[10005]; int w[10005];

poj 3117 World Cup(简单数学题)

题目链接:http://poj.org/problem?id=3117 World Cup Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8634   Accepted: 4327 Description A World Cup of association football is being held with teams from around the world. The standing is based on

HDU 4891 简单模拟

The Great Pan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1035    Accepted Submission(s): 355 Problem Description As a programming contest addict, Waybl is always happy to take part in vario