1 | int gcd(int n,int m)//n>m |
1 | int gcd(int n,int m)//n>m |
1 |
<https: //daringfireball.net/projects/markdown/syntax>
The full documentation of Markdown’s syntax
|Hash函数|数据1|数据2|数据3|数据4|数据1得分|数据2得分|数据3得分|数据4得分|平均分| |—-|—-|—-|—-|—-|—-|—-|—-|—-|—-| |BKDRHash|2|0|4774|481|96.55|100|90.95|82.05|92.64| |APHash|2|3|4754|493|96.55|88.46|100|51.28|86.28| |DJBHash|2|2|4975|474|96.55|92.31|0|100|83.43| |JSHash|1|4|4761|506|100|84.62|96.83|17.95|81.94| |RSHash|1|0|4861|505|100|100|51.58|20.51|75.96| |SDBMHash|3|2|4849|504|93.1|92.31|57.01|23.08|72.41| |PJWHash|30|26|4878|513|0|0|43.89|0|21.95| |ELFHash|30|26|4878|513|0|0|43.89|0|21.95|
Tom was on the way home from school. He saw a matrix in the sky. He found that if we numbered rows and columns of the matrix from 0, then, $ {a} _ {i,j}={C} _ {i}^{j}$
if i < j, $ {a}_{i,j}=0$
Tom suddenly had an idea. He wanted to know the sum of the numbers in some rectangles. Tom needed to go home quickly, so he wouldn’t solve this problem by himself. Now he wants you to help him.
Because the number may be very large, output the answer to the problem modulo a prime p.
Multi test cases(about 8). Each case occupies only one line, contains five integers, $ x_{1}、y_{1}、x_{2}、y_{2}、p.
x_{1}\leq x_{2}\leq {10}^{5},y_{1}\leq y_{2}\leq {10}^{5},2\leq p\leq {10}^{9}$ .
###Latex公式测试
行内公式 $ \delta = \beta / (\alpha + 1) $
行间公式
$$
\frac{O}{I} \approx \frac{A}{1+AF}
$$
$$ 上下标 U_o = A^2 * ( U_+ - U_- ) $$
$$ 上下标 (U_o = A^2 * ( U_+ - U_- )) $$
$$ 上下标 [U_o = A^2 * ( U_+ - U_- )] $$
积分
$ \int_1 ^2 sin x dx $
方程组
$$
\begin{aligned}
\dot{x} & = \sigma(y-x) \newline
\dot{y} & = \rho x - y - xz \newline
\dot{z} & = -\beta z + xy
\end{aligned}
$$
$$
\begin{eqnarray}
&& \frac{\partial x}{\partial C_{ikj}} \
&& \frac{\partial C_{ikj}}{\partial R_{ik}} \
&& \frac{\partial C_{ikj}}{\partial R_{jk}}\
&& a = R_{ik}^2-R_{jk}^2 , b = (R_{ij}^4-a^2)^2
\end{eqnarray}
$$
$$
\left{ \Sigma= { (\theta,\varphi)|0\le \theta \le 2\pi,0\le \varphi \le\frac{\pi}{2} \right}
$$
Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 65535/65536 K (Java/Others)
Yuanfang is puzzled with the question below:
There are n integers, a1, a2, …, an. The initial values of them are 0. There are four kinds of operations.
Operation 1: Add c to each number between ax and ay inclusive. In other words, do transformation ak<—ak+c, k = x,x+1,…,y.
Operation 2: Multiply c to each number between ax and ay inclusive. In other words, do transformation ak<—ak×c, k = x,x+1,…,y.
Operation 3: Change the numbers between ax and ay to c, inclusive. In other words, do transformation ak<—c, k = x,x+1,…,y.
Operation 4: Get the sum of p power among the numbers between ax and ay inclusive. In other words, get the result of axp+ax+1p+…+ay p.
Yuanfang has no idea of how to do it. So he wants to ask you to help him.
There are no more than 10 test cases.
For each case, the first line contains two numbers n and m, meaning that there are n integers and m operations. 1 <= n, m <= 100,000.
Each the following m lines contains an operation. Operation 1 to 3 is in this format: “1 x y c” or “2 x y c” or “3 x y c”. Operation 4 is in this format: “4 x y p”. (1 <= x <= y <= n, 1 <= c <= 10,000, 1 <= p <= 3)
The input ends with 0 0.
For each operation 4, output a single integer in one line representing the result. The answer may be quite large. You just need to calculate the remainder of the answer when divided by 10007.
5 5
3 3 5 7
1 2 4 4
4 1 5 2
2 2 5 8
4 3 5 3
0 0
307
7489
1 | struct Node |
1 |
|
ACM - ICPC Regionals 2014 Bangkok 亚洲区域赛 国外某数学题
艰辛坎坷的探索历程
设 $ {f(n)=C_{n}^{r}(n∈N^{ * },r∈[0,n])} $中奇数的个数。
题意是说,求出 $ \sum f(k),k∈[low,high] $
庞大的数据, $ n≤16\times{10^{11}}. $
判断给定 $ n∈N^{ * } $时 $ C_n^r(r∈[0,n]) $的奇偶性。 不难往n,r的二进制表示方向考虑。
查阅他人博客获得结论: $ n{ & }r==r $时 $ C_n^r $为奇数。 然而本题中无需直接应用这一“定理”,所要做的是统计。
拿出纸笔推算发现,若n的二进制表示中有d个1,则 $ C_n^r(r∈[0,n]) $中存在 $ 2^d $个奇数。
研究 $ f(n) $ 的递推关系及通项。 编写暴力程序 $ O(n^2) $ ,打表观察 $ n∈[0,64) $ 时 $ f(n) $ 的取值:
1
2
2 4
2 4 4 8
2 4 4 8 4 8 8 16
2 4 4 8 4 8 8 16 4 8 8 16 8 16 16 32
2 4 4 8 4 8 8 16 4 8 8 16 8 16 16 32 4 8 8 16 8 16 16 32 8 16 16 32 16 32 32 64
第一行 $ f(0)=1 $ 作为边界条件, 第二行 $ f(1)=2 $ ,随后各行的第k行的 $ 2^{k-2} $ 个数分别表示 $ f(2^{k-2}),f(2^{k-2}+1),…,f(2^{k-1}-1) $ 。
通过不懈的努力,观察发现从第3行开始,每行的前半部分与前一行完全一致,每行的后半部分的各个f值恰为前半部分对应位置的f值的2倍。
出于数列直觉,我们尝试求解各行的和构成的数列的递推以及通项。
$ a_1=1 $
$ a_2=2 $
$ a_3=a_2+2\times{a_2}=3\times{a_2}=6 $
…
$ a_n=a_{n-1}+2\times{a_{n-1}}=3\times{a_{n-1}}(n\geq 3) $(递推公式)
通项公式:
$$
\begin{equation} a_n= \begin{cases} 1 &\mbox{$n=1$}\newline 2 &\mbox{$n=2$}\newline 2\times3^{n-2} &\mbox{$n\geq 3$} \end{cases} \end{equation}
$$
$$
\begin{equation} S_n=\sum\limits_{i=1}^{n} {a_i}= \begin{cases} 1 &\mbox{$n=1$}\newline 3 &\mbox{$n=2$}\newline 3+6\times\frac{1-3^{n-2}}{1-3}=3+3\times{(3^{n-2}-1)}=3^{n-1} &\mbox{$n\geq 3$} \end{cases} \end{equation}
$$
$$
S_n=3^{n-1}(a_n的前n项和的公式)
$$
化简后上面这个公式样子够好看了吧?
再看一下第2步发现的规律,应用“二分”手段高效地求解,而且真的可以二分求解。
具体地说,就是先置求解区间 $ [l,r) $ (左闭右开)的端点于每行的头尾( $ l=2^{i-2},r=2^{i-1} $ ),利用上一步所得公式计算该区间的 $ 左端点前缀和U=\sum\limits_{k=1}^{2^{i-2}} {f(k)} $ 与 $ 右端点前缀和V=\sum\limits_{k=1}^{2^{i-1}-1} {f(k)} $ 后,不断地对区间折半,总可以确定新区间的左端点前缀和与右端点前缀和。
当区间缩至一点时, $ U==V==f(k) $,即能得到我们所求,而无需计算出[1..n]的每个函数值。
以上所解决的并不是最终答案,而是前缀和 $ \sum\limits_{k=1}^{n} {f(k)} $ ;
不过走到这一步已经很好办了, $ ans=\sum\limits_{k=low}^{high} {f(k)}=\sum\limits_{k=1}^{high} {f(k)}-\sum\limits_{k=1}^{low-1} {f(k)} $
PS:写完代码后,用极大的n值测试一下,事实上 $ \sum\limits_{k=1}^{n} {f(k)} $已经超出了int64的范围。其他的细节不必多说了。
1.319s AC java代码:
1 | /** |
0.279s AC cpp代码:
1 |
|
转载源页面
poj 3070
1 |
|
ACM-ICPC Live Archive Regionals 2014 >> Asia - Kuala Lumpur 6811 - Irrigation Lines
参见:转载前页面
怎么读题时就没发现“每行每列各有一个水阀”?这是把问题转化成二分图模型的关键啊
1 |
|
像这样搞错映射关系,不是个很好的情况
1 |
|
早就听说#define有不靠谱之处,平时写代码也对它多有抵触情绪;今日偶然一用,大跌眼镜
1 |
通常预处理器只对宏定义做相应的字符替换,编译器不做语法检查;visual studio 则能在替换后检查语法。
无编译错误,调用的时候无论如何都算不对
1 | return MAX(Depth(T->lchild), Depth(T->rchild)) + 1; |
加号的运算优先级如何处理?