03 2015 档案
摘要:动态规划基础例题,要理解状态和状态转移方程。。。 #include using namespace std;int kase = 0;int n, T, t[80];int M1, M2, st1[64], st2[64];bool has_train[512][64][2];int dp[51...
阅读全文
摘要:这道题有点像翻煎饼那题,方法不限,只要次数在9^6之内即可。 从前到后依此选择数,最多只需要两次就可以将每个数放到正确位置。 #include using namespace std;int a[10240];void change(const int l, const int r){ f...
阅读全文
摘要:这题用了冒泡排序的思想,不过紫书上的描述有误,建议参考原题。 #include using namespace std;deque a;vector res;bool is_order(){ for (int i = 1; i != a.size(); ++i) if (a[i] > n, n...
阅读全文
摘要:不想说这题有多么水了,最简单的DFS题了,但是!我花了N天在杭电用G++交了20多遍一直超时,最后改C++交过了!! 这是什么情况!!无语了!! #define _CRT_SECURE_NO_WARNINGS#include #include #include const int maxn = ...
阅读全文
摘要:这题关键就是递推公式,注意紫书上推的c(k)那里貌似有点问题,应该是c(k-1)。 另外2^k方的计算可以用1using namespace std;using LL = long long;LL C[32] = {1};LL g(LL k, LL i){ if(i (1LL= (1LL...
阅读全文
摘要:最水的题,挺简单,用数学做的,刚开始判断负数写成了-1失误超时了. #include using namespace std;int main(){ int n, kase = 0; while(cin >> n, n > 0) printf("Case %d: %d\...
阅读全文
摘要:循环遍历数组即可,注意临界条件的判断。 #include using namespace std;const int maxn = 102400;int p[maxn], q[maxn];int main(){ //freopen("in.txt", "r", stdin); int...
阅读全文
摘要:这题算贪心中最简单的,属于背包问题吧,写的效率有点低,用数组加指针控制应该更好。 #include #include #include #include #include using namespace std;int main(){ int T; cin >> T; while(...
阅读全文
摘要:Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point lo...
阅读全文
摘要:Problem Description 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。你的任务是,对于给定的N,求出有多少种合法的放置方法。 #include #include #include using ...
阅读全文
摘要:数学题,寻找斐波那契取模后的周期T,然后求Mod_Fib(a^b % T)即可。 求a^b % T时要用快速幂来计算,详细方法为http://blog.csdn.net/kun768/article/details/42344897 #include #include using LLU = u...
阅读全文
摘要:循环赛日程表问题问题描述: 设有n(n = 2^k)位选手参加网球循环赛,循环赛共进行n-1天,每位选手要与其他n-1位选手比赛一场,且每位选手每天必须比赛一场,不能轮空。试按此要求为比赛安排日程: (1) 每个选手必须与其他n-1个选手各赛一场; (2) 每个选手一天只能赛一场; (3) ...
阅读全文
摘要:题目大意:有n个牛肉汉堡和n个鸡肉汉堡给2n个孩子吃。每个孩子在吃之前都要抛硬币,正面吃牛肉汉堡,反面吃鸡肉汉堡。如果剩下的所有汉堡都一样,则不用抛硬币。求最后两个孩子吃到相同汉堡的概率。 正面不好思考,考虑最后两个孩子吃不同汉堡的概率。则根据概率相关知识,P(n) = (1 / 2) ^ (2...
阅读全文
摘要:纯粹数学题,推公式吧。注意边界处理精度控制就可以了。 #include #include #define EPS 1e-7int main(){ int T; scanf("%d", &T); while (T--){ double a, b, S; scanf("%lf %lf %lf", ...
阅读全文
摘要:比较水的一题,找到方法就好说了。 #include using namespace std;char tab[128][128];int main(){ int h, w; while (cin >> h >> w){ cin.get(); for (int i = 0; i > tab[i...
阅读全文
摘要:通过这题学习了线性筛法素数打表的方法,题目本身更像数学思考题。 #include #include #include #include #include using namespace std;using LL = long long int;const int maxn = 1024000;b...
阅读全文
摘要:基础题,就用基本方法即可,计算约数时算到sqrt(n)即可,要注意(int)sqrt(n)和n的关系。 #include #include #include using namespace std;int main(){ int T; cin >> T; while (T--){ int L,...
阅读全文
摘要:用打表的方法来做,蕴含着一种递推的思想。 #include #include using namespace std;int n, res[1024];const int MOD = 1e9 + 7;void init() { res[1] = res[2] = 1; for (int i = ...
阅读全文
摘要:纯粹找规律的一小学数学题,空格处的数可有输入计算得出,每个6格三角形为一个计算单位。 #include #include using namespace std;int tab[10][10];int main(){ int T; cin >> T; while (T--){ for (int...
阅读全文
摘要:高中数学数列方法做的,打表大法好,全程打表。 计算一段数的和,用S(n~m) = S(m) - S(n-1)做的。 #include using namespace std;const int maxn = 10001;bool isp[maxn];int cnt, p[2000], sum[2...
阅读全文
摘要:这道题在数据结构这一章里算是简单的,但是很容易WA和RE,可能得debug很长时间。 值得注意的地方: 1.纸牌被处理的次数中,每次发牌并且检查一次匹配,算处理一次,而不是四次 2.查看匹配的时候,如果一次匹配成功并且删除了三张纸牌,要继续检查是否匹配,这是个循环的过程 3.可以通过用set记录...
阅读全文

浙公网安备 33010602011771号