- 博客(134)
- 收藏
- 关注
原创 Python笔记 - 集合
集合创建方式: 1. 使用 {}:eg: s = {2,3,4,5,6} 2. 使用set() eg: s1 = set(range(6))集合中的元素不允许重复 定义空集合 s = set()集合中的元素是无序的 集合元素的新增操作: 调用add()方法,一次添加一个元素; 调用update()方法至少添加一个元素; 集合元素的删除操作...
2021-08-01 16:00:59
280
原创 Python笔记 - 元组
元组的创建方式:1.使用()eg:t = ('Python', 'world' , 98)2 .使用内置函数 tuple()只包含一个元组的的元素需要使用逗号和小括号 eg: t = (10, )
2021-07-31 09:25:25
168
原创 Python笔记 - 字典
字典的创建:# 使用{}创建字典scores = {'张三': 100, '李四': 98, '王五': 45}print(scores)# 使用内置函数dict()student = dict(name='jack', age=20)print(student)
2021-07-30 09:51:59
292
原创 排序模板
1.冒泡排序(O(n²))最好情况下O(n)for(int i = 0; i < n-1; i++)//升序 { for(int j = 0; j < n-1-i; j++) { if(a[j] > a[j+1]) { int temp = a[j]; a[j] = a[j+1]; a[j+1] = temp;...
2019-04-08 16:03:46
348
原创 POJ - 1321 - 棋盘问题 【DFS】
在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。Input输入含有多组测试数据。 每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n <= 8 , k <= n...
2018-08-10 15:05:48
220
原创 POJ - 3126 - Prime Path 【BFS + 素数打表】
题意:给你两个四位数的素数,让你从第一个素数变成第二个,每次操作只能改动一位数字,且需要保证改动后的数字任为为素数;输出需要操作多少次; 题解:先素数打表,BFS处理时将满足条件的数字放入队列中(未被访问过且为素数,与队列front()的元数只有一位数字不同);#include<iostream>#include<cstdio>#include<cstr...
2018-08-08 10:24:22
229
原创 POJ-3278 - Catch That Cow【BFS】
题意: John要去抓奶牛,奶牛不会移动,John移动的方式有三种:向前移动一步,耗时一分钟; 向后移动一步,耗时一分钟; 向前移动当前所处的位置的2倍,耗时一分钟;题解:1. if(N >= k),当John所处的位置大于奶牛的, John 只能向后一步一步移动,即耗时N - K ; 2. if(N < K),用BFS去解决; #include<io...
2018-08-06 11:56:36
154
转载 搜索剪枝
what's 剪枝?常用的搜索有Dfs和Bfs。Bfs的剪枝通常就是判重,因为一般Bfs寻找的是步数最少,重复的话必定不会在之前的情况前产生最优解。深搜,它的进程近似一颗树(通常叫Dfs树)。而剪枝就是一种生动的比喻:把不会产生答案的,或不必要的枝条“剪掉”。剪枝的关键就在于剪枝的判断:什么枝该剪,什么枝不该剪,在什么地方减。剪枝的原则?正确性,准确性,高效性。常用...
2018-08-06 10:59:16
554
原创 HDU - 2612 - Find a way 【BFS】
题意: 输出Y和M 到图中 ‘@’的最小步数之和题解: 用三维数组分别储存Y 和 M 到 图中的每一点的步数,输出最小的步数和;#include<iostream>#include<cstdio>#include<cstring>#include<queue>#define INF 0x7ffffffusing namespace...
2018-08-06 09:53:58
203
原创 POJ - 3984 -迷宫问题【BFS + 打印路径】
题解: 用一个结构体二维数组来存每个点的上一个点的坐标,通过递归到达起点,在回溯时打印路径#include<iostream>#include<cstdio>#include<cstring>#include<queue>using namespace std;int mp[5][5];bool vis[5][5];int di...
2018-08-04 15:14:16
260
原创 POJ - 2251 - Dungeon Master 【BFS】
题意: 从S到E需要多少分钟(只能上下左右前后移动一格,每移动一个耗费1分钟);#include<iostream>#include<cstdio>#include<cstring>#include<queue>using namespace std;const int maxn = 35;struct node{ int...
2018-08-04 14:34:14
184
原创 Codeforces - 617E - XOR and Favorite Number【莫队】
#include<bits/stdc++.h>using namespace std;const int maxn = 1<<20;struct node{ int l, r, id;}Q[maxn];int pos[maxn], a[maxn];long long ans[maxn], flag[maxn];bool cmp(node a, ...
2018-08-04 10:38:45
238
原创 POJ - 2230 - Watchcow【欧拉回路】/补
#include<iostream>#include<cstdio>#include<vector>using namespace std;const int maxn = 1e4+10;const int maxm = 4e4+10;int n, m;struct Edge{ int to,flag;}e;vector<Edg...
2018-08-01 15:44:48
167
原创 UVA - 10129 -Play on Words【欧拉路】/补
(来自:《算法竞赛入门经典》)题意:输入n(n≤100000)个单词,是否可以把所有这些单词排成一个序列,使得每个单词的第一个字母和上一个单词的最后一个字母和上一个单词的第一个字母相同(例如acm,malform,mouse)。每个单词最多包含1000个小写字母。输入中可以有重复的单词。【分析】把字母看作结点,单词看成有向边,则问题有解,当且仅当图中有欧拉路径。前面讲过,有向图存在欧拉道路...
2018-08-01 10:48:50
160
原创 HDU - 1285 -确定比赛名次【拓扑排序】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1285#include<bits/stdc++.h>using namespace std;const int maxn = 515;int mp[maxn][maxn];int _in[maxn];int ans[maxn];int N, M;void init(){...
2018-07-30 11:11:01
155
原创 LOJ - #6284. 数列分块入门 8
题目链接:https://ajax.loj.ac/problem/6284#include<bits/stdc++.h>using namespace std;const int maxn = 1e5+5;int a[maxn], pos[maxn], blo, n, tag[maxn], l, r, c;void reset(int x){ if(tag[x]...
2018-07-30 10:05:15
247
原创 LOJ - #6283. 数列分块入门 7
题目链接: https://ajax.loj.ac/problem/6283#include<bits/stdc++.h>#define ll long long#define mod 10007using namespace std;const int maxn = 1e5 + 5;int blo, opt, l, r, c, n, m;int pos[maxn],...
2018-07-26 15:52:37
226
原创 LOJ - #6282. 数列分块入门 6
题目链接:https://ajax.loj.ac/problem/6282#include<bits/stdc++.h>#define ll long longusing namespace std;const int maxn = 1e5 + 5;int blo, opt, l, r, c, n, m;int pos[maxn], a[maxn], st[maxn*2...
2018-07-26 10:36:42
255
原创 LOJ-#6281. 数列分块入门 5
题目链接:https://ajax.loj.ac/problem/6281#include<bits/stdc++.h>#define ll long longusing namespace std;const int maxn = 5e4 + 5;int blo, opt, l, r, c, a[maxn], flag[maxn], pos[maxn], n, sum[...
2018-07-26 09:10:19
218
原创 LOJ - #6280. 数列分块入门 4
题目链接:https://loj.ac/problem/6280#include<bits/stdc++.h>#define ll long longusing namespace std;const int maxn = 5e4 + 5;int blo, n, opt, l, r, c, pos[maxn];ll atag[maxn], sum[maxn], a[ma...
2018-07-25 17:41:21
248
原创 LOJ - #6279. 数列分块入门 3
题目链接:#6279. 数列分块入门 3#include<bits/stdc++.h>using namespace std;const int maxn = 1e5 + 5;int blo, n, opt, l, r, c, a[maxn], pos[maxn], atag[maxn];set<int>st[maxn];int add(int l, int...
2018-07-25 17:12:37
262
原创 LOJ - #6278. 数列分块入门 2
输出格式对于每次询问,输出一行一个数字表示答案。样例样例输入41 2 2 30 1 3 11 1 3 21 1 4 11 2 3 2样例输出302#include<bits/stdc++.h>using namespace std;const int maxn = 5e4 + 5;int blo, n, opt, l, r,...
2018-07-25 11:02:14
330
原创 LOJ - #6277数列分块入门 1
输出格式对于每次询问,输出一行一个数字表示答案。样例样例输入41 2 2 30 1 3 11 0 1 00 1 2 21 0 2 0样例输出25#include<bits/stdc++.h>using namespace std;const int maxn = 5e4 + 5;int blo, n, opt, l, r, c...
2018-07-25 10:11:31
200
原创 牛客小白月赛5 - G - 异或(xor)【找规律】
链接:https://www.nowcoder.com/acm/contest/135/G 从前,Apojacsleam家的水族箱里,养了一群热带鱼。 在这几条热带鱼里,Apojacsleam特别喜欢一条叫做TbGx(请勿人肉)的热带鱼,所以每次都让她第一个吃食物。对于每一条鱼,Apojacsleam都有一个顺序,鱼会按照这个顺序排序,越靠前的地位越高。 吃饱喝足是要睡觉的...
2018-07-24 16:39:45
460
原创 牛客小白月赛5 -I- 区间 (interval)【差分数组】
链接:https://www.nowcoder.com/acm/contest/135/I来源:牛客网Apojacsleam喜欢数组。 他现在有一个n个元素的数组a,而他要对a[L]-a[R]进行M次操作: 操作一:将a[L]-a[R]内的元素都加上P 操作二:将a[L]-a[R]内的元素都减去P 最后询问a[l]-a[r]内的元素之和?...
2018-07-24 15:52:44
164
原创 牛客小白月赛5 - j - 时间time
链接:https://www.nowcoder.com/acm/contest/135/J来源:牛客网 Apojacsleam是一个喜欢特殊时刻的人。 他定义了一个时刻,若电子表显示ab:ba(24小时制),则该时刻为“回文时刻”(可以有前导零)。例如00:00就是回文时刻。 给定一个时刻,求此时刻的上一个和下一个回文时刻。J题附加:00:00就是...
2018-07-24 09:50:27
173
原创 CodeForces - 890A - ACM ICPC【水题】
#include<iostream>#include<cstdio>using namespace std;int main(){ int a[6], ans = 0; for (int i = 0; i < 6; i++){ cin >> a[i]; ans += a[i]; } ...
2018-07-21 23:35:10
158
原创 HDU - 1061 - 快速幂
#include<bits/stdc++.h>using namespace std;const int Mod = 1e5;int pow_mod(long long a, long long n, int m){ long long ans = 1; while(n){ if(n & 1){ ans = (ans * a) %...
2018-07-21 09:13:38
265
原创 快速幂【模板】
O(logn):#include<bits/stdc++.h>using namespace std;int pow_mod(int a, int n, int m){ if(n == 0) return 1; int x = pow_mod(a, n/2, m); long long ans = (long long)x * x % m; ...
2018-07-20 16:50:39
8794
1
原创 HDU - 5832 -A water problem【大数取模】
题解:因为137*73=10001,则将值对10001取模。#include<iostream>#include<cstring>#include<cstdio>#define mod 10001using namespace std;const int maxn = 1e7 + 5;char a[maxn];int main(){ ...
2018-07-20 16:03:59
171
原创 Codeforces - 1005D - Polycarp and Div 3【同余】
题意:只包含数字的字符串,将其划分成多个部分使其能被3整除的部分最多。题解:当一个数为3的倍数,那么该数各个位之和能被3整除;eg: 数 XYZ****;1.如果 X 能被3整除 则 ans++, 取第一个数 即 X | YZ****;2.如果 X 不能被3整除 ,但 X+ Y 能被3 整除 取前两个数 则 ans ++ ,即 XY | Z****;3.如果 X 不能被3 ...
2018-07-20 10:23:11
258
原创 Codeforces - 1005C - Summarize to the Power of Two【map】
题意:给你一个序列,对于序列中的元素 i 如果存在 j 满足i + j (i ≠ j)的值为2的幂则保留,否则将其删除;输出需要删除的个数。#include<bits/stdc++.h>using namespace std;const int maxn = 122222;map<int,int>mp;int a[maxn];int main(){ ...
2018-07-20 08:43:09
196
原创 codeforces - 1005B - Delete from the Left【模拟】
题意:两个字符串,输出需要删除多少个字符使两个字符串相等,只能从当前左的字符开始删除;题解:计算两个字符串从右往左有多少个字符相等,不相等的字符为需要删除;#include <bits/stdc++.h>using namespace std;const int maxn = 222222;char a[maxn], b[maxn];int main(){ scanf...
2018-07-11 11:25:51
201
原创 Codeforces - 1005A - Tanya and Stairways【模拟】
题意:Tanya爬楼梯,每爬一层楼就会说出这一层楼梯的编号;例如她爬上两层楼,其中第一个楼包含3个楼梯3,第二个包含44个,她说出的数字为1 ,2 ,3 ,1 ,2 ,3 ,4,输出Tanya爬了几层楼,每一层楼有多少楼梯。 题解:用Vector存储每一层楼的楼梯数;#include <bits/stdc++.h>using namespace std;vector ...
2018-07-11 11:11:10
433
原创 NYOJ -1212 - 士兵杀敌(二)【线段树单点更新】
题目描述南将军手下有N个士兵,分别编号1到N,这些士兵的杀敌数都是已知的。小工是南将军手下的军师,南将军经常想知道第m号到第n号士兵的总杀敌数,请你帮助小工来回答南将军吧。南将军的某次询问之后士兵i可能又杀敌q人,之后南将军再询问的时候,需要考虑到新增的杀敌数。输入只有一组测试数据第一行是两个整数N,M,其中N表示士兵的个数(1<N<1000000),M表示指令的条数。(1<M&...
2018-06-29 11:31:47
120
原创 NYOJ - 1221 - 盗梦空间【模拟】
题目描述《盗梦空间》是一部精彩的影片,在这部电影里,Cobb等人可以进入梦境之中,梦境里的时间会比现实中的时间过得快得多,这里假设现实中的3分钟,在梦里就是1小时。然而,Cobb他们利用强效镇静剂,可以从第一层梦境进入第二层梦境,甚至进入三层,四层梦境,每层梦境都会产生同样的时间加速效果。那么现在给你Cobb在各层梦境中经历的时间,你能算出现实世界过了多长时间吗?比如,Cobb先在第一层梦境待了1...
2018-06-29 10:37:54
218
原创 HDU - 1087-Super Jumping! Jumping! Jumping! 【LIS变形】
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now. The game can b...
2018-06-11 20:30:25
145
原创 HDU - 1069-Monkey and Banana【LIS】
A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monk...
2018-06-11 20:18:15
144
原创 HDU - 1114 - Piggy-Bank【完全背包】
在 ACM 能够开展之前,必须准备预算,并获得必要的财力支持。该活动的主要收入来自于 Irreversibly Bound Money (IBM)。思路很简单。任何时候,某位 ACM 会员有少量的钱时,他将所有的硬币投入到小猪储钱罐中。这个过程不可逆,因为只有把小猪储钱罐打碎才能取出硬币。在足够长的时间之后,小猪储钱罐中有了足够的现金,用于支付 ACM 活动所需的花费。但是,小猪储钱罐存在一个...
2018-06-11 16:34:52
147
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人