Gym 101981G - Pyramid - [打表找规律][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem G]
题目链接:http://codeforces.com/gym/101981/attachments
The use of the triangle in the New Age practices seems to be very important as it represents the unholy
trinity (Satan, the Antichrist and the False Prophet bringing mankind to the New World Order with
false/distorted beliefs). The triangle is of primary importance in all Illuminati realms, whether in the
ritual ceremonies of the Rosicrucians and Masons or the witchcraft, astrological and black magic practices
of other Illuminati followers.
One day you found a class of mysterious patterns. The patterns can be classified into different degrees. A
pattern of degree n consists of n*(n+1)/2 small regular triangles with side length 1, all in the same direction,
forming a big triangle. The figure below shows the pattern of degree 3. All small regular triangles are
highlighted.

Since the pattern contains many regular triangles, which is very evil and unacceptable, you want to
calculate the number of regular triangles formed by vertices in the pattern, so that you can estimate the
strength of Illuminati. It is not necessary that each side of regular triangles is parallel to one side of the
triangles. The figure below shows two regular triangles formed by vertices in a pattern of degree 3.

Since the answer can be very large, you only need to calculate the number modulo 10^9 + 7.
Input
The first line contains an integer t (1 ≤ t ≤ 10^6) — the number of test cases.
Each of the next t lines contains an integer n (1 ≤ n ≤ 10^9) — the degree of the pattern.
Output
For each test case, print an integer in one line — the number of regular triangles modulo 10^9 + 7.
Example
standard input
3
1
2
3
standard output
1
5
15
题意:
上面那个图形的度数为 $3$,里面包含了 $15$ 个正三角形。现在给出度数 $n$,让你找出那样一个图形里面包含多少个正三角形。
题解:
暴力打出度数在 $1 \sim 20$ 内的表,发现规律是三阶差分是等差数列 $4,5,6,7,\cdots$(真的我没有开玩笑……),或者说四阶差分是常数 $1$。然后果断推了个递推式用矩阵快速幂交了一发……TLE+1。
然后知道了只能 $O(1)$ 地求,开始考虑推通项公式。类比于四次函数求四阶导数之后为常数,换句话说通向公式应当是一个四次多项式。
因此可以假设 $a_n = An^4 + Bn^3 + Cn^2 + Dn + E$,然后将前五项 $a_1 = 1, a_2 = 5, a_3 = 15, a_4 = 35, a_5 = 70$ 代入解五元一次线性方程组,
解得 $A = \frac{1}{24}, B = \frac{1}{4}, C = \frac{11}{24}, D = \frac{1}{4}, E = 0$。
(注意不要忘了除法是乘逆元……已经有两次因为这个WA+n了……)
然后实际上,OEIS搜一下就可以知道 $a_n = C_{n+3}^{4}$。
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+;
ll n;
ll fpow(ll a,ll n)
{
ll res=,base=a%mod;
while(n)
{
if(n&) res*=base, res%=mod;
base*=base, base%=mod;
n>>=;
}
return res%mod;
}
ll inv(ll a){return fpow(a,mod-);}
int main()
{
int T;
cin>>T;
while(T--)
{
scanf("%I64d",&n);
ll ans=;
ans+=fpow(n,), ans%=mod;
ans+=*fpow(n,)%mod, ans%=mod;
ans+=*fpow(n,)%mod, ans%=mod;
ans+=*n%mod, ans%=mod;
ans*=inv(), ans%=mod;
printf("%I64d\n",ans);
}
}
Gym 101981G - Pyramid - [打表找规律][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem G]的更多相关文章
- Gym 101981J - Prime Game - [数学题][线性筛+分解质因数][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem J]
题目链接:http://codeforces.com/gym/101981/attachments 题意: 令 $mul(l,r) = \prod_{i=l}^{r}a_i$,且 $fac(l,r)$ ...
- 计蒜客 39279.Swap-打表找规律 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest L.) 2019ICPC西安邀请赛现场赛重现赛
Swap There is a sequence of numbers of length nn, and each number in the sequence is different. Ther ...
- Gym - 101981G The 2018 ICPC Asia Nanjing Regional Contest G.Pyramid 找规律
题面 题意:数一个n阶三角形中,有多少个全等三角形,n<=1e9 题解:拿到题想找规律,手画开始一直数漏....,最后还是打了个表 (打表就是随便定个点为(0,0),然后(2,0),(4,0), ...
- 最短路+找规律 Samara University ACM ICPC 2016-2017 Quarterfinal Qualification Contest L. Right Build
题目链接:http://codeforces.com/gym/101149/problem/L 题目大意:有n个点(其实是n+1个点,因为编号是0~n),m条有向边.起点是0,到a和b两个节点,所经过 ...
- Gym - 101981M The 2018 ICPC Asia Nanjing Regional Contest M.Mediocre String Problem Manacher+扩增KMP
题面 题意:给你2个串(长度1e6),在第一个串里找“s1s2s3”,第二个串里找“s4”,拼接后,是一个回文串,求方案数 题解:知道s1和s4回文,s2和s3回文,所以我们枚举s1的右端点,s1的长 ...
- Gym - 101981D The 2018 ICPC Asia Nanjing Regional Contest D.Country Meow 最小球覆盖
题面 题意:给你100个三维空间里的点,让你求一个点,使得他到所有点距离最大的值最小,也就是让你找一个最小的球覆盖掉这n个点 题解:红书模板题,这题也因为数据小,精度也不高,所以也可以用随机算法,模拟 ...
- Gym - 101981K The 2018 ICPC Asia Nanjing Regional Contest K.Kangaroo Puzzle 暴力或随机
题面 题意:给你1个20*20的格子图,有的是障碍有的是怪,你可以每次指定上下左右的方向,然后所有怪都会向那个方向走, 如果2个怪撞上了,就融合在一起,让你给不超过5w步,让所有怪都融合 题解:我们可 ...
- Gym - 101981I The 2018 ICPC Asia Nanjing Regional Contest I.Magic Potion 最大流
题面 题意:n个英雄,m个怪兽,第i个英雄可以打第i个集合里的一个怪兽,一个怪兽可以在多个集合里,有k瓶药水,每个英雄最多喝一次,可以多打一只怪兽,求最多打多少只 n,m,k<=500 题解:显 ...
- Gym - 101981J The 2018 ICPC Asia Nanjing Regional Contest J.Prime Game 计数
题面 题意:1e6的数组(1<a[i]<1e6), mul (l,r) =l × (l+1) ×...× r, fac(l,r) 代表 mul(l,r) 中不同素因子的个数,求s ...
随机推荐
- EAS开发报错 :数据库表 或 视图 不存在
一:原因分析 建模之后,发布数据时未能及时在数据库创建相应的表格或视图. 二:解决办法 建模视图下——右键模型——更新数据库. 三:名称字段.描述字段在数据库里的存储格式 ...
- Laravel: 基础篇
一.安装 1)采用一键安装包 http://laravelacademy.org/resources-download 2)Mac 上安装 ----------在Mac上安装composer----- ...
- 51单片机stack堆栈
一般编译器的堆栈用于保存局部变量.函数的参数.函数的返回值.中断上下文信息等.但Keil对局部变量.函数参数预先分配空间(放在静态全局变量区),Keil的堆栈只是用于保存函数嵌套调用的PC.中断上下文 ...
- 如何在你的Vue项目配置vux
做移动端项目的话vue现在是首要的选择,足够轻便,文档足够全,当然用的人多,项目中遇到的坑别人可能也遇到过,解决起来也比较方便,至于在开发中做需要的移动端组件库,个人比较推崇vux. 其实项目里组件库 ...
- windows 上搭建gitblit
https://www.cnblogs.com/ucos/p/3924720.htmlhttps://www.cnblogs.com/sumuncle/p/6362697.htmlhttp://www ...
- C语言 · 数的划分
算法训练 数的划分 时间限制:1.0s 内存限制:256.0MB 锦囊1 使用动态规划. 锦囊2 用F[i,j,k]表示将i划分成j份,最后一份为k的方案数,则F[i,j,k]= ...
- NaviSoft31.源码开发完成
NaviSoft是作者一人开发完成,从之前的1.0版本,到现在的3.1版本.历经2年时间,开发完成 下面是NaviSoft的源码结构 加QQ群了解更多信息
- JSP通过AJAX获取服务端的时间,在页面上自动更新
1.在页面上引入js <head> <meta http-equiv="Content-Type" content="text/html; charse ...
- Python3集合
集合(set)是一个无序的不重复元素序列. 可以使用大括号 { } 或者 set() 函数创建集合,注意:创建一个空集合必须用 set() 而不是 { },因为 { } 是用来创建一个空字典. 创建格 ...
- JS设计模式——观察者模式(通俗易懂)
Observer模式的概念 Observer模式是行为模式之一,它的作用是当一个对象的状态发生变化时,能够自动通知其他关联对象,自动刷新对象状态. Observer模式提供给关联对象一种同步通信的手段 ...