面面數
Problem Description
DS 看見過這麼一個題目:
求在三維世界中,經過一個公共點的 n 個平面(但任意三個平面不過同一直線)把空間分成的塊數
DS發現整個平面被分成了 N 部分(N ≤ 2000000000),那麼最少需要用多少個平面呢?
致歉:
請 if (n == 0) cout << 1 << endl; .... Sorry
Input
第一行一個整數代表數據的組數 T (T ≤ 10000)
每組數據一個整數 N (1 ≤ N ≤ 2000000000)
Output
Sample Input
5 1 2 3 4 100
Sample Output
0 1 2 2 11
<span style="white-space:pre"> </span><span style="font-size:24px;color:#ff0000;">作爲結論:記下來!</span>
#include<iostream>
using namespace std;
long long a[60000];
int main()
{
a[0]=1;a[1]=2;a[2]=4;a[3]=8;a[4]=14;
for(int i=5;i<60000;i++)
{
a[i]=a[i-1]+2*(i-1);
}
int t,n;
cin>>t;
while(t--)
{
cin>>n;
if(n==0)
{
cout<<"1"<<endl;
continue;
}
for(int i=0;i<60000;i++)
{
if(a[i]>=n)
{
cout<<i<<endl;
break;
}
}
}
}