码迷,mamicode.com
首页 > 其他好文 > 详细

欧拉公式

时间:2014-08-14 20:36:59      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:style   blog   os   io   for   2014   cti   代码   

LRJ算法入门经典第二版上面写错了,害得我想了半天。。。

V : 点数, E :边数  F :面数

欧拉公式 V - E + F = 2;

V =  n + n / 4 sum(i * (n - 2 - i));  [ 0 <= i <= n - 2];

E = n + n / 2 sum((i * (n - 2 - i ) + 1); [ 0 <= i <= n - 2];

代码实现:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<string>
#include<sstream>
#include<ctime>
using namespace std;
#define _PI acos(-1.0)
#define INF (1 << 10)
#define esp 1e-9
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pill;
/*===========================================
===========================================*/
LL _V(LL n){  /*求点*/
    LL ans = 0;
    for(LL i = 0 ; i <= n - 2 ; i++)
        ans = ans + i * (n - 2 - i);
    LL _ans = n + n * ans / 4;
    return _ans;
}
LL _E(LL n){ /*求面*/
    LL ans = 0;
    for(LL  i = 0 ; i <= n - 2; i++)
        ans = ans + (i * (n - 2 - i) + 1);
    LL _ans = n + n * ans / 2;
    return _ans;
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        LL N;
        scanf("%I64d",&N);
        LL V = _V(N);
        LL E = _E(N);
        printf("%I64d\n",1 + E - V);
    }
    return 0;
}

欧拉公式,布布扣,bubuko.com

欧拉公式

标签:style   blog   os   io   for   2014   cti   代码   

原文地址:http://blog.csdn.net/u013451221/article/details/38563039

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!