【Codeforces Round 328 (Div 2)B】【找规律】The Monster and the Squirrel 正多边形连边分割块数

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T> inline void gmax(T &a,T b){if(b>a)a=b;}
template <class T> inline void gmin(T &a,T b){if(b<a)a=b;}
const int N=0,M=0,Z=1e9+7,ms63=1061109567;
LL n,m;
int main()
{
	while(~scanf("%lld",&n))
	{
		LL m=3*(n-3)+(n-3)*(n-4)+1;
		printf("%lld\n",m);
	}
	return 0;
}
/*
【题意】
给你一个有n([3,54321])个点的正多边形。
我们顺时针,以每个点为起点,向其他所有点连一条边。
这条边一直连到没其他点阻挡,就停下来。
让你输出我们最终把这个正多边形分割成几部分。

【类型】
找规律

【分析】
对于n=3,4,5,6,
我们发现答案分别是1,4,9,16。
而且已经AC了大量人,于是大胆猜测答案为3*(n-3)+(n-3)*(n-4)+1
具体是这么分析的:分割的部分=多边形内部连边数+1。
那我们究竟在这个正多边形中连了多少条边呢?
第一个点肯定连了n-3条边,这个点左侧和右侧的点,每个点也是连n-3条边。于是这里有3*(n-3)
而除此之外的其他点,都因为已经与1连边,所以连边数减少1。即(n-3)*(n-4)
最后再加上1就是答案啦、

【时间复杂度&&优化】
O(1)

*/

你可能感兴趣的:(ACM,ICPC,codeforces,找规律)