版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_41117236/article/details/81988841
【题目】
折线分割平面
TimeLimit: 2000/1000 MS (Java/Others) MemoryLimit: 65536/32768 K (Java/Others)
64-bit integer IO format:%I64d
Problem Description
我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目。比如,一条折线可以将平面分成两部分,两条折线最多可以将平面分成7部分,具体如下所示。
Input
输入数据的第一行是一个整数C,表示测试实例的个数,然后是C 行数据,每行包含一个整数n(0<n<=10000),表示折线的数量。
Output
对于每个测试实例,请输出平面的最大分割数,每个实例的输出占一行。
SampleInput
2 1 2
SampleOutput
2 7
【题解】
直线分割平面公式:F[n]=1+n*(n+1)/2
折线分割平面公式:F(n)=2n*n -n+1
会用就行
【代码】
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#define mem(a) memset(a,0,sizeof(a))
#define go(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int INF=0x3f3f3f3f;
typedef long long ll;
typedef unsigned long long ull;
main()
{
int n,m; cin>>n;
while(n--)
{
cin>>m;
ll ans=2*m*m-m+1;
cout<<ans<<endl;
}
}