[杂题]CSUOJ1413 Area of a Fractal
题意:题中给了图,所以不看字大概也知道
求的是第n个图形的面积。
就是找规律 递推 一类的...
先给结论:
很鬼畜的公式: $\displaystyle\frac{3\times 17^n+2\times 7^n}{5}$
递推式是: $\displaystyle S_n = S_{n-1}\times 17-4\times 7^{n-1}$
重点在于17和7是怎么来的。
在题图的基础上画些个框框



观察可以发现 图1中的 $1\times 1$的方格变成了图2中$\sqrt{17}\times \sqrt{17}$的方格
其中17就是$4\times 4 + 1\times 1$
所以第二个方格的面积为前一个方格的17倍。
显然17倍了之后还不是该图形的面积,因为有
(灰格子)的面积少了。

数一下就会发现4个拐中的每个拐都缺了7块
就这样 神奇的7和17都得到了。。。
然后解啊解啊就能解出那个鬼畜的公式了。
有了公式这题就很简单了
只需要用ex_gcd求出5的逆元,然后套一套公式,模一模就完成了~
代码:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <cmath>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <set>
#include <map>
typedef long long LL;
typedef long double LD;
const double pi=acos(-1.0);
const double eps=1e-;
#define INF 0x3f3f3f
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
typedef pair<int, int> PI;
typedef pair<int, PI > PP;
#ifdef _WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
//#pragma comment(linker, "/STACK:1024000000,1024000000")
//LL quick(LL a, LL b){LL ans=1;while(b){if(b & 1)ans*=a;a=a*a;b>>=1;}return ans;}
//inline int read(){char ch=' ';int ans=0;while(ch<'0' || ch>'9')ch=getchar();while(ch<='9' && ch>='0'){ans=ans*10+ch-'0';ch=getchar();}return ans;}
inline void print(LL x){printf(LLD, x);puts("");}
//inline void read(LL &ret){char c;int sgn;LL bit=0.1;if(c=getchar(),c==EOF) return ;while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();sgn=(c=='-')?-1:1;ret=(c=='-')?0:(c-'0');while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');if(c==' '||c=='\n'){ ret*=sgn; return ; }while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;ret*=sgn;}
const int mod=; LL quick(LL a, LL b)
{
LL ans=;
while(b)
{
if(b & )ans=(ans*a)%mod;
a=(a*a)%mod;
b>>=;
}
return ans%mod;
} void ex_gcd(int a, int b, int &x, int &y)
{
if(b)
{
ex_gcd(b, a%b, x, y);
int tmp=x;
x=y;
y=tmp-(a/b)*y;
}
else
{
x=, y=;
return ;
}
}
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int n;
scanf("%d", &n);
if(n==)
{
printf("1\n");
continue;
}
int x, y;
ex_gcd(, mod, x, y);
print((((*quick(, n))%mod+(*quick(, n))%mod)*x)%mod);
}
return ;
}
CSUOJ 1413
[杂题]CSUOJ1413 Area of a Fractal的更多相关文章
- 正睿OI DAY3 杂题选讲
正睿OI DAY3 杂题选讲 CodeChef MSTONES n个点,可以构造7条直线使得每个点都在直线上,找到一条直线使得上面的点最多 随机化算法,check到答案的概率为\(1/49\) \(n ...
- dp杂题(根据个人进度选更)
----19.7.30 今天又开了一个新专题,dp杂题,我依旧按照之前一样,这一个专题更在一起,根据个人进度选更题目; dp就是动态规划,本人认为,动态规划的核心就是dp状态的设立以及dp转移方程的推 ...
- wangkoala杂题总集(根据个人进度选更)
CQOI2014 数三角形 首先一看题,先容斥一波,求出网格内选三个点所有的情况,也就是C(n*m,3);然后抛出行里三点共线的方案数:C(n,3)*m; 同理就有列中三点共线的方案数:n*C(m,3 ...
- 2019暑期金华集训 Day6 杂题选讲
自闭集训 Day6 杂题选讲 CF round 469 E 发现一个数不可能取两次,因为1,1不如1,2. 发现不可能选一个数的正负,因为1,-1不如1,-2. hihoCoder挑战赛29 D 设\ ...
- Atcoder&CodeForces杂题11.7
Preface 又自己开了场CF/Atcoder杂题,比昨天的稍难,题目也更有趣了 昨晚炉石检验血统果然是非洲人... 希望这是给NOIP2018续点rp吧 A.CF1068C-Colored Roo ...
- Codeforces 杂题集 2.0
记录一些没有写在其他随笔中的 Codeforces 杂题, 以 Problemset 题号排序 1326D2 - Prefix-Suffix Palindrome (Hard version) ...
- 【Java面试】-- 杂题
杂题 2019-11-03 21:09:37 by冲冲 1.类加载器的双亲委派机制 类加载器:把类通过类加载器加载到JVM中,然后转换成class对象(通过类的全路径来找到这个类). 双亲委派机制 ...
- 贪心/构造/DP 杂题选做Ⅱ
由于换了台电脑,而我的贪心 & 构造能力依然很拉跨,所以决定再开一个坑( 前传: 贪心/构造/DP 杂题选做 u1s1 我预感还有Ⅲ(欸,这不是我在多项式Ⅱ中说过的原话吗) 24. P5912 ...
- 贪心/构造/DP 杂题选做Ⅲ
颓!颓!颓!(bushi 前传: 贪心/构造/DP 杂题选做 贪心/构造/DP 杂题选做Ⅱ 51. CF758E Broken Tree 讲个笑话,这道题是 11.3 模拟赛的 T2,模拟赛里那道题的 ...
随机推荐
- jQuery 黑白插件
1 add jQuery and plug in to the page <script src="js/jquery.min.js"></script> ...
- 第五章 jQuery中的动画
通过jQuery中的动画方法,能轻松地为网页添加精彩的视觉效果,给用户一种全新体验. 1.show()方法和hide()方法 该方法的功能与css()方法设置display属性效果相同. 给show( ...
- android手机震动
Vibrator是安卓提供的震动器,其没有构造器,通过getSystemService(Context.VIBRATOR_SERVICE)方法获取对象.但使用此类时需要在清单文件中添加访问权限andr ...
- SQL 树结构统计数据
create table #Tmp( ID int IDENTITY (1,1) not null, name varchar(50), sl int); DECLARE @ID VARCHAR(36 ...
- WPF嵌入百度地图完整实现
无论是做App还是web开发,很多都会用到地图功能,一般都会调用第三方的API实现地图功能!而正如国内的地图API提供方,基本上对Android.IOS和web开发提供了很完整的一套API,但是对于桌 ...
- OC1_类与对象
// // main.m // OC1_类与对象 // // Created by zhangxueming on 15/6/9. // Copyright (c) 2015年 zhangxuemin ...
- props验证
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 修改placeholder颜色
#contact_info为textarea的ID #contact_info::-webkit-input-placeholder{ color:#999;}#contact_info:-moz-p ...
- QML鼠标事件实现变色矩形
QML支持鼠标事件处理,我们可以利用这个来实现一个变色矩形示例,代码如下: import QtQuick 2.4 import QtQuick.Controls 1.3 import QtQuick. ...
- js中的in-for循环
<!doctype html><html lang="en"> <head> <meta charset="UTF-8" ...