n2

Python学习之路 第三篇 Python基础(一)

时光毁灭记忆、已成空白 提交于 2019-11-28 20:05:24
1.IDLE的使用:IDLE是Python编程的编辑器 shell命令只能一次一次的执行程序,摁CTRL+N进入可多行编辑界面。 注释和注释法:注释能让写的程序失效。注释法包括“#”注释法【单行注释】,三引号注释法【多行注释】(要在英文书写模式中进行三引号注释中文状态下可能会无效)。 # import re # string="peceython" # pat="p.*y" # rst=re.search(pat,string,re.I) # print(rst) ''' import re string="peceython" pat="p.*y" rst=re.search(pat,string,re.I) print(rst) '''     在PyCharm中还能用CTRL+?注释选中的所有代码。     字符串: 用引号引起来的字符叫做字符串。   #字符串(引号): name = " linux " name = ' alex ' name = """ zlex """ name = ''' dgugu ''' #加法: >>> n1="alex" >>> n2="liunx" >>> n3=n1+n2 >>> print(n3) alexliunx #乘法 >>> n1="fgywfgw" >>> n2=n1*15 >>> print(n2)

排序算法

北战南征 提交于 2019-11-28 16:15:23
排序算法 排序法 最差时间分析 平均时间复杂度 稳定度 空间复杂度 冒泡排序 O(n2) O(n2) 稳定 O(1) 快速排序 O(n2) O(n*log2n) 不稳定 O(log2n)~O(n) 选择排序 O(n2) O(n2) 不稳定 O(1) 二叉树排序 O(n2) O(n*log2n) 不稳定 O(n) 插入排序 O(n2) O(n2) 稳定 O(1) 堆排序 O(n*log2n) O(n*log2n) 不稳定 O(1) 希尔排序 O O 不稳定 O(1) 堆排序 O(nlogn) O(nlogn) 不稳定 O(1) 3.排序算法的思想: (1)冒泡排序: 是相邻元素之间的比较和交换,两重循环O(n2);所以,如果两个相邻元素相等,是不会交换的。所以它是一种稳定的排序方法 (2)选择排序: 每个元素都与第一个元素相比,产生交换,两重循环O(n2);举个栗子,5 8 5 2 9,第一遍之后,2会与5交换,那么原序列中两个5的顺序就被破坏了。所以不是稳定的排序算法 (3)插入排序: 插入排序是在一个已经有序的小序列的基础上,一次插入一个元素。刚开始这个小序列只包含第一个元素,事件复杂度O(n2)。比较是从这个小序列的末尾开始的。想要插入的元素和小序列的最大者开始比起,如果比它大则直接插在其后面,否则一直往前找它该插入的位置。如果遇见了一个和插入元素相等的

UVA-10313

倾然丶 夕夏残阳落幕 提交于 2019-11-28 14:00:31
题意:从1-N种硬币,每个硬币的面值是1-N,数量无限,问,给你面值K,使用总数为T枚的硬币,总共有多少种方案组合出K。 如果输入只有一个数K,表示使用0-K枚硬币组合出K 有俩个数K,N1,表示使用0-N1枚硬币,组合出K 如果有三个数K,N1,N2,表示使用N1-N2枚硬币,组合出K。 Sample Input 6 6 3 6 2 5 6 1 6 Sample Output 11 7 9 11 解题思路: DP,dp[j][k] = dp[j][k]+dp[j-i][k-1] dp[j][k] 的含义是 使用k枚硬币组合出j的方案数。 方程的含义是使用 1 枚面值为i的硬币 + 先前的总数。 注意生成dp数组的顺序,按照不重复枚举的顺序生成。 首先是全部使用1。然后是开始使用2,然后开始加入3,一直加入到N 这样就不会重复计算一样的方案数。 #include <string> #include<iostream> #include <sstream> #include<map> #include<memory.h> #include<vector> #include<algorithm> #include<queue> #include<vector> #include<stack> #include<math.h> #include<iomanip> #include

Day03

无人久伴 提交于 2019-11-28 08:19:43
变量的组成 变量名:用来引用变量值, 赋值符号:赋值 变量值:存放数据 变量名的命名规范 具有一定的意义 只能有字母,下划线,数字组成,不能以数字开头 关键字不能作为变量名使用 注释的作用 使注释的代码不进行翻译 用来解释说明代码的信息与作用 turtle画图 import turtle turtle.setup() turtle.speed(8) turtle.pensize(1) n1 = 2 n2 = 2 turtle.seth(90) for x in range(100): n3 = n1 + n2 turtle.circle(n3, 90) n1 = n2 n2 = n3 turtle.done() 来源: https://www.cnblogs.com/2222bai/p/11401926.html

