01 2021 档案
摘要:题目链接: poj2070 Fibonacci \(Fibonacci\) 数列有: \(F_0=0, F_1=1, F_n=F_{n-1}+F_{n-2}(n\ge 2)\) . 于是 \[ \begin{align} \begin{pmatrix} F_{n+1} & F_n \\ F_n &
阅读全文
摘要:A. K-divisible Sum /** * Educational Codeforces Round 103 (Rated for Div. 2) * c++11 */ #include <bits/stdc++.h> using namespace std; typedef long lon
阅读全文
摘要:题目链接: hdu5392 ( Infoplane in Tina Town ) 说来惭愧,鄙人费了好些功夫才读懂题意。。 对第一个样例: \({1,2,3}\) 执行一次宏变为 \(1,3,2\) ,再执行一次宏变为 \(1,2,3\) 。执行两次宏后回到原序列,因此答案为 \(2\) 。
阅读全文
摘要:题目链接: 1061 ( Rightmost Digit ) /** * hdu1061 Rightmost Digit(快速幂取模) * */ #include <iostream> using namespace std; typedef long long LL; LL fastPow(LL
阅读全文
摘要:题目链接: 2817 ( A sequence of numbers ) 算术序列即等差数列,几何序列即等比数列。 等差数列 \(a_k=a_1+(k-1)\cdot d\) ( \(d\) 为公差) 等比数列 \(a_k=a_1\cdot q^{k-1}\) ( \(q\) 为公比),由于 \(k
阅读全文
摘要:A. Nezzar and Colorful Balls 直接求出现次数最多的数字的个数就好了。 // Codeforces Round #698 (Div. 2) #include <bits/stdc++.h> using namespace std; typedef long long LL;
阅读全文
摘要:题目链接: hdu5686 ( Problem B ) \(dp[n][1]\) 代表长度为 \(n\) 的全 \(1\) 序列构成的新序列中以 \(1\) 为尾的序列数量; \(dp[n][0]\) 代表长度为 \(n\) 的全 \(1\) 序列构成的新序列中以 \(2\) 为尾的序列数量。 递推
阅读全文
摘要:题目链接: hdu5666 ( Segment ) \(c\)++ \(AC\) 代码: /** * hdu5666 Segment * q为质数,故题意为求解x+y=p与坐标轴围成的三角形区域内的整数坐标点的数目:(q-1)*(q-2)/2 */ #include <iostream> using
阅读全文
摘要:题目链接: hdu1316 ( How Many Fibs? ) \(java\ AC\) 代码: /** * hdu1316 How Many Fibs? * */ import java.math.BigInteger; import java.util.Scanner; public clas
阅读全文
摘要:题目链接: 1063 ( Exponentiation ) \(java\ AC\) 代码,只有输出格式处理稍微复杂一点。 /** * hdu1063 Exponentiation * */ import java.math.BigDecimal; import java.util.Scanner;
阅读全文
摘要:题目链接: hdu1047 Integer Inquiry 对于 \(java\) 来说, 这就是一道简单的累加题。 /** * hdu1047 Integer Inquiry * */ import java.math.BigInteger; import java.util.Scanner; p
阅读全文
摘要:题目链接: hdu1042 N! \(c\)++ \(AC\) 代码: /** * hdu1042 N! * 0 <= N <= 10000 */ #include <iostream> #include <iomanip> #include <cstring> using namespace st
阅读全文
摘要:题目链接: hdu1401 Solitaire 这是一道十分适合双向广搜的题。 考虑到 \(4\) 个相同棋子在一个 \(8\times8\) 的棋盘上,总状态数不过 \(\C_{64}^4=635376<1e6\) 种,单向广搜应该也不会超时,不过我第一次试了下结果还是 \(TLE\) 了,猜想可
阅读全文
摘要:题目链接: poj1077 Eight 难点在如何标记已遍历的的八数码状态:利用康托展开可将全排列一一映射到自然数。 解决状态标记问题,剩下的就与普通 \(bfs\) 无异了。 初始化从终态开始搜索,遍历八数码所有的状态。随后根据输入的状态直接回溯到终态。 /** * poj1077 Eight *
阅读全文
摘要:题目链接: hdu4460 ( Friend Chains ) 将每个人当作顶点,朋友关系当作顶点之间权值为 \(1\) 的边,建立无向图。 图上任意两点间最短距离的最大值即为所求,从每个顶点 \(bfs\) 就最大距离即可,时间复杂度 \(O(n^2)\) 。 特别地,若该图不连通,则输出 \(-
阅读全文
摘要:题目链接: hdu1240 ( Asteroids! ) /** * hdu1240 Asteroids * 三维bfs,不过6个方向而已 */ #include <cstdio> #include <queue> #include <iostream> #include <cstring> #in
阅读全文
摘要:搜索空间不过 \(1e4\) ,暴力 \(bfs\) 即可得到最少操作。 输出每次操作可能需要在 \(bfs\) 时手动模拟队列,方便找到最优解后回溯输出。 /** * poj3414 Pots * */ #include <cstdio> #include <queue> #include <io
阅读全文
摘要:方法一 由于四位数的素数仅有 \(1061\) 个,因此可以预处理所有的四位素数,每两个素数之间只有一位不同则有边,由此建出一个无向图。预处理后便成了裸的图上 \(bfs\) 。 /** * poj3126 Prime Path * 四位数的素数仅1061个 * prime[169] = 1009,
阅读全文
摘要:这题直接 \(bfs\) 居然能过是我没想到的。 /** * poj1426 Find The Multiple * */ #include <cstdio> #include <queue> using namespace std; typedef long long LL; LL bfs(int
阅读全文
摘要:这么简单的暴搜问题也能wa爆心态,我果然还是一如既往的菜。 /** * poj3278 Catch That Cow * bfs */ #include <cstdio> #include <cstring> #include <algorithm> #include <queue> using n
阅读全文
摘要:一道裸的 \(bfs\) ,然而还是折腾到我了。 /** * hdu1312 Red and Black * bfs */ #include <iostream> #include <cstdio> #include <queue> using namespace std; #define pii
阅读全文
摘要:一个简单的中缀表达式求值问题,对每一行单独处理,操作数与运算符交替读入处理即可。 #include <iostream> #include <iomanip> #include <sstream> #include <stack> #include <string> using namespace
阅读全文
摘要:这本应是一道很简单的模拟题,时间复杂度,然而数据范围,n和m最大为32767,用模拟理应超时。 一通百度过后,发现很多人用模拟,然后我也模拟了一下,A了。 1 #include <cstdio> 2 #include <vector> 3 #include <numeric> 4 #include
阅读全文

浙公网安备 33010602011771号