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 ...
随机推荐
- IOS应用内购(一)内购的种类
Glossary IAP - In App Purchase, 应用内购. 内购种类 consumable - 可消费的,比如游戏中的金币,金币可以购买游戏道具或者装备,这个金币是可以消费的,用完之后 ...
- mac 上安装 openJDK11
紧接上篇,mac现在基本上作为开发者的主力机,当然也要安装jdk的 首先需要卸载原来的jdk8,如下: ls /Library/Java/JavaVirtualMachines/ sudo rm -r ...
- nlp资料网站
原文地址 http://blog.sina.com.cn/s/blog_574a437f01019poo.html 昨天实验室一位刚进组的同学发邮件来问我如何查找学术论文,这让我想起自己刚读研究生时茫 ...
- HTTP缓存及其合理使用
以前以为HTTP缓存是个简单的事,项目中遇到后才发觉关于缓存实践有挺深的学问. from几篇文章详见: 使用 HTTP 缓存:Etag, Last-Modified 与 Cache-Control 合 ...
- Geoserver GeoWebCache 切图失败 This requested used more time than allowed and has been forcefully stopped. Max rendering time is 60.0s
错误信息: This requested used more time than allowed and has been forcefully stopped. Max rendering time ...
- 12 Best Live Chat Software for Small Business Compared (2019) 最佳的wordpress在线聊天工具推荐插件 来帮你和潜在客户互动
12 Best Live Chat Software for Small Business Compared (2019) Did you know that more than 67% of ...
- 自己动手在win2003系统中添加虚拟网卡
运用虚拟网卡我们可以更好地使用我们的网络,那么在win2003中该怎么操作呢?下面就为大家介绍下具体的步骤 虚拟网卡是用软件来实现虚拟的网卡,通过运用虚拟网卡我们可以更好地使用我们的网络.但是虚拟 ...
- Hive学习笔记——安装和内部表CRUD
1.首先需要安装Hadoop和Hive 安装的时候参考 http://blog.csdn.net/jdplus/article/details/46493553 安装的版本是apache-hive-2 ...
- java interface接口的传值方法
A 类 package interface_test; public class A { private IPresenter ip; public A(IPresenter ip) { this.i ...
- 深度学习中交叉熵和KL散度和最大似然估计之间的关系
机器学习的面试题中经常会被问到交叉熵(cross entropy)和最大似然估计(MLE)或者KL散度有什么关系,查了一些资料发现优化这3个东西其实是等价的. 熵和交叉熵 提到交叉熵就需要了解下信息论 ...