1010 Radix (25 point(s)) - C语言 PAT 甲级

青春壹個敷衍的年華 提交于 2019-11-28 03:45:16
1010 Radix (25 point(s)) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is yes, if 6 is a decimal number and 110 is a binary number. Now for any pair of positive integers N​1​​ and N​2​​, your task is to find the radix of one number while that of the other is given. Input Specification: Each input file contains one test case. Each case occupies a line which contains 4 positive integers: N1 N2 tag radix Here N1 and N2 each has no more than 10 digits. A digit is less than its radix and is chosen from the set { 0-9, a-z } where 0-9

Recurrence Algorithm Big-Oh Solution

痞子三分冷 提交于 2019-11-27 19:54:20
Recurrence Algorithm Big-Oh Solution T(n) = T(n/2) + O(1) Binary SearchO(log n) T(n) = T(n-1) + O(1) Sequential SearchO(n) T(n) = 2 T(n/2) + O(1) Tree TraversalO(n) T(n) = T(n-1) + O(n) Selection Sort (other n2 sorts)O(n2) T(n) = 2 T(n/2) + O(n) Mergesort (average case Quicksort)O(n log n) T(n) = T(n - 1) + T(n - 2) + ..... + T(1) or T(n) = a + 2 * T(n - 1) Exponential T(n) = n * T(n - 1) + O(1) Factorial 来源: https://www.cnblogs.com/beiyeqingteng/p/11374862.html

WPF后台代码实现TextBlock滚动条

泄露秘密 提交于 2019-11-27 12:48:58
方法一: 常规的WPF操作: <ScrollViewer Width="300" Height="150" BorderBrush="Brown" BorderThickness="2" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"> <TextBlock x:Name="_txtb" Background="HotPink" TextWrapping="Wrap" Foreground="Wheat"/> </ScrollViewer> 后台代码: _txtb.Text = "1\r\n7\r\n6\r\n5dsaadsfjhduhtndsadjdhsajhscadsadsadas哈哈哈你\r\n4\r\n3\r\n2\r\n1\r\n0\r\n1\r\n2"; 方法二: 后台直接写: public MainWindow()     { InitializeComponent(); var outer = new ScrollViewer(); outer.Background = Brushes.Gray; outer.Width = 300; outer.Height = 100; var inner = new TextBlock(); inner.Background =

C#中ref与out使用小结

拜拜、爱过 提交于 2019-11-27 08:15:22
使用ref前需要将变量初始化,而使用out前初始化与否都可以,ref传递的是参数的地址,out则是参数的返回值,ref传递的参数在函数退出时,赋值与否,编译器都不会报错;而out传递的参数则需要在退出函数时完成赋值操作。 示例如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MyTest { class Program { static void Method1(out int nNum) { nNum = 10; } static void Method2(ref int nNum) { nNum = 20; } static void Main(string[] args) { int n1; int n2 = 1; Console.WriteLine("n2 = {0}", n2); Method1(out n1); Method2(ref n2); Console.WriteLine("n1 = {0}", n1); Console.WriteLine("n2 = {0}", n2); Console.ReadKey(); } } } 来源: https://www

有关单向链表的题目

老子叫甜甜 提交于 2019-11-27 01:18:44
1、编码的关键是思路,思路不对,不可能编出正确的代码。考虑下面两个关于单向链表的题目: 2、单向链表,如何判断是否构成环形?   a、思路一:常规做法,建个集合,遍历单向链表,集合没有包含元素,添加进去集合,集合包含元素直接返回true,跳出遍历,返回false。   b、思路二:使用快慢指针,建立两个节点,n1从head开始,n2从head->next开始,while(n1 && n2),n1每次走一步,n2每次走两步。如果n2先走到null,说明没有环。如果n1==n2,说明有环,n2又从后面追上来。 3、对于单向链表,查找倒数第K个节点。   a、思路一:先计算节点个数,倒数第K个,就是正数Count-K-1   b、建立两个节点,n1,n2,n1先移动K个单位,然后n1,n2同时向后移动,n1移动到null,n2就是倒数第K个。 转载于:https://www.cnblogs.com/nzbbody/p/3558336.html 来源: https://blog.csdn.net/weixin_30196887/article/details/99234667

1010 Radix(25 分)

风格不统一 提交于 2019-11-26 19:36:20
1010 Radix(25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is yes , if 6 is a decimal number and 110 is a binary number. Now for any pair of positive integers N ​ 1 ​​ and N ​ 2 ​​, your task is to find the radix of one number while that of the other is given. Input Specification: Each input file contains one test case. Each case occupies a line which contains 4 positive integers: N1 N2 tag radix Here N1 and N2 each has no more than 10 digits. A digit is less than its radix and is chosen from the set { 0-9, a - z } where 0-9