Sawtooth

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 ?

InputThe 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 ≤ 10
12)OutputFor 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 题意:问用"M"形的线条去切割一个平面,问当有n个"M"时能把平面切割成几份?
用1条直线切割平面可以把平面分成2份
用2条直线切割平面可以把平面分成4份
用3条直线切割平面可以把平面分成7份
用n条直线切割平面可以把平面分成2+2+3+4+....+n份
假设"M"的线条可以无限延长成直线,那么一个M相当于4条直线,但是考虑到"M"实际上并没有延长成直线,那么一个"M"的切割份数一定小于4条直线的切割分数,
猜想二者可能满足某种关系。
直线:
n=4时,ans=11
n=8时,ans=37
“M”:
n=1时,ans=2
n=2时,ans=19
发现
11-9=2
37-2*9=19
设“M”个数为n,那么有4n*(4n+1)/2+1-9n ---> n*(8n-7)+1
直接输出答案会爆ll。
可以用JAVA或者高精度算法。
这里用的是拆分乘。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9;
int main()
{
//freopen("input.txt","r",stdin);
ll T,kase=;
scanf("%lld",&T);
while(T--)
{
ll n;
scanf("%lld",&n);
ll a0=(*n-)%mod;
ll a1=(*n-)/mod;
ll b0=n%mod;
ll b1=n/mod;
ll num0=(a0*b0+);
ll num1=(b0*a1+b1*a0+num0/mod);
ll num2=(a1*b1+num1/mod);
num0%=mod;
num1%=mod;
printf("Case #%lld: ",kase++);
if(num2) printf("%lld%09lld%09lld\n",num2,num1,num0);
else if(num1) printf("%lld%09lld\n",num1,num0);
else printf("%lld\n",num0);
}
return ;
}

 

HDU 5047 Sawtooth 找规律+拆分乘的更多相关文章

  1. hdu 5047 大数找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=5047 找规律 信kuangbin,能AC #include <stdio.h> #include & ...

  2. HDU 2086 A1 = ? (找规律推导公式 + 水题)(Java版)

    Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2086 ——每天在线,欢迎留言谈论. 题目大意: 有如下方程:Ai = (Ai-1 ...

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

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

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

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

  5. hdu 5106 组合数学+找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=5106 给定n和r,要求算出[0,r)之间所有n-onebit数的和,n-onebit数是所有数位中1的个数. 对 ...

  6. Doom HDU - 5239 (找规律+线段树)

     题目链接: D - Doom  HDU - 5239  题目大意:首先是T组测试样例,然后n个数,m次询问,然后每一次询问给你一个区间,问你这个这段区间的加上上一次的和是多少,查询完之后,这段区间里 ...

  7. hdu 4708(暴力+找规律)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708 思路:由于N不大,并且我们可以发现通过旋转得到的4个对角线的点的位置关系,以及所要旋转的最小步数 ...

  8. hdu 4759 大数+找规律 ***

    题目意思很简单. 就是洗牌,抽出奇数和偶数,要么奇数放前面,要么偶数放前面. 总共2^N张牌. 需要问的是,给了A X B Y  问经过若干洗牌后,第A个位置是X,第B个位置是Y 是不是可能的. Ja ...

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

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

随机推荐

  1. Java生鲜电商平台-技术方案与文档下载

    Java生鲜电商平台-技术方案与文档下载 说明:任何一个好的项目,都应该有好的文档与设计方案,包括需求文档,概要设计,详细设计,测试用例,验收报告等等,类似下面这个图: 有以下几个管理域: 1. 开发 ...

  2. Kibana插件开发

    当前开发环境 Kibana版本:7.2 elasticsearch版本:7.2 开发环境安装可参考:https://github.com/elastic/kibana/blob/master/CONT ...

  3. SQLi-LABS Page-2 (Adv Injections) Less23-Less26

    Less-23 GET - Error based - strip comments http://10.10.202.112/sqli/Less-23?id=1' Warning: mysql_fe ...

  4. iOS开发之--为UITextField监听数值变化的三种方法

    项目中有个验证码输入直接验证跳转页面,用的RAC来监听textfield的输入值,如下: @weakify(self); [self.codeView.textField.rac_textSignal ...

  5. 修改host指定域名指向ip,Windows脚本与Linux脚本

    修改host指定域名指向ip,Windows脚本与Linux脚本 一,Windows系统修改hosts文件 Windows系统下hosts文件位置:C:\Windows\System32\driver ...

  6. 【IDE_IntelliJ IDEA】idea中设置类和方法的注释模板

    参考博文:idea生成类注释和方法注释的正确方法

  7. Python从零开始——函数

    一:Python函数知识概览 二:函数的定义与调用 三:参数传递 四:函数返回值 五:匿名函数的定义与调用 六:变量作用域与改变变量作用域

  8. linux(03)基础系统优化

    Linux之基础系统优化 Linux基础系统优化 >>> https://www.cnblogs.com/pyyu/p/9355477.html Linux的网络功能相当强悍,一时之 ...

  9. angular 学习记录

    3章3小结 路由传参的3种方式和路由快照,订阅, @相同路由的跳转(只是参数不同),并不会触发Oninit ,因为没有重新创建component @子路由 //此种情况 是当我路由地址是 ../Hom ...

  10. POJ3630-Phone List-(字典树)

    一直没有学字典树,听起来很唬人,闲来无事找一道入门题做做. 字典树:又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以 ...