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. getElementsByClassName

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. 修改数据库表的schema,(表的[dbo.]前缀)

    数据库使用过程中遇到这种问题,请看下图

  3. Printing Array elements with Comma delimiters

    https://www.codewars.com/kata/printing-array-elements-with-comma-delimiters/train/csharp using Syste ...

  4. SQL笔记(1)索引/触发器

    --创建聚集索引 create clustered index ix_tbl_test_DocDate on tbl_test(DocDate) GO --创建非聚集索引 create nonclus ...

  5. MVC服务器前台提示

    [HttpPost] public ActionResult AddMsg(MsgModel model) { string strSql = "insert into tbl_msg(ti ...

  6. KaliLinux装好系统后安装常用软件

    1.配置软件源 leafpad /etc/apt/source.list or(recommand):#官方源deb kali main non-free contribdeb-src kali ma ...

  7. Redis核心知识之—— 时延问题分析及应对、性能问题和解决方法【★★★★★】

    参考网址: Redis时延问题分析及应对:http://www.cnblogs.com/me115/p/5032177.html Redis常见的性能问题和解决方法:http://www.search ...

  8. Codeforces723E One-Way Reform【欧拉回路】

    题意:给你n点m边的图,然后让你确定每条边的方向,使得入度=出度的点最多 . 度数为偶数的点均能满足入度 = 出度. 证明:度数为奇数的点有偶数个,奇度点两两配对连无向边,则新图存在欧拉回路,则可使新 ...

  9. jQuery插件开发全解析,类级别与对象级别开发

    jQuery插件的开发包括两种: 一种是类级别的插件开发,即给jQuery添加新的全局函数,相当于给jQuery类本身添加方法.jQuery的全局函数就是属于jQuery命名空间的函数,另一种是对象级 ...

  10. Java源码初学_LinkedList

    一.LinkedList的内部数据结构 LinkedList底层是一个链表的数据结构,采用的是双向链表,基本的Node数据结构代码如下: private static class Node<E& ...