自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

许少y

Codes change the world !

  • 博客(46)
  • 资源 (2)
  • 收藏
  • 关注

原创 hdoj--1069 Monkey and Banana(dp)

hdoj 1069题解按面积排序,LIS.#include <iostream>#include <vector>#include <fstream>#include <algorithm>using namespace std;struct block{ int x, y, z; block(int x, int y, int z):x(x), y(y), z(z){}}

2016-03-29 18:28:12 638

原创 UVa--10048 Audiophobia(floyd)

UVa 10048题意求图中两点最大噪声值最小的路径。题解Floyd算法变形一下: d[i][j]=min(d[i][j],max(d[i][k],d[k][j]))d[i][j] = min(d[i][j], max(d[i][k], d[k][j]))#include <bits/stdc++.h>using namespace std;const int maxn = 105;const

2016-03-29 17:32:16 422

原创 nyoj--93 汉诺塔(三)(stack)

nyoj 93题解用三个栈模拟。#include <iostream>#include <cstdio>#include <stack>#include <vector>using namespace std;int t, p, q;bool solve(){ vector< stack<int> > h(4); int from, to; for(int i =

2016-03-26 16:36:02 489

原创 codeforces--652B z-sort(sorting)

传送门题解z-sorted sequence 有如下特点: a1≤a2≥a3≤a4≥a5≤a6≥a7...a_1\le a_2\ge a_3 \le a4\ge a_5\le a_6\ge a_7... 可以看到,偶数位置上的数总是不小于两边奇数位置上的数,排序后按此规则填即可。#include <bits/stdc++.h>using namespace std;const int maxn

2016-03-26 08:42:38 508

原创 codeforces--652A Gabriel and Caterpillar (模拟)

传送门题解第一天是从2pm算起,然后从第二天开始都是从10am算起,模拟整个行进过程。需注意的是,caterpillar可以滑到地底下,意味着其所在高度可以是负的。#include <bits/stdc++.h>using namespace std;int main(){ #ifdef LOCAL fstream cin("data.in"); fstream cout

2016-03-26 08:31:39 663

原创 nyoj--300 Kiki & Little Kiki 2(矩阵快速幂)

nyoj 300题解操作函数:f(i)=f(i)^f((i−1+n)%n)f(i) = f(i) \text{^} f((i - 1 + n) \% n)一共有mm次操作,而mm可以达到10810^8的数量级,所以考虑构造一个矩阵加速运算。 构造矩阵: 以n=4n = 4为例 E=∣∣∣∣∣∣1001110001100011∣∣∣∣∣∣E = \begin{vmatrix} 1 &1& 0 &

2016-03-24 20:39:36 479

原创 nyoj--299 Matrix Power Series(矩阵 + 二分)

nyoj 299题解Sk=A+A1+A2+...+AkS_k = A + A^1 + A^2 + ... + A^kif k is even : Sk=(A1+A2+…+Ak/2)+Ak/2(A1+A2+…+Ak/2) =Sk/2+Ak/2Sk/2 =Sk/2(E+Ak/2)S_k = (A^1 + A^2 + … + A^{k/2}) + A^{k/2}(A^1 + A^2 + … + A^{k

2016-03-23 11:44:52 513

原创 nyoj--63 小猴子下落

nyoj 63题解模拟最后一个的下落。#include <iostream>#include <algorithm>using namespace std;int main(){ int D, I; while(cin >> D >> I && D) { int k = 1; for(int i = 1; i <= D - 1; ++i)

2016-03-20 22:54:49 433

原创 poj--3264 Balanced Lineup(RMQ)

poj 3264题解RMQ练手。#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;const int maxn = 50000 + 10;int ax[maxn][20], in[maxn][20];int n, q;void RMQ(){

2016-03-19 22:01:03 362

原创 nyoj--71 独木舟上的旅行(贪心)

nyoj 71题解贪心策略:在不超载的情况下,尽可能让最轻的和最重的同乘一条船。#include <iostream>#include <algorithm>using namespace std;const int maxn = 300 + 10;int a[maxn];int t, n, w;int main(){ for(cin >> t; t--; ) {

2016-03-19 20:05:57 387

原创 nyoj--1058 部分和问题(dfs)

nyoj 1058题解dfs搜索。 注意剪枝。#include <iostream>#include <vector>#include <cstring>#include <algorithm>using namespace std;const int maxn = 25;int a[maxn], vis[maxn];int n, k, flag;void dfs(int po

2016-03-19 16:42:40 965

原创 nyoj--284 坦克大战(bfs+优先队列)

nyoj 284题解与一般的迷宫问题不同,这里的每一点如果可扩展,可能要走1步或者2步,如果用普通的队列,无法保证到达终点时步数最少。 因此使用优先队列,每一次走都选择步数最少的进行扩展。#include <iostream>#include <queue>#include <cstring>#include <string>#include <cstdio>#include <algo

2016-03-19 12:36:48 466

原创 nyoj--58 最少步数

题解BFS或者DFS最短路。#include <iostream>#include <cstdio>#include <queue>#include <cstring>#include <algorithm>using namespace std;typedef pair<int, int> pii;const int inf = 1 << 30;int maze[9][9] = {

2016-03-19 10:21:14 673

原创 nyoj--298 点的变换(矩阵)

nyoj 298题解参阅Matrix67大神的十个利用矩阵乘法解决的经典题目#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <algorithm>#include <cmath>using namespace std;const int maxn = 10000 + 10;c

2016-03-19 00:20:28 477

原创 zoj--1951 Goldbach's Conjecture(math)

zoj 1951题解验证一百万以内的哥德巴赫猜想。 素数打表,然后枚举。#include <iostream>#include <cstdio>#include <vector>#include <algorithm>using namespace std;const int maxn = 1000000 + 10;bool vis[maxn];vector<int> p;int

2016-03-18 23:35:02 444

原创 nyoj--301 递推求值(矩阵快速幂)

nyoj 301题解用矩阵加速运算。 ∣∣∣∣∣f(n)f(n−1)1∣∣∣∣∣=∣∣∣∣b10a00c01∣∣∣∣∣∣∣∣∣f(n−1)f(n−2)1∣∣∣∣∣=∣∣∣∣b10a00c01∣∣∣∣n−2∣∣∣∣∣f(2)f(1)1∣∣∣∣∣\begin{vmatrix} f(n) \\ f(n - 1) \\1 \end{vmatrix} = \begin{vmatrix}b & a & c \

2016-03-18 21:06:35 448

原创 poj--1789 Truck History(最小生成树Prim算法)

poj 1789题解每个code视为一个结点,每两个code都有一条边,权值是这两个code对应位置的不同字符数。这便是一个求最小生成树的权重问题。 注:这是一个完全无向图,共有n(n−1)/2n(n - 1)/2条边,如果用Kruskal算法,会MLE。#include <iostream>#include <string>#include <cstring>#include <fstre

2016-03-17 22:29:01 381

原创 nyoj--1000 又见斐波那契数列(快速幂+欧拉定理)

nyoj 1000题解F(0)=a,F(1)=bF(0) = a, F(1) = b F(n)=F(n−1)F(n−2)F(n) = F(n - 1)F(n - 2) ⇒F(n)=F(n−2)2F(n−3)\Rightarrow F(n) = F(n - 2)^2F(n-3) ⇒F(n)=F(n−3)3F(n−4)2\Rightarrow F(n) = F(n - 3)^3F(n - 4)^2

2016-03-17 20:53:06 1229

原创 PAT--1115. Counting Nodes in a BST

pat A.1115题解每个结点附加一个域表示该结点所在的层次,建树的时候同时计算。 然后遍历之。#include <iostream>#include <string>#include <algorithm>using namespace std;typedef struct node* BinTree;struct node{ int k; int l; Bin

2016-03-16 19:51:24 525

原创 蓝桥杯--算法提高 01背包

题解水水更健康~#include <iostream>#include <algorithm>using namespace std;const int maxn = 5000 + 10;int dp[maxn];int n, m;int main(){ cin >> n >> m; int w, v; for(int i = 0; i < n; ++i)

2016-03-16 17:52:34 1058

原创 PAT--1113. Integer Set Partition

PAT A.1113题解排下序就ok。#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int maxn = 100000 + 10;int n, a[maxn];int main(){ while(cin >> n)

2016-03-16 17:31:15 380

原创 PAT--1112. Stucked Keyboard

PAT A.1112题意键盘上打字的时候,有一些键可能会被卡住,这就导致某个键你只按键一次,却会连续出现k次,你所要做的就是找出这些可能被卡住的键,并还原出原始的输入序列。题解难点在于如何判断一个连续k个字符的子串其字符是否是被卡住的,因为后面完全有可能出现该字符却并不连续k次出现。 我的解决方法是multimap,每个字符作为键,键值是其连续的长度为k的子串,这样要判断一个字符是否可能是被卡住的

2016-03-16 16:54:53 1074

原创 nyoj--148 fibonacci数列(二)(矩阵快速幂)

nyoj 148 模板记录之。#include <iostream>#include <fstream>#include <cmath>#include <vector>#include <algorithm>using namespace std;typedef vector<int> vec;typedef vector<vec> mat;const int mod = 1000

2016-03-15 12:00:07 419

原创 nyoj--92 图像有用区域(bfs)

nyoj 92题解此题实际上是要遍历”0”圈以外的数,把它们置为0。 BFS遍历是一层一层的,对于每个当前正遍历的结点,如果它的邻接点(邻近的元素)为0,那就不作为扩展结点放入队列中,否则将其置为0并作为扩展节点放入队列。 这种方法需要把整个图像(矩阵)套在”1”圈里,像装裱一副字画?#include <iostream>#include <cstdio>#include <queue>#

2016-03-15 10:44:37 382

原创 codeforces--650A Watchmen(math)

CF 650A题意求 |xi−xj|+|yi−yj|=(xi−xj)2+(yi−yj)2−−−−−−−−−−−−−−−−−√|x_i - x_j| + |y_i - y_j| = \sqrt{(x_i - x_j)^2 + (y_i - y_j)^2} 的个数。题解显然,只有xi==xjx_i == x_j 或者 yi==yjy_i == y_j 的时候才相等。#include <bits/stdc

2016-03-14 19:04:15 459

原创 python笔记之字符串格式化

Python中字符串的格式化有两种方式: 1. 字符串格式化表达式,类似于C语言中的printf模型; 2. 字符串格式化方法调用,format方法。字符串格式化表达式:"" % ()格式化规则:%[(name)][flags][width][.precision]typecodename: 字典键flags: 左对齐(-),正负号(+),补零(0)的标志位width: 位宽.precis

2016-03-13 20:57:37 692

原创 蓝桥杯--算法训练 方格取数(多线程dp)

题意取过的数会变成0,因此两条路径相交的部分只能取一次。#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int maxn = 12;int dp[maxn][maxn][maxn][maxn], g[maxn][maxn];int

2016-03-13 15:22:19 964

原创 nyoj--61 传字条(一)(多线程dp)

nyoj 61题意m∗nm*n的矩形方格,从左上角到右下角找到两条互不相交的路径(首尾两端除外),使得路径上的和最大。题解多线程dp,get new skill~ 定义状态:dp(k,x1,y1,x2,y2)dp(k, x_1, y_1, x_2, y_2)表示两人在第k步时分别到(x1,y1)(x_1, y_1),(x2,y2)(x_2, y_2)时的最大和。 状态转移:dp(k,x1,y1,

2016-03-13 13:20:57 410

原创 nyoj--84 阶乘的0

nyoj 84题解算术基本定理,每个大于1大正整数可以分解成: n=pa11pa22...pakkn = p_1^{a_1}p_2^{a_2}...p_k^{a_k},这些素数中,相乘末尾有0的只有2∗52*5,而一个数的阶乘中2的次幂总是高于5的次幂的,所以只需要知道阶乘中5的次幂即可。#include <iostream>#include <vector>using namespace st

2016-03-13 10:32:04 321

原创 nyoj--24 素数距离问题

nyoj 24题解素数打表,O(nlogn)O(nlogn),然后二分查找。#include <iostream>#include <cstring>#include <vector>#include <cmath>#include <cstdio>#include <algorithm>using namespace std;const int maxn = 1000005;vect

2016-03-13 10:04:42 313

原创 nyoj--19 擅长排列的小明(dfs)

nyoj 19题解简单DFS.#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int n, m, t;int p[10], vis[10];void dfs(int pos){ if(pos == m) { for(i

2016-03-13 00:34:25 406

原创 nyoj--17 单调递增最长子序列(LIS)

nyoj 17题解O(n2)O(n^2) 和 O(nlogn)O(nlogn) 两种解法。#include <iostream>#include <string>#include <cstring>#include <algorithm>using namespace std;int main(){ int t; char dp[10005]; string src

2016-03-12 22:38:05 364

原创 hdoj--1950 Bridging signals(LIS with O(nlogn))

hdoj 1950题解O(n2)O(n^2)的LIS会TLE,见识到O(nlogn)O(nlogn)解法的LIS.#include <iostream>#include <cstdio>#include <algorithm>using namespace std;const int maxn = 40000 + 10;int p[maxn], dp[maxn];int n, t;

2016-03-12 11:40:55 413

原创 codeforces--651B Beautiful Paintings

题解桶排的思想,累加每个严格递增的序列的长度减一的值。n = int(input())a = [int(x) for x in input().split()]vis = [0] * 1005for i in range(n): vis[a[i]] += 1ans = 0while n: num = 0 for i in range(1, 1001):

2016-03-11 22:00:14 397

原创 codeforces--651A Joysticks(贪心)

题解贪心:每次都选择电量更小的那个进行充电。 注意:初始都为1的时候。a, b = [int(x) for x in input().split()]ans = 1while a > 2 or b > 2: if a > b: a, b = b, a a += 1 b -= 2 ans += 1if a == 1 and b == 1: ans = 0pri

2016-03-11 21:05:55 438

原创 nyoj--115 城市平乱(最短路径)

题解计算这n个点到Q的最短路径,取最小值。 Floyd 会TLE. 没优化的Dijkstra。#include <iostream>#include <cstdio>#include <vector>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1005;const int inf

2016-03-11 20:18:36 565

原创 蓝桥杯--历届试题 翻硬币(贪心)

题解如果源字符串与目标字符串对应位置上的字符不同,那必然要操作一次。这样一次操作可以让该位置上的字符变得相同,但有可能导致另一个被翻转的字符变得不同, 继续这样处理下去就好啦。#include <iostream>#include <string>#include <algorithm>using namespace std;int main(){ string src, dec;

2016-03-10 17:28:03 559

原创 nyoj--38 布线问题(最小生成树)

nyoj 38题解计算最小生成树的权重,然后加上花费最小的那个顶点的值。 Kruskal算法如下:#include <iostream>#include <cstdio>#include <vector>#include <cstring>#include <queue>#include <algorithm>using namespace std;const int maxn = 5

2016-03-10 14:36:40 385

原创 nyoj--20 吝啬的国度(dfs)

nyoj 20题意求一棵树每个结点的父节点,根节点为-1.题解就是一个无向图,dfs一下。#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;const int maxn = 100000 + 10;int p[ma

2016-03-09 23:12:55 437

原创 nyoj--129 树的判定(并查集)

nyoj 129题意若干条有向边(u,v)(u, v),判定能否构成一棵有向树。题解构成有向树的条件是: 1. 空树是有向树; 2. 只有一个根节点,除根节点外的每个结点只有一个父节点,也就是只有一个结点入度为0,其他结点入度为1; 3. 不能形成环。可以用并查集检查集合个数,显然一棵树应只有一个集合。 一开始没注意到空树,一直WA,WA,WA,伤得不轻。#include <iostream

2016-03-08 17:54:49 658

mybatis从入门到精通

mybatis从入门到精通 Mybatis使用之环境搭建 Mybatis使用之简单的增删改查 ...

2018-04-16

蓝桥杯2014年C语言真题

2014年的蓝桥杯C语言试题。 1.啤酒和饮料 2.切面条 3.李白打酒 4.史丰收速算 5.打印图形 6.奇怪的分式 7.六角填数 8.蚂蚁感冒 9.地宫取包 10.小朋友排队

2015-02-02

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除