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. CSS自定义右键菜单

    <style> .menu { width: 100px; font-size: 14px; font-family: "微软雅黑"; border: 1px soli ...

  2. CPU体系结构(组成部分)

    在准备网络工程师考试,里面有些知识点是比较常考的.自己写这篇博客呢,当作是笔记吧,自己看一看也分享给大家一起学习. 这部分的内容就是讲CPU里面的组成结构以及各部分的功能. CPU的构成:CPU主要由 ...

  3. 006-OpenStack-配仪表盘

    OpenStack-配仪表盘 [基于此文章的环境]点我快速打开文章 计算节点安装(compute1) 1.安装 yum install openstack-dashboard -y &> ...

  4. Arbitrage POJ - 2240

    题目链接:https://vjudge.net/problem/POJ-2240 思路:判正环,Bellman-ford和SPFA,floyd都可以,有正环就可以套利. 这里用SPFA,就是个板子题吧 ...

  5. git push origin master错误

    以下错误是因为远程有的文件,本地没有,故而无法push文件到远程 $ git push origin master To git@github.com:AntonioSu/learngitWindow ...

  6. eclipse配置JDK和设置编译版本的几种方法

    eclipse配置JDK和设置编译版本的几种方法  2016-12-13 16:08             http://blog.csdn.net/gnail_oug/article/detail ...

  7. Spring Boot 引入外部yml配置文件

    当需要在springboot中引用其他的yml文件时,需要在application.yml里配置 spring:     profiles:         include: email,xmyb   ...

  8. Python进阶-Ⅷ 匿名函数 lambda

    1.匿名函数的引入 为了解决那些功能很简单的需求而设计的一句话函数 def func(i): return 2*i # 简化之后 func = lambda i:2*i #todo 其中:func是函 ...

  9. Attention篇(二)

    主要是对<Attention is all you need>的分析 结合:http://www.cnblogs.com/robert-dlut/p/8638283.html  以及自己的 ...

  10. [LeetCode] 410. Split Array Largest Sum 分割数组的最大值

    Given an array which consists of non-negative integers and an integer m, you can split the array int ...