HDU4466 Triangle
题意:给一个长为N的铁丝,问你有几种方法将其划分为若干段,使得每一段都能围成一个边长为整数的三角形,并且围成的三角形都相似
思路其实很明显,三角形的周长必定是N的约数,那么答案就是周长C能围城的三角形的数量*[N/C]的拆分数的和。问题是这两个东西怎么求。后者比较简单,打个表就能发现它是2的幂次。前者讨论三条边的关系后可以得出递归式:f[i]=f[i-2]+i/3-i/4。之后容斥一下即可。
#include<bits/stdc++.h>
using namespace std;
#define MAXN 5000000+10
#define MODD 1000000007
const int maxn=MAXN-;
int n,tot,f[MAXN],pw[MAXN]={},d[MAXN];
void init(){
for(int i=;i<=maxn;i++)
pw[i]=pw[i-]*,pw[i]%=MODD;
}
int main(){
init();
int Case=;
while(~scanf("%d",&n)){
Case++;
for(int i=;i<=maxn;i++)f[i]=f[i-]+i/-i/,f[i]%=MODD;
tot=;
for(int i=;i*i<=n;i++)
if(n%i==){
if(i*i!=n){
d[++tot]=i;
d[++tot]=n/i;
}
else d[++tot]=i;
}
sort(d+,d+tot+);
for(int i=;i<=tot;i++)
for(int j=;j<i;j++)
if(d[i]%d[j]==)f[d[i]]-=f[d[j]],f[d[i]]=(f[d[i]]+MODD)%MODD;
long long ans=;
for(int i=;i<=tot;i++)ans=(ans+(long long)f[d[i]]*pw[n/d[i]-]%MODD)%MODD;
printf("Case %d: %lld\n",Case,ans);
}
return ;
}
HDU4466 Triangle的更多相关文章
- HDU4466 Triangle 计数 容斥原理
原文链接https://www.cnblogs.com/zhouzhendong/p/HDU4466.html 题目传送门 - HDU4466 题意 多组数据,每次询问一个数 $n(n\leq 5\t ...
- [LeetCode] Triangle 三角形
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- [LeetCode] Pascal's Triangle II 杨辉三角之二
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- [LeetCode] Pascal's Triangle 杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【leetcode】Pascal's Triangle II
题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...
- 【leetcode】Pascal's Triangle
题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...
- POJ 1163 The Triangle(简单动态规划)
http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- Triangle - Delaunay Triangulator
Triangle - Delaunay Triangulator eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...
- LeetCode 118 Pascal's Triangle
Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...
随机推荐
- java 随记
后台开发的过程中积累的关于java的杂记 架构 SSH框架 为什么要分层? 因为分层使代码变得清晰,容易写也容易阅读,更重要的是让代码扩展性更好,层与层之间的改动不会互相影响 各层的分工 dao--与 ...
- 操作系统--进程管理1--单个CPU情况
1.进程概念 进程:一个正在执行的程序:操作系统提出进程概念目的:是为了跟踪程序在执行期间的状态.而程序只是一段代码,是一个静态的概念 无法准确描述程序执行时候发生的一切.程序代码被加载进内存后就以进 ...
- Paint the Grid Reloaded(缩点,DFS+BFS)
Leo has a grid with N rows and M columns. All cells are painted with either black or white initially ...
- 附录三 关于book.h
本书中用到的公用函数放到了头文件book.h中. #ifndef __BOOK_H__ #define __BOOK_H__ #include <stdio.h> #include < ...
- Windows解决anaconda下双python版本安装TensorFlow
首先,就是双版本anaconda的安装: 以前安装好的是python2.7版本,而TensorFlow的安装仅支持3.5版本的.但是自己本来的2.7版本又不想遗弃.所以安装双版本的: 在anacond ...
- PHP小技巧
1.js获取服务器年月日 var date= '<?php echo date("Y-m-d",time())?>';//获取服务器年月
- weiapi 获取项目根目录
无法使用: Server.Map("~"); Server.Map("~/"); Server.Map("./"); Server.Map( ...
- TFS在项目中Devops落地进程(上)
经过近2年折腾,基于TFS的Devops主线工程大体落地完毕.在此大体回忆下中间的各种历程. 开始之前简单说下什么是TFS(Team Foundation Server). TFS是微软推出的一款AL ...
- 高效sql2005分页存储过程
高效分页存储过程 --分页存储过程示例 Alter PROCEDURE [dbo].[JH_PageDemo] @pageSize int = 9000000000, @pageIndex int = ...
- Espresso浅析和使用
欢迎大家前往腾讯云社区,获取更多腾讯海量技术实践干货哦~ Espresso是一个Google官方提供的Android应用UI自动化测试框架.Google希望,当Android的开发者利用Espress ...