题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=4466

题目意思:

一根长为N的木棒,长度分成若干个三角形,使得任意两个三角形都相似。对应顺序三角形全部全等的为同一种分法,求总共有多少种分法。

解题思路:

数学题。

先考虑分成一个三角形的情况。

不妨设a<=b<=c;

1、当b=c时,a至少为1,所以c<=(n-1)/2

而a<=b 所以n-2*c<=c =>c>=n/3; 故共有(n-1)/2-(n/3)+(n/3?0:1)种。

2、当b<c时,肯定有b<=c-1

此时若a+b>c 则a+b>c-1

如果a,b,c能构成三角形,则a,b,c-1也一定能够构成三角形。

反过来,如果a,b,c-1能够构成三角形,也即a+b>c-1 当a+b!=c时,一定能使a,b,c构成三角形。故可以通过dp[n-1]递推过来,然后减去a+b=c+1的情况。

此时n=2*c+1,c=(n-1)/2  只有当n为奇数的时候才有可能,而a+b=(n-(n-1)/2),a<=b 所以这种情况共有 (n-(n-1)/2)/2种,化简得(n+1)/4

在考虑有多个三角形的情况。

假设N=a*b 则把b作为一个基本三角形,a个1,作为a个部分,中间有a-1个隔板,每个隔板可选可不选,一共有2^(a-1)种情况。

当所有的隔板都不选的话,就是一个大三角形,所以此时要把,刚才求得的一个三角形中三边不互质的数量减掉。而每个约数,对应的该约数能拆分成一个互质三角形的种数的不互质的三角形,乘以倍数就是大的不互质的三角形。

详见代码:

#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#define eps 1e-6
#define INF 0x1f1f1f1f
#define PI acos(-1.0)
#define ll __int64
#define lson l,m,(rt<<1)
#define rson m+1,r,(rt<<1)|1
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define M 1000000007
#define N (5000000+10) /*
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
*/
int dp[N],bin[N]; //dp[i]表示一个三角形的情况,并且是互质的情况 void init()
{
dp[3]=1;
for(int i=4;i<N;i++)
{
dp[i]=dp[i-1]+(i-1)/2-i/3+(i%3?0:1); //b==c的情况
if(!(i&1)) //当前一个为奇数
dp[i]-=i/4; //减去,递推中不满足要求的部分
dp[i]=dp[i]%M;
if(dp[i]<0)
dp[i]+=M;
}
bin[1]=1;
for(int i=2;i<N;i++)
{
bin[i]=(bin[i-1]<<1)%M;
for(int j=2;i*j<N;j++)
{
dp[i*j]-=dp[i]; //减去一个三角形中三边不互质的部分,,
if(dp[i*j]<0) //也就是对应的约数的dp[i],对于每个互质的小的a,b,c 对应一个j*a,j*b,j*c
dp[i*j]+=M;
}
}
return ;
} int main()
{
int n,ca=0; init();
//printf("%I64d\n",dp[3]); while(scanf("%d",&n)!=EOF)
{
int ans=0;
for(int i=1;i*i<=n;i++)
{
if(n%i)
continue;
ans=(ans+1LL*dp[i]*bin[n/i])%M; //中间乘法可能会溢int
if(i*i!=n)
ans=(ans+1LL*dp[n/i]*bin[i])%M;
}
printf("Case %d: %I64d\n",++ca,ans);
}
return 0;
}

hdu-4466-Triangle 数学题的更多相关文章

  1. HDU 5914 Triangle 数学找规律

    Triangle 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5914 Description Mr. Frog has n sticks, who ...

  2. hdu 4324 Triangle LOVE

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4324 Triangle LOVE Description Recently, scientists f ...

  3. hdu 5587 Array 数学题

    Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5587 De ...

  4. HDU 5914 Triangle 【构造】 (2016中国大学生程序设计竞赛(长春))

    Triangle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  5. HDU 5914 Triangle(打表——斐波那契数的应用)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5914 Problem Description Mr. Frog has n sticks, whos ...

  6. HDU 6467 简单数学题 【递推公式 && O(1)优化乘法】(广东工业大学第十四届程序设计竞赛)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6467 简单数学题 Time Limit: 4000/2000 MS (Java/Others)    M ...

  7. HDU 4324 Triangle LOVE 拓扑排序

    Problem Description Recently, scientists find that there is love between any of two people. For exam ...

  8. HDU 4324 Triangle LOVE (拓扑排序)

    Triangle LOVE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  9. HDU 6467.简单数学题-数学题 (“字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛)

    简单数学题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  10. hdu 6512 Triangle

    Problem Description After Xiaoteng took a math class, he learned a lot of different shapes, but Xiao ...

随机推荐

  1. java 使用grpc步骤

    1.配置grpc maven依赖 <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-ne ...

  2. CSDN博客栏目设置个性化

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha ====== <a href=" http://weibo.com/23 ...

  3. Codeforces.314E.Sereja and Squares(DP)

    题目链接 http://www.cnblogs.com/TheRoadToTheGold/p/8443668.html \(Description\) 给你一个擦去了部分左括号和全部右括号的括号序列, ...

  4. BZOJ.3139.[HNOI2013]比赛(搜索 Hash)

    题目链接 不会搜索了.. DFS()中两个参数,枚举每两个队伍的比赛结果(分配当前队伍的分数). 可以发现方案数量与具体哪只球队得了多少分无关,只与当前比赛的队伍数量和得分序列的组成有关.可以记忆化搜 ...

  5. Linux上挂载NTFS分区

    1.   简介 本文的目的是提供读者在Linux操作系统上如何mount NTFS分区的文件系统的step-by-step指南.本文包括两个部分: 以只读方式mount NTFS文件系统: 以读写方式 ...

  6. NOIP 2013 转圈游戏

    [题目描述] n个小伙伴(编号从 0 到 n−1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从 0 到 n−1.最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 1 号位置,……, ...

  7. VS2013发布网站删除.CS文件

    VS2013发布网站时,默认不删除.CS文件,想要删除的话,需要一些配置   1.在要发布的网站上右键,选择"发布网站". 2.在发布窗口中,会让你选择一个发布配置文件,没有的话点 ...

  8. 使用GSON和泛型解析约定格式的JSON串(转)

    时间紧张,先记一笔,后续优化与完善. 解决的问题: 使用GSON和泛型解析约定格式的JSON串. 背景介绍: 1.使用GSON来进行JSON串与java代码的互相转换. 2.JSON的格式如下三种: ...

  9. Implementation of Serial Wire JTAG flash programming in ARM Cortex M3 Processors

    Implementation of Serial Wire JTAG flash programming in ARM Cortex M3 Processors The goal of the pro ...

  10. Renesas M16C/6X -- Simple PWM Signal Generation Using DMA

    1. Requirements To generate a PWM output, we need to create a train of pulses with constant period a ...