H. Eyad and Math   time limit per test 2.0 s memory limit per test 256 MB input standard input output standard output Eyad was given a simple math problem, but since he is very bad at math he asked you to help him. Given 4 numbers, a, b, c, and d. Yo…
H. Eyad and Math time limit per test 2.0 s memory limit per test 256 MB input standard input output standard output Eyad was given a simple math problem, but since he is very bad at math he asked you to help him. Given 4 numbers, a, b, c, and d. Your…
我们在推导机器学习公式时,常常会用到各种各样的对数,但是奇怪的是--我们往往会忽略对数的底数是谁,不管是2,e,10等. 原因在于,lnx,log2x,log10x,之间是存在常数倍关系. 回顾学过的数学知识,换底公式如下: 则有 故我们不用纠结对数公式中底数究竟是谁,常数倍关系往往对最后结果不产生影响…
\(>Codeforces \space 1037\ H. Security<\) 题目大意 : 有一个串 \(S\) ,\(q\) 组询问,每一次给出一个询问串 \(T\) 和一个区间 \([l,r]\) ,要求找出 \(S\) 在 \([l,r]\) 之间的子串中字典序大于 \(T\) 且最小的 \(1 \leq |S|\leq 10^5, 1\leq q \leq 2 \times 10^5\) 解题思路 : 其实这个题一点意思都没有,就是一个 \(sam\) + 线段树合并裸题.. 但…
题目链接  Jamie and Tree 题意  给定一棵树,现在有下列操作: $1$.把当前的根换成$v$:$2$.找到最小的同时包含$u$和$v$的子树,然后把这棵子树里面的所有点的值加$x$: $3$.查询以$v$为根的子树的点权之和. 这道题其他都是常规操作,就是当前根结点为$cnt$的时候求$x$和$y$的$LCA$(操作$2$要用到) 我们假定解题的时候根一直不变(我一般都设$1$为根结点) 答案为$LCA(x,y)$ $xor$ $LCA(x, cnt)$ $xor$ $LCA(y…
I. Move Between Numbers   time limit per test 2.0 s memory limit per test 256 MB input standard input output standard output You are given n magical numbers a1, a2, ..., an, such that the length of each of these numbers is 20 digits. You can move fro…
题目链接: http://codeforces.com/contest/1187/problem/E 题意: 给出一颗树,找到一个根节点,使所有节点的子节点数之和最大 数据范围: $2 \le n \le 2 \cdot 10^5$ 分析: 最暴力的方法是枚举所有的根节点,计算他们子节点之和,复杂度是$O(n^2)$ 但是可以发现,$a$作为根节点和$b$作为根节点,只有$a,b$节点的子节点数有变化 根的子节点数肯定是$n$,与他交换的点节点数是$x$的话,那么根的子节点数就变成$n-x$,交…
Codeforces 题面传送门 & 洛谷题面传送门 一种换根 dp 的做法. 首先碰到这类题目,我们很明显不能真的把图 \(G\) 建出来,因此我们需要观察一下图 \(G\) 有哪些性质.很明显我们可以把它看作 \(T_1,T_2\) 上分别有一个标记,每次可以将 \(T_1,T_2\) 上的某个标记沿着某条边移动一步,问 \(k\) 步之后标记刚好回到原位的方案数是多少. 显然两棵树是独立的,因此可以分开来考虑,我们记 \(dp1_{i,j}\) 表示 \(T_1\) 中从 \(i\) 开始…
Problem H. Hell on the MarketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86821#problem/H Description Most financial institutions had become insolvent during financial crisis and went bankrupt or…
D. Bash and a Tough Math Puzzle time limit per test 2.5 seconds memory limit per test 256 megabytes input standard input output standard output Bash likes playing with arrays. He has an array a1, a2, ... an of n integers. He likes to guess the greate…
赛后补题,还是要经常回顾,以前学过的匈牙利都忘记了,“猪队友”又给我讲了一遍... 怎么感觉二分图的匈牙利算法东西好多啊,啊啊啊啊啊啊啊啊啊(吐血...) 先传送一个写的很好的博客,害怕智障找不到了.大神膜%%%    Orz H - Words from cubes Informikas was cleaning his drawers while he found a toy of his childhood. Well, it's not just a toy, it's a bunch…
题意:给你四个数,求出a^b是否小于c^d,是的话输出<,否则输出>; 思路:因为数据很大,所以我们需要降低数据的规模,比如用一个log10()函数,这就能解决了,注意,要用scanf输入: 代码: #include<iostream> #include<algorithm> #include<cstdio> #include<cmath> using namespace std; int main() { int t; double a,b,c…
我--又诈尸了-- 代码几乎都不会写了,打场CF居然上分啦,开心!(虽然还是比不过列表里的各路神仙) 题目链接 题目描述 一棵\(n\)个点的有根树,规定一种dfs序(规则:编号小的点优先dfs),\(m\)次询问一个点\(u\)和一个区间\([l, r]\),求dfs序在这个区间内的叶子中,到\(u\)最小的距离. \(n, m \le 500000\) 题解 这题--很简单-- 题面一上来给个什么欧拉遍历定义--我吓得比赛中没看这题--(实际上码量对于代码几乎都不会敲的退役选手来说,不是非常…
E. The Architect Omar   time limit per test 1.0 s memory limit per test 256 MB input standard input output standard output Architect Omar is responsible for furnishing the new apartments after completion of its construction. Omar has a set of living…
K. Malek and Summer Semester   time limit per test 1.0 s memory limit per test 256 MB input standard input output standard output Malek registered n courses for the summer semester. Malek has a success rate m, which means he has to succeed at least i…
还有J题,J题自己并不是,套的板子,大家写的都一样,因为大家都是套板子过的,贴一下代码,等学会了写一篇博客... J.Boxes Game 代码: 1 //J. Boxes Game-取数博弈-不会,套的板子 2 #include<iostream> 3 #include<algorithm> 4 #include<cstdio> 5 #include<cstring> 6 #include<cmath> 7 using namespace st…
F. Building Numbers   time limit per test 3.0 s memory limit per test 256 MB input standard input output standard output In this problem, you can build a new number starting from 1, by performing the following operations as much as you need: Add 1 to…
B. Linear Algebra Test   time limit per test 3.0 s memory limit per test 256 MB input standard input output standard output Dr. Wail is preparing for today's test in linear algebra course. The test's subject is Matrices Multiplication. Dr. Wail has n…
2017 JUST Programming Contest 3.0 昨天的训练赛,打的好难过,因为被暴打了,写了8题,他们有的写了9题,差了一道dp,博客上写7道题的题解. 因为有一道是套板子过的,并不懂,他们说是取数博弈,也有学长说是记忆化dp,等学会了再写博客... 先占个坑,D题dp,J题记忆化dp(取数博弈)... 写其他的题解,这场比赛感触很深,测评姬一开始睡觉了,emnnn,然后发生了很多有趣的故事... 卡数组大小,卡输入输出,长个脑子了,不要轻易用cout,用的话关流同步ios:…
现在有n个整数,在这n个数中找出k个数,保证这k个数中任意两个数差的绝对值可以被m整除. Input第一行输入三个整数n,k,m(2<=k<=n<=100000,1<=m<=100000). 第二行包含n个整数a1,a2,...,  an(0 <= ai <= 10^9 ).Output如果不存在这样的k个数,输出"No":否则输出"Yes"后,在下一行输出这k个数,数与数之间用空格隔开. (存在多种情况,输出任意一种).E…
题目链接:http://codeforces.com/problemset/problem/888/D 题意: 给定n,k,问你有多少种1到n的排列,满足至少有n-k个a[i] == i. (4 <= n <= 1000, 1 <= k <= 4) 题解: 转换题意: 给定n,k,问你有多少种1到n的排列,满足最多有k个a[i] != i. D(i)表示1到i的排列的错排方案数. 那么ans = ∑(C(n,i) * D(i)) + 1,其中i∈[2,k]. ps: 错排递推式:D…
http://codeforces.com/problemset/problem/348/A A. Mafia time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day n friends gathered together to play "Mafia". During each round of the g…
A. An Olympian Math Problem 54.28% 1000ms 65536K   Alice, a student of grade 66, is thinking about an Olympian Math problem, but she feels so despair that she cries. And her classmate, Bob, has no idea about the problem. Thus he wants you to help him…
D. Iterated Linear Function time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x))for n > 0. For the…
以10为底的log函数: 形式为 double  log10(double  x) 以e为底的log函数(即 ln)double log (double x) 如何表达log 以a为底b的对数: 用换底公式:可以表达为:log(a)/log(b) #include<iostream> #include<cmath> using namespace std; int main() { double a=3.456; cout<<log(a)<<endl;//l…
fabs()绝对值函数 #include<stdio.h> #include<math.h> int main(){ double db=-12.56; printf("%.2f\n", fabs(db)); ; } floor()向下取整:ciel()向上取整 不管四舍五入,向上取整必+1 #include<stdio.h> #include<math.h> int main(){ double db1=-5.2, db2=5.2; p…
啃书部分已单独做成Gitbook了,后续不再更新.详情访问个人网站ccoding.cn或ccbyte.github.io 说在前面 一直想刷算法找不到很适合的书,后来发现考PAT很多推荐<算法笔记>,看了一下挺不错的,因为自己很久没用C了,有些细节忘了,而这本书是从基本写起应该还不错. 基础部分为五章(2~6:C基础/排序/查找/递归/贪心/STL模板库) 提高篇有六章(7~13:栈/队列/链表/树/图/动态规划/hash和KMP) 先看基础篇吧,也恢复一下写C的手感. 基础篇内容简单一些但也…
三角函数 1.cos 函数 --- 求x的余弦值,返回弧度x的余弦值.(弧度=角度×PI/180). 函数原型 double cos(double x); 函数参数:弧度值 用例:v = cos (x); 2.sin 函数 --- 求x的正弦值,返回弧度x的正弦值.(弧度=角度×PI/180). 函数原型 double sin(double x); 函数参数:弧度值 用例:v = sin (x); 3.tan 函数 --- 求x的正切值,返回弧度x的正切值.(弧度=角度×PI/180). 函数原…
小明是一个聪明的孩子,对数论有着很浓烈的兴趣.他发现求1到正整数10^n (10的n次方)之间有多少个素数是一个很难的问题,该问题的难点在于决定于10^n 值的大小. 告诉你n的值,并且用ans表示小于10^n的素数的个数. 现在的问题是:ans这个数有多少位. 输入数据有若干组,每组数据包含1个整数n(1 < n < 1000000000),若遇到EOF则处理结束. ->题解:素数有无穷多个,能估计出小于一个正实数X的素数有多少个,并用F(x)表示, 随着X的增长, F(x)  /  …
总所周知,我们在高中学过对数函数,记作y=logax.下面是百度百科关于对数函数的描述: 对数的定义:一般地,如果ax=N(a>0,且a≠1),那么数x叫做以a为底N的对数,记作x=logaN,读作以a为底N的对数,其中a叫做对数的底数,N叫做真数. 一般地,函数y=logax(a>0,且a≠1)叫做对数函数,也就是说以幂为自变量,指数为因变量,底数为常量的函数,叫对数函数. 其中x是自变量,函数的定义域是(0,+∞).它实际上就是指数函数的反函数,可表示为x=ay.因此指数函数里对于a的规定…