Sawtooth

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 422    Accepted Submission(s): 134

Problem Description
Think about a plane:

● One straight line can divide a plane into two regions.
● Two lines can divide a plane into at most four regions.
● Three lines can divide a plane into at most seven regions.
● And so on...

Now we have some figure constructed with two parallel rays in the
same direction, joined by two straight segments. It looks like a
character “M”. You are given N such “M”s. What is the maximum number of
regions that these “M”s can divide a plane ?

 
Input
The first line of the input is T (1 ≤ T ≤ 100000), which stands for the number of test cases you need to solve.

Each case contains one single non-negative integer, indicating number of “M”s. (0 ≤ N ≤ 1012)

 
Output
For each test case, print a line “Case #t: ”(without quotes, t means
the index of the test case) at the beginning. Then an integer that is
the maximum number of regions N the “M” figures can divide.
 
Sample Input
2
1
2
 
Sample Output
Case #1: 2
Case #2: 19
 
Source
 
 
其实题目已经很清楚的告知我们是有线条分平面引申而来的了....
对于线条分平面
0  1
1  1 +1
2  1+1 +2
3 1+1 +2+3
4 1+1 +2+3+4
............
n   1+n(n+1)/2;
那么对于一个m型号的模型,其实我们可以将其视其为四条线段组合而成,这样这个公式就变为:
 4n*(4n+1)/2 +1  ---->显然得到的答案有余坠,我
0  1
1   11    2       9
2   37    19     9*2
......
推到得到:
 4n*(4n+1)/2  +1 -8*n----> 8n^2-7n+1
代码:
 #include<cstdio>
#include<cstring>
char aa[],bb[];
int ans[];
int mul( char *a, char *b, int temp[])
{ int i,j,la,lb,l;
la=strlen(a);
lb=strlen(b); for ( i=;i<la+lb;i++ )
temp[i]=;
for ( i=;i<=la-;i++ ) {
l=i;
for ( j=;j<=lb-;j++ ) {
temp[l]=(b[j]-'')*(a[i]-'')+temp[l];
l++;
}
}
while ( temp[l]== )
l--;
for ( i=;i<=l;i++ ) {
temp[i+]+=temp[i]/;
temp[i]=temp[i]%;
}
if ( temp[l+]!= )
l++; while ( temp[l]/!= ) {
temp[l+]+=temp[l]/;
temp[l]=temp[l]%;
l++;
}
if ( temp[l]== )
l--;
return l;
}
void cal(__int64 a,char *str)
{
int i=;
while(a>)
{
str[i++]=(a%)+'';
a/=;
}
}
int main()
{
int cas;
__int64 n;
scanf("%d",&cas);
for(int i=;i<=cas;i++)
{
scanf("%I64d",&n);
printf("Case #%d: ",i);
if(n==)printf("1\n");
else
{
memset(aa,'\0',sizeof(aa));
memset(bb,'\0',sizeof(bb));
memset(ans,,sizeof(ans));
//,(8*n-7)*n+1
cal(*n-,aa);
cal(n,bb);
int len=mul(aa,bb,ans);
ans[]++;
int c=;
for(int j=;j<=len;j++)
{
ans[j]+=c;
if(ans[j]>)
{
c=ans[j]/;
ans[j]%=;
}
}
if(c>)
printf("%d",c);
for(int j=len;j>=;j--)
printf("%d",ans[j]);
printf("\n");
}
}
return ;
}

hdu----(5047)Sawtooth(大数相乘+数学推导)的更多相关文章

  1. HDU 5047 Sawtooth(大数模拟)上海赛区网赛1006

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 解题报告:问一个“M”型可以把一个矩形的平面最多分割成多少块. 输入是有n个“M",现 ...

  2. HDU 5047 Sawtooth(大数优化+递推公式)

    http://acm.hdu.edu.cn/showproblem.php?pid=5047 题目大意: 给n条样子像“m”的折线,求它们能把二维平面分成的面最多是多少. 解题思路: 我们发现直线1条 ...

  3. 2014 网选 上海赛区 hdu 5047 Sawtooth

    题意:求n个'M'型的折线将一个平面分成的最多的面数! 思路:我们都知道n条直线将一个平面分成的最多平面数是 An = An-1 + n+1 也就是f(n) = (n*n + n +2)/2 对于一个 ...

  4. HDU 5858 Hard problem (数学推导)

    Hard problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5858 Description cjj is fun with ...

  5. HDU 5047 Sawtooth 找规律+拆分乘

      Sawtooth Think about a plane: ● One straight line can divide a plane into two regions. ● Two lines ...

  6. hdu 5584 LCM Walk(数学推导公式,规律)

    Problem Description A frog has just learned some number theory, and can't wait to show his ability t ...

  7. HDU 5047 Sawtooth 高精度

    题意: 给出一个\(n(0 \leq n \leq 10^{12})\),问\(n\)个\(M\)形的折线最多可以把平面分成几部分. 分析: 很容易猜出来这种公式一定的关于\(n\)的一个二次多项式. ...

  8. HDU 5073 Galaxy(Anshan 2014)(数学推导,贪婪)

    Galaxy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total S ...

  9. HDU-1719 Friend 数学推导

    Friend HDU - 1719 Friend number are defined recursively as follows. (1) numbers 1 and 2 are friend n ...

随机推荐

  1. DataTable或者DataRow转换对象

    public static IEnumerable<T> ConvertObject<T>(DataTable dt) where T : new() { var v = ty ...

  2. jquery之html(),text()方法详解

    一:html() html()函数用于设置或返回当前jQuery对象所匹配的DOM元素内的html内容. 该函数的用途相当于设置或获取DOM元素的innerHTML属性值. 该函数属于jQuery对象 ...

  3. 通过NuGet获取sqlite对应的.net的dll

    https://www.nuget.org/packages/System.Data.SQLite/ 直接在Package Manager Console中执行命令,会自动安装依赖项的 Install ...

  4. php 怎么设置报错级别 和 控制报错[转]

    在Windows环境下:有时在其他环境下运行正常的程序在自己的环境上会报错误    程序会 报出  Undefined index:   这样的错误例如有如下的代码:                  ...

  5. JAVA 调用命令并输出

    public class test10 { /** * @param args */ public static void main(String[] args) throws Exception { ...

  6. poj1265Area(pick定理)

    链接  Pick定理是说,在一个平面直角坐标系内,如果一个多边形的顶点全都在格点上,那么这个图形的面积恰好就等于边界上经过的格点数的一半加上内部所含格点数再减一. pick定理的一些应用 题意不好懂, ...

  7. Eclipse中配置Tomcat服务器

    在首先外部安装好tomcat,然后在eclipse配置Tomcat服务器: 选择要配置的tomcat版本: 选择tomcat的安装的路径,选择你安装的JRE: 到此tomcat服务器就算是配置好了,接 ...

  8. access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")

    在开启derby服务出现该错误(测试hibernate 连接数据库时  使用myeclipse2014自带的数据库--windows->show view->other->Myecl ...

  9. Android GestureDetector方法详解

    为了加强点击.拖动响应事件,Android提供了GestureDetector手势识别类.通过GestureDetector.OnGestureListener来获取当前被触发的操作手势(Single ...

  10. 关于时区的时间的详解,比如UTC\GMT等

    UTC 和 GMT 及 北京时间的关系 UTC和GMT,这两者几乎是同一概念.它们都是指的格林尼治标准时间,只不过UTC的称呼更为正式一点.两者的区别在于前者是一个天文 上的概念,而 后者是基于一个原 ...