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 ...
随机推荐
- D - Zhenya moves from the dormitory URAL - 2015
After moving from his parents’ place Zhenya has been living in the University dormitory for a month. ...
- Problem V
Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that th ...
- java Mybatis框架动态SQL
1.if+where <select id="getgoods" resultType="Goods" > select * from goods ...
- java模拟登陆功能
package test; import java.util.Scanner; public class Login { static Scanner sc=new Scanner(System.in ...
- redis源码分析之事务Transaction(上)
这周学习了一下redis事务功能的实现原理,本来是想用一篇文章进行总结的,写完以后发现这块内容比较多,而且多个命令之间又互相依赖,放在一篇文章里一方面篇幅会比较大,另一方面文章组织结构会比较乱,不容易 ...
- Windows常用shell命令大全
Windows常用shell命令大全 基于鼠标操作的后果就是OS界面外观发生改变, 就得多花学习成本.更主要的是基于界面引导Path与命令行直达速度是难以比拟的.另外Geek很大一部分是键盘控,而非鼠 ...
- C#链接数据库增删改查的例子
以users表为例,有三个字段,自增长的编号id,int类型:名称name,nvarchar类型,密码pwd,nvarchar类型首先在vs2005中引入using System.Data.SqlCl ...
- 前端面试题(4)iframe有哪些优点?iframe缺点是什么?
优点: iframe能够原封不动的把嵌入的网页展现出来. 如果有多个网页引用iframe,那么你只需要修改iframe的内容,就可以实现调用的每一个页面内容的更改,方便快捷. 网页如果为了统一风格,头 ...
- Django 入门案例开发(中)
昨天已经描述了如何搭建Django的开发环境,今天描述业务流程,具体我们要实现一个什么样的业务: 以下的业务都是假设的(网上书店 页面做的low): 1.用户注册及登录业务: 这是一个网上书店阅读 ...
- RabbitMQ消息队列系列教程(一)认识RabbitMQ
摘要 RabbitMQ是最为流行的消息中间件,是处理高并发业务的利器.本系列教程,将跟大家一起学习RabbitMQ. 目录 RabbitMQ是什么? RabbitMQ的特点是什么? 一.RabbitM ...