<?xml version="1.0" encoding="utf-8" ?><rss version="2.0"><channel><title><![CDATA[MasterAn的博客]]></title><description><![CDATA[Valar Dohaeris]]></description><link>https://blog.youkuaiyun.com/MasterAn</link><language>zh-cn</language><generator>https://blog.youkuaiyun.com/</generator><copyright><![CDATA[Copyright &copy; MasterAn]]></copyright><item><title><![CDATA[Codeforces 689 D - Friends and Subsequences(数据结构 RMQ +二分)]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/81880536</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/81880536</guid><author>MasterAn</author><pubDate>Tue, 21 Aug 2018 00:36:00 +0800</pubDate><description><![CDATA[题目链接   看过来



题意

给定两个长度为nnn的数列a,ba,ba,b,问有多少个区间[L,R](0≤L≤R&amp;amp;lt;n)[L,R](0≤L≤R&amp;amp;lt;n)[L,R]  (0\leq L \leq Rmax(al,al+1,...,ar)=min(bl,bl+1,...,br)max(al,al+1,...,ar)=min(bl,bl+1,...,br)max(a_l,a_{l+1},.....]]></description><category></category></item><item><title><![CDATA[CodeForces - 140E New Year Garland (DP 计数）]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/81155980</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/81155980</guid><author>MasterAn</author><pubDate>Sun, 22 Jul 2018 16:40:43 +0800</pubDate><description><![CDATA[题意

用m种颜色的彩球装点n层的圣诞树。圣诞树的第i层恰由l[i]个彩球串成一行，且同一层内的相邻彩球颜色不同，同时相邻两层所使用彩球的颜色集合不同。求有多少种装点方案，答案对p取模。

题目链接



题解

等几天写

代码



#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
typedef long long ll;

int mo...]]></description><category></category></item><item><title><![CDATA[Codeforces Round #485 (Div. 2) contest 987]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/81104807</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/81104807</guid><author>MasterAn</author><pubDate>Wed, 18 Jul 2018 20:36:27 +0800</pubDate><description><![CDATA[A. Infinity Gauntlets

水题，模拟

B. High School: Become Human

取对数比较

D.Fair


有n个城市，m条路，保证任意城市都相通，保证任意两个城市之间都只有1条路径。现在，要在某一个城市举办一场盛会，每个城市都会生产1种商品（不同城市之间生产的商品可能相同）共有k种不同的商品，现在，举办盛会需要s种不同的商品。每种商品都需要走到相应的城...]]></description><category></category></item><item><title><![CDATA[BZOJ  4002    有意义的字符串(矩阵快速幂，特征方程）]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/80171520</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/80171520</guid><author>MasterAn</author><pubDate>Wed, 02 May 2018 20:30:53 +0800</pubDate><description><![CDATA[题目链接

分析

这是一个有通项公式的数列。设an=p∗an−1+q∗an−2,an=p∗an−1+q∗an−2,a_n=p*a_{n-1}+q*a_{n-2},

an=(b+d√2)n+(b−d√2)nan=(b+d2)n+(b−d2)na_n={(\frac{b+\sqrt d}{2})}^n+{(\frac{b-\sqrt d}{2})}^n 
由特征方程可知，p=b,q=d−b24p=...]]></description><category></category></item><item><title><![CDATA[URAL 1132Square Root（二次剩余模板）]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/80108457</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/80108457</guid><author>MasterAn</author><pubDate>Fri, 27 Apr 2018 15:13:31 +0800</pubDate><description><![CDATA[题目链接

题意

二次剩余模板题

代码



#include &amp;lt;iostream&amp;gt;
#include &amp;lt;cstdio&amp;gt;
using namespace std;

typedef long long ll;
int k;
ll a,p,w;
struct T{ll x,y;};

T mul_two(T a,T b,ll p)
{
    T ans;
    ans...]]></description><category></category></item><item><title><![CDATA[Codeforces392 C. Yet Another Number Sequence(矩阵快速幂+二项式展开）]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/80106584</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/80106584</guid><author>MasterAn</author><pubDate>Fri, 27 Apr 2018 13:07:54 +0800</pubDate><description><![CDATA[
题目 Yet Another Number Sequence
题意 
 如题
分析 
 二项式展开递推公式，构造矩阵。关于矩阵快速幂的一般情况，请看Luo神的这篇文章。Latex的矩阵太难写了。。。 
请看Acdreamers大佬的分析
代码


#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;

typedef unsigned long ...]]></description><category></category></item><item><title><![CDATA[Codeforces 385E Bear in the Field(矩阵快速幂）]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/80083864</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/80083864</guid><author>MasterAn</author><pubDate>Wed, 25 Apr 2018 18:53:25 +0800</pubDate><description><![CDATA[Source

Problem

一片n∗nn∗nn*n的草莓地，每个位置的初始草莓量为横坐标和纵坐标之和。给出熊的初始位置(sx,sy）(sx,sy）(sx,sy）,以及初始移动速度（dx,dy)（dx,dy)（dx,dy),求这头熊 ttt 秒后的位置。每一秒会发生下列3件事：


速度增加kkk（kkk为该位置的草莓数，即k=x+yk=x+yk=x+y)
熊的位置发生移动，Xt=Xt−1+D...]]></description><category></category></item><item><title><![CDATA[UVAlive3998 （UVA 1404) Prime k-tuple (素数筛法）]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/80066699</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/80066699</guid><author>MasterAn</author><pubDate>Tue, 24 Apr 2018 16:35:33 +0800</pubDate><description><![CDATA[Source



Problem

输入4个正整数a,b,k,sa,b,k,sa,b,k,s,输出区间[a,b][a,b][a,b]内距离为sss的素数kkk元组的个数。



Solution

bbb最大为maxn=2∗109maxn=2∗109maxn=2*10^9,只要筛选SIZE=maxn−−−−−√SIZE=maxnSIZE=\sqrt{maxn}以内的素数。然后每次把在[a,b][...]]></description><category></category></item><item><title><![CDATA[LA 4998 Simple Encryption(不动点迭代，同余）]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/80063058</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/80063058</guid><author>MasterAn</author><pubDate>Tue, 24 Apr 2018 12:49:45 +0800</pubDate><description><![CDATA[Source

Problem

输入正整数K1K1K_1(K1≤50000)K1≤50000)K1\le50000)，找一个12位正整数K2K2K_2使得KK21≡K2(mod1012)K1K2≡K2(mod1012)K_1^ {K_2} \equiv K_2 \pmod {10^{12}}。

Solution

一开始以为是解同余方程，想要构造答案，后来发现想歪了，只能枚举。这个式子可以使用...]]></description><category></category></item><item><title><![CDATA[Codeforces 848A. From Y to Y (思维，构造）]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/80053921</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/80053921</guid><author>MasterAn</author><pubDate>Mon, 23 Apr 2018 17:53:11 +0800</pubDate><description><![CDATA[
Source
Problem

给定一个字符串，看作是n个长度为1的字符串，通过n-1次合并操作可变为一个长度为1的字符串，每次合并 s1,s2s1,s2s1,s2的代价为∑′z′c=′a′f(s1,c)∗f(s2,c)∑c=′a′′z′f(s1,c)∗f(s2,c) \sum _{c='a'} ^{'z'}f(s1,c)*f(s2,c),ccc为s1,s2s1,s2s1,s2都出现的字符，f(...]]></description><category></category></item><item><title><![CDATA[CodeForces 963A - Alternating Sum 等比数列求和 逆元 数论]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/80036453</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/80036453</guid><author>MasterAn</author><pubDate>Sun, 22 Apr 2018 10:09:46 +0800</pubDate><description><![CDATA[
题目链接
题意 
 求等比数列的和并对1e9+91e9+91e9+9取模。
分析 
S=a1(qlen−1)q−1S=a1(qlen−1)q−1S=\frac{a1(q^len -1)}{q-1},q=bk∗(inv(a))k(mod1e9+9),其中len=(n+1)/k,inv(a)为a的逆元q=bk∗(inv(a))k(mod1e9+9),其中len=(n+1)/k,inv(a)为a的逆元...]]></description><category></category></item><item><title><![CDATA[Codeforces Round #467 (Div. 2)-E-Lock Puzzle(思维题，构造）]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/80016170</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/80016170</guid><author>MasterAn</author><pubDate>Fri, 20 Apr 2018 11:19:55 +0800</pubDate><description><![CDATA[
题目链接
题意 
 给定两个长度为n(1≤n≤2000)n(1≤n≤2000)n(1 \le n\le2000)的字符串s,ts,ts,t,问是否能通过不超过610061006100次的shiftshiftshift操作使得sss变成ttt。shift(x)shift(x)shift(x)定义为将字符串最后xxx个字符反转并移至字符串首。若可以，则输出一种可能的方案的操作次数及操作序列。
分析 ...]]></description><category></category></item><item><title><![CDATA[UVA11426 GCD - Extreme (II) 究极GCD 欧拉函数]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/80009404</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/80009404</guid><author>MasterAn</author><pubDate>Thu, 19 Apr 2018 19:13:41 +0800</pubDate><description><![CDATA[
题目链接
题意 
 输入正整数n，求gcd(1,2)+gcd(1,3)+gcd(2,3)+...+gcd(n−1,n),gcd(1,2)+gcd(1,3)+gcd(2,3)+...+gcd(n−1,n),gcd(1,2)+gcd(1,3)+gcd(2,3)+...+gcd(n-1,n),即求所有满足1≤i&amp;lt;j≤n1≤i&amp;lt;j≤n1\le i\lt j\le n的数对(i,j)(i,j)...]]></description><category></category></item><item><title><![CDATA[UVALive3704(Cellular Automaton)]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/80007702</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/80007702</guid><author>MasterAn</author><pubDate>Thu, 19 Apr 2018 17:05:25 +0800</pubDate><description><![CDATA[
题目链接
题意 
 一个细胞自动机含nnn个格子，每个格子的取值为0∼m−10∼m−10{\sim}m-1。给定距离ddd，则每次操作后每个格子的值将变为到它的距离不超过ddd的所有格子在操作之前的值之和除以mmm的余数，其中i和j的距离为min{|i−j|,n−|i−j|}min{|i−j|,n−|i−j|}min\{|i-j|,n-|i-j|\}。给出n，m，d，kn，m，d，kn，m，d，...]]></description><category></category></item><item><title><![CDATA[TopCoder9915（期望递推）]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/80004324</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/80004324</guid><author>MasterAn</author><pubDate>Thu, 19 Apr 2018 14:21:20 +0800</pubDate><description><![CDATA[TopCoder 9915(期望递推)


题目链接
题意 
桌面上有RR R 张红牌和 BBB 张黑牌， 随机打乱顺序后放在桌面上，开始一张一张地翻牌，翻到红牌得到 111 美元，黑牌则付出 11 1 美元。可以随时停止翻牌，在最优策略下平均能得到多少钱。
分析 
用f[i,j]f[i,j]f[i,j]表示剩下iii 张红牌和jjj 张黑牌获得钱的期望。决定翻牌或不翻。不翻牌则期望为 000，翻...]]></description><category></category></item><item><title><![CDATA[UVA10870(Recurrents)]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/78767228</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/78767228</guid><author>MasterAn</author><pubDate>Sun, 10 Dec 2017 20:34:30 +0800</pubDate><description><![CDATA[题目链接矩阵快速幂裸题
代码：
#include <bits/stdc++.h>using namespace std;
typedef long long ll;
struct Matrix{
  ll e[18][18];
};Matrix Multiply(Matrix a, Matrix b,ll d,ll mod)
{
    Matrix ans;
    for(ll i=0; i<d]]></description><category></category></item><item><title><![CDATA[UVA11077 Find the Permutations（排列统计）]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/78766491</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/78766491</guid><author>MasterAn</author><pubDate>Sun, 10 Dec 2017 18:58:06 +0800</pubDate><description><![CDATA[UVA11077 Find the Permutations（排列统计）题目链接
题解（出自训练指南） 
     首先考虑一个简单的问题。任意给出一个排列P，至少需要交换几次才能变成{1,2,…,n}？这个次数也等于从{1,2,…,n}变换到该排列所需的次数。因此，直接把排列P理解成一个置换，并且分解成循环，各循环之间独立。 
     设f(i,j)表示满足“至少需要交换j次才能变成{1,2,…]]></description><category></category></item><item><title><![CDATA[UVA557(概率）]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/78766301</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/78766301</guid><author>MasterAn</author><pubDate>Sun, 10 Dec 2017 18:24:46 +0800</pubDate><description><![CDATA[题目链接
题解 
 根据题意描述，不妨先求出最后两个人吃到不同的汉堡的概率，设其为p。那么易知，前面n-2个人中，有n/2-1个人吃了牛肉堡，剩下的人吃了鸡肉堡。 
因此p[n]=(0.5)^(n-2)C(n-2,n/2-1)，p[n + 1] / p[n] = (2  n - 1)/ (2 * n)。最终答案为1-p。不过可以发现p可以进行递推，因此可以事先算出所有的p值，最后直接输出答案即可。]]></description><category></category></item><item><title><![CDATA[UVA 1646圈图的匹配]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/78763410</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/78763410</guid><author>MasterAn</author><pubDate>Sun, 10 Dec 2017 10:37:46 +0800</pubDate><description><![CDATA[UVA 1646圈图的匹配题目链接
题意 
 n(3<=n<=10000)个节点组成一个圈，求匹配（即没有公共点的边集）的个数。例如，n=4时有7个，n=100时有792070839848372253127个。
题解 
 此题为找规律题，动手画图枚举，当n=5时有11个，n=6时有18个，可以发现，答案为一个斐波拉契数列，数据很大，使用python实现大数即可。
代码
if __name__ ==]]></description><category></category></item><item><title><![CDATA[HDU 3501  Calculation 2]]></title><link>https://blog.youkuaiyun.com/MasterAn/article/details/78510289</link><guid>https://blog.youkuaiyun.com/MasterAn/article/details/78510289</guid><author>MasterAn</author><pubDate>Sun, 12 Nov 2017 10:18:26 +0800</pubDate><description><![CDATA[HDU 3501  Calculation 2题目链接
Problem Description
Given a positive integer N, your task is to calculate the sum of the positive integers less than N which are not coprime to N. A is said to be coprime to]]></description><category></category></item></channel></rss>