- 博客(116)
- 收藏
- 关注

原创 重要的逆向思维
第一题liouzhou_101住在柳侯公园附近,闲暇时刻都会去公园散散步。很那啥的就是,柳侯公园的道路太凌乱了,假若不认识路就会走着走着绕回原来的那条路。liouzhou_101就开始自己YY,假若给他当上那啥管理者,就会想尽量减少道路回圈的个数,但是大范围的改变道路终归不是什么良策。经过调查,发现公园有N个景点,为了显示景点之间的优越性,我们按照1,2,…,N来把这N个景点编号,
2013-11-03 01:33:39
1183

原创 HNOI-排队
ans=n!*A(n+1,2)*A(n+3,m)+n!*C(n+1,1)*2*m*A(n+2,m-1);#include#include#include#include#includeusing namespace std;int n,m;struct bign{ long long a[10010]; int len; };bi
2013-10-29 19:51:32
967

原创 关于dijkstra的贪心思想的正确性的证明
dijkstra看似简单,其实却很有意思。 现在发现对于一个问题,如果决心搞懂,总是会有一个难到易(初步搞懂问题),易到难(开始深入),难到易(已经深入理解)。 我在看dijkstra的时候一开始有点迷茫,因为觉得贪心怎么会在全局上取得最优呢,结果证明是对的,我的解释就是dijkstra算法中已经把每个点都遍历过,能取最短的都已经取了,于是在想通了后觉得简单,但
2013-05-16 19:39:32
4224
原创 Python_序列
1)列表# 1) 基础操作>>> a = [] # 创建一个列表# append(x) 将x添加到列表末尾,相当于a[len(a):] = [x]>>> a.append(1)>>> a[1]>>> a.append(2) >>> a[1, 2]# extend(iterable) 将可迭代对象添加到列表末尾,相当于a[len(a):] = [iterable]>>&g.
2021-09-17 19:09:33
233
原创 Python_魔法方法
1)构造和析构 (1) 为什么使用__init__()'''需要初始化对象时就需要重写__init__()方法'''>>> class Rectangle: '''定义一个矩形类, 需要长和宽两个参数, 拥有计算周长和面积两个方法。 所以我们需要对象在初始化的时候拥有长宽两个参数, 因此需要用__init__()方法''' def __init__(self, x, y): self.x = x self.y = y ...
2021-09-16 23:24:31
342
原创 Python_类和对象
1.对象 = 属性(变量) + 方法(函数)属性:对象的特征;方法:对象的行为以lzm为例写成代码class Lzm: # Python中的类名约定以大写字母开头 # 特征的描述称为属性,在代码层面来看其实就是变量 body = 'strong' face = 'handsome' arms = 2 legs = 2 mouth = 'big嘴' ismale = True # 方法实际就是函数,通过调用这些函数来完成某
2021-08-27 17:47:36
244
原创 Python_循环
for循环和while循环后都可以接else语句for i in range(7): print(i, end = ' ')else: print('\nOK')>>>0 1 2 3 4 5 6 OK'''在for循环完整执行后会执行else'''for i in range(7): print(i, end = ' ') if i == 6: breakelse: print('\nOK')>>>0 1
2021-08-27 16:08:18
116
原创 Python_异常处理
1.常见异常'''AssertionError:断言语句失败。当assert这个关键字后面的条件为False时,程序将停止并抛出AssertionError异常。assert语句一般是在测试程序的时候用于在代码中置入检查点'''>>> a = ['lzm']>>> assert len(a) > 0>>> a.pop()'lzm'>>> assert len(a) > 0Traceback (most re
2021-08-26 23:41:55
6406
原创 Python_永久储存_pickle
pickle模块可以非常容易地将列表、字典这类复杂数据类型储存为文件(用普通的文件操作也许可以转换成字符串再写入文本保存,但反过程会异常麻烦),它几乎可以把所有Python的对象都转化为二进制的形式存放,该过程称为pickling,二进制形式转换回对象的过程称为unpickling。'''pickling'''>>> import pickle>>> a = [123, 3.14, 'lzm', ['another list']]>>> pi
2021-08-26 17:57:40
209
原创 Python_永久储存_文件系统
1. OS模块>>> import os'''获得应用程序当前的工作目录,使用getcwd()函数获得'''>>> os.getcwd()'C:\\Users\\威震东南亚\\AppData\\Local\\Programs\\Python\\Python39''''用chdir(path)函数改变当前工作目录'''>>> os.chdir('C:\\Users\\威震东南亚\\Desktop\\')>>> os.
2021-08-25 23:08:42
173
原创 Python_永久储存_文件
打开文件# 在python中使用open函数来打开文件并返回文件对象open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)# 第二个参数指定文件打开模式''' 'r':以只读方式打开文件(default) 'w':以写入的方式打开文件,会覆盖已存在的文件 'x':如果文件已存在,使用此模式打开将引发异常.
2021-08-24 23:55:03
163
原创 Python_集合
>>> s = {}>>> type(s)<class 'dict'>>>> s1 = {1,2,3,4,5}>>> type(s1)<class 'set'>#唯一性>>> s2 = {1,1,2,2,3,3}>>> s2{1, 2, 3}集合内的元素是无序的,无法索引# 创建集合>>> s1 = {1,2,3,4,5}.
2021-08-21 16:28:06
109
原创 Python_收集参数
当不清楚有多少参数传入函数时可以使用收集参数,例如print函数就是使用收集参数*:打包为元组>>> def f(*a): print('有%d个参数' % len(a)) print('第二个参数是:',a[1]) >>> f(1,2,3,4,5)有5个参数第二个参数是: 2>>> def f(*a): print(type(a)) >>> f(1,1,1,1,1)<class 'tuple'&
2021-08-21 15:23:45
330
原创 Python_zip
>>> a = [1, 2, 3]>>> b = [4, 5, 6]>>> c = [4, 5, 6, 7, 8]>>> lzm = zip(a, b) #返回一个列表,内容是元组lzm = [(1, 4), (2, 5), (3, 6)]>>> lzm = zip(a, c)lzm = [(1, 4), (2, 5), (3, 6)] #长度以最短的为准>>> unlzm = z.
2021-08-19 11:02:18
123
原创 Python_字典
字典就是映射,由key(键)到value(值)的映射,通俗点就是列表的index换成了key。字典用大括号{ }定义,由key和value共同构成。value可以取不可变的任何数据类型。#字典的创建和访问>> dict1 = {'lzm':'handsome', '吕zm':'帅', '吕治珉':'英俊'}>>> dict1{'lzm': 'handsome', '吕zm': '帅', '吕治珉': '英俊'}>>> dict1['lzm
2021-08-15 11:45:56
374
原创 快速幂计算
// by BNU_LZM#include#includeusing namespace std;const int maxn = 1010;int ans[maxn], n;bool dfs(int d, int maxd){ if(ans[d] == n) return true; if(d == maxd) return false; int m = 0; for
2017-03-31 21:08:28
396
原创 广东工业大学新生赛决赛B题
Problem B: 占点游戏Description众所周知的是,TMK特别容易迟到,终于在TMK某次又迟到了之后,Maple怒了,Maple大喊一声:“我要跟你决一死战!”然后Maple就跟TMK玩起了一个关于占点的游戏。Maple在一个无限展开的只有整数点的二维平面上找到两个点,由TMK和Maple分别操控这两个点,两
2017-03-30 15:08:51
501
原创 广东工业大学新生赛决赛F题
// by BNU_LZM#include#include#include#includeusing namespace std;const int maxn = 100000+5;struct Edge{ int u, v, d; Edge(int u, int v, int d) : u(u), v(v), d(d) {}};vector edges;vecto
2017-03-30 12:56:18
431
原创 广东工业大学新生赛决赛E题
Problem E: 倒水(Water)Description一天,CC买了N个容量可以认为是无限大的瓶子,开始时每个瓶子里有1升水。接着~~CC发现瓶子实在太多了,于是他决定保留不超过K个瓶子。每次他选择两个当前含水量相同的瓶子,把一个瓶子的水全部倒进另一个里,然后把空瓶丢弃。(不能丢弃有水的瓶子)显然在某些情况下CC无法达到目标,比如N=3,K=1。此时
2017-03-27 08:57:10
418
原创 广东工业大学新生赛决赛H题
Problem H: tmk买礼物Description今天是校赛的日子,为了庆祝这么喜庆的日子,TMK打算买些礼物给女票LSH庆祝一下。TMK进入了雪梨超市,然后刚踏入的一瞬间,店主就对TMK说:“恭喜你成为了本店第2147483647位顾客,本店在搞一个活动,对本店第2147483647位顾客进行赠送活动。你先看看你有多少钱?”TMK一摸口袋,发
2017-03-26 21:53:11
509
原创 spfa
#include#include#include#include#include#include#includeusing namespace std;void init(){ freopen("practicein.txt","r",stdin); freopen("practiceout.txt","w",stdout);}bool spfa(int s){
2017-03-25 08:24:31
484
原创 Dijkstra
#include#include#include#include#include#include#includeusing namespace std;const int INF = 1000000000;const int maxn = 100010; struct Edge{ int from, to, dist; Edge(int u, int v, int d
2017-03-25 08:23:29
390
原创 Kruskal
#include#include#include#include#include#include#includeusing namespace std;void init(){ freopen("practicein.txt","r",stdin); freopen("practiceout.txt","w",stdout);}int cmp(const int i,
2017-03-25 08:22:07
343
原创 旋转游戏
// by BNU_LZM#include#include#includeusing namespace std;int line[8][8] = { {0, 2, 6, 11, 15, 20, 22}; {1, 3, 8, 12, 17, 21, 23}; {10, 9, 8, 7, 6, 5, 4}; {19, 18, 17, 16, 15, 14, 13};};in
2017-03-23 21:19:33
405
原创 编辑书稿
// by BNU_LZM#include#include#includeusing namespace std;const int maxn = 10;int n, a[maxn];bool check(){ for(int i = 0; i < n-1; i++) if(a[i] > a[i+1]) return false; return true;}in
2017-03-22 20:09:57
528
原创 宝箱
// by BNU_LZM#include#includeusing namespace std;int main(){ int n, s1, s2, v1, v2; scanf("%d%d%d%d%d", &n, &s1, &v1, &s2, &v2); long long ans = 0; if(s1 > s2) { swap(s1, s2); swap(v1, v2);
2017-03-21 22:27:08
541
原创 危险的组合
// by BNU_LZM#include#includeint a[40];int main(){ freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); memset(a, 0, sizeof(a)); a[0] = a[1] = a[2] = 0; a[3] = 1; for(int i = 4
2017-03-21 20:13:00
909
原创 万圣节后的早晨
// by BNU_LZM#include#include#include#include#includeusing namespace std;char map[20][20];int s[4], t[4], d[300][300][300];int dx[] = {0, 0, 0, 1, -1};int dy[] = {0, 1, -1, 0, 0};vector
2017-03-20 22:30:28
455
原创 天平难题
#include#include#include#includeusing namespace std;const int maxn = 7;struct Tree{ double l, r; Tree() : l(0), r(0) {}};bool vis[1<<maxn];double r, w[maxn], sum[1<<maxn];vector tree[1
2017-03-18 14:59:34
567
1
原创 带宽
// by BNU_LZM#include#include#include#include#includeusing namespace std;const int maxn = 10;vector u, v;int id[256], letter[100];int main(){ char s[100]; scanf("%s", s); int n = 0;
2017-03-18 14:58:26
457
原创 环形跑道
// by BNU_LZM#includeconst int maxn = 100000+10;int n, p[maxn], a[maxn];int main(){ freopen("in.txt", "r", stdin); int T; scanf("%d", &T); while(T--) { scanf("%d", &n); for(int i = 1;
2017-03-17 14:17:38
574
原创 和为0的四个值
// by BNU_LZM#include#includeusing namespace std;const int maxn = 4010;int a[maxn], b[maxn], c[maxn], d[maxn], w[maxn*maxn];int erfenl(int x, int y, int v){ int m; while(x < y) { m = x+(
2017-03-14 22:03:47
438
原创 联合国大楼
// by BNU_LZM #includeint map[60][60];int main(){ freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); int n; scanf("%d", &n); int cnt = 0; for(int i = 1; i <= n; i++) { for(
2017-03-14 21:24:08
492
原创 埃及分数问题
// by BNU_LZM#include#include#include#includeusing namespace std;int ans[1010], v[1010], maxd;int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b);}int get_from(int a, int b){ int i;
2017-03-14 18:06:57
332
原创 单调队列
// by BNU_LZM#include#include#include#include#include#include#includeusing namespace std;const int maxn = 1010;struct node{ int p, v;}q[maxn];int n, k, f, r, a[maxn];void init(){
2017-03-13 20:53:45
219
原创 困难的串
// by BNU_LZM#include#include#include#includeusing namespace std;const int maxn = 110;int a[maxn], cnt = 0, l, k;int solve(int cur){ if(cnt == k) { for(int i = 0; i < cur; i++) printf("
2017-03-13 20:50:31
464
原创 倒水问题
// by BNU_LZM#include#include#include#include#includeusing namespace std;struct node{ int v[3], d; bool operator < (const node &rhs) const { return d > rhs.d; }};int t, cap[3], ans[21
2017-03-13 20:49:24
541
原创 素数环
//by BNU_LZM#include#include#include#include#includeusing namespace std;const int maxn = 110;int n, a[maxn], isp[1010];void solve(int *A, int cur){ if(cur == n && isp[A[1]+A[n]]) { fo
2017-03-11 19:19:38
286
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人