hdu1249 三角形

用N個三角形最多可以把平面分成幾個區域?

一條直線和三角形的一角相交,會產生兩個交點,從而新產生一條線段,這條新產生的線段便對應着新生成的面,即兩個交點-->一個面。

因爲題目是三角形和三角形進行相交,產生的交點既是原來圖像的交點,也是新加入的三角形的交點,即一個交點-->一個面。所以:


新增一條直線,最多新增交點個數
爲原來三角形個數*2,因爲直線可以和原來每個三角形的其中一個角相交。 
設edge[n] 爲已存在n個三角形時加上一條直線最多能和edge[n]條直線相交
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <map>
#include <cstring>
using namespace std;
const int N = 10005;
int edge[N];
long long ans[N];
int main(void)
{
    ans[0] = 1;
    edge[0] = 0;
    ans[1] = 2;
    for (int i = 2; i < N; ++i)
    {
        edge[i - 1] = 2 * (i - 1);
        ans[i] = ans[i - 1] + 3 * edge[i - 1]; //3 代表三角形有三邊
    }
    int T, n;
    cin >> T;
    while (T--)
    {
        cin >> n;
        cout << ans[n] << endl;
    }
	return 0;
}

 
發佈了55 篇原創文章 · 獲贊 11 · 訪問量 7831
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章