continue

方程的解(拓展欧几里德)

匿名 (未验证) 提交于 2019-12-02 23:49:02
******************************************* 1 void exgcd(ll a,ll b,ll &x,ll &y) 2 { 3 if(b==0) 4 { 5 x=1;y=0;return ; 6 } 7 exgcd(b,a%b,x,y); 8 ll z=x;x=y;y=z-(a/b)*y; 9 return ; 10 } View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<string> 5 #include<algorithm> 6 #include<cmath> 7 #include<stack> 8 #include<vector> 9 #include<queue> 10 #include<bits/stdc++.h> 11 #define MAXN 401 12 #define ps push_back 13 #define ll long long 14 using namespace std; 15 ll aa,bb,cc; 16 ll T; 17 void exgcd(ll a,ll b,ll &x,ll &y) 18 { 19 if(b==0) 20 { 21 x=1;y=0;return ; 22 } 23

continue break exit(0) return 的用法和区别

匿名 (未验证) 提交于 2019-12-02 23:26:52
continue break exit(0) return 的用法和区别 break: 负责终止离它最近的while、do while、for或switch语句,并从这些语句之后的第一条语句开始继续执行。break语句只能出现在迭代语句或者switch语句内部(包括潜逃在此类循环里的语句或块的内部)。break语句的作用范围仅限于最近的循环或者switch。 continue: 终止最近的循环中的当前迭代并立即开始下一次迭代。continue语句只能出现在for、while、和do while循环内部,或者嵌套在此类循环里的语句或者块的内部。和break语句类似的是,出现在嵌套循环中的continue语句也仅作用于离它最近的循环。和break语句不同的是,只有当swith语句嵌套在迭代语句内部时,才能在switch里使用continue。 return: 终止当前函数的执行。 exit(0): exit 函数将无条件地关闭程序。因为它绕过了程序的正常逻辑流程,所以应该谨慎使用它。有时候会出现一些非常少见的情况,使得程序有必要在 main 以外的函数中终止。要实现这一点,可以使用 exit 函数。要使用 exit 函数,必须包含 < c s t d l i b > <cstdlib> < c s t d l i b > 头文件。请注意,该函数采用整数实参

Python之循环

匿名 (未验证) 提交于 2019-12-02 22:54:36
<1>while循环的格式 while 条件: 条件满足时,做的事情 1 ...(省略)... demo i = 0 while i< 5 : print( "当前是第%d次执行循环" %(i+ 1 )) print( "i=%d" %i) i+= 1 <2>for循环 像while循环一样,for可以完成循环的功能。 在Python中 for循环可以遍历任何序列的项目,如一个列表或者一个字符串等。 for循环的格式 for 临时变量 in 列表或者字符串等: 循环满足条件时执行的代码 else : 循环不满足条件时执行的代码 demo1 name = 'dongGe' for x in name: print(x) 循环关键字:break、continue break的作用:用来结束整个循环 continue的作用:用来结束本次循环开始下个循环 break/continue 只能在循环中,除此以外不能单独使用 break/continue在嵌套循环中,只对最近的一次循环起作用。 文章来源: Python之循环

Python 字符串转JSON; 先装字典在转JSON; json.dumps(d)

匿名 (未验证) 提交于 2019-12-02 22:51:30
#-*- coding:UTF-8 -*- import os; import json class MysqlUtil(): def __init__(self): pass if __name__ == '__main__': document = open("C:/Users/ald/Desktop/log/access_api/access_api.log", "r"); document_w = open("C:/Users/ald/Desktop/log/access_api/access_api.json", "w"); doc_list = document.readlines() for line in doc_list: line_arr=line.split('"') #print line_arr if(len(line_arr)<=3): continue ip_arr=line_arr[0].split(' ') if(len(ip_arr)==0): continue ip_str=ip_arr[0] url_arr=line_arr[1].split(' ') if(len(url_arr)<=2): continue url_type=url_arr[0] url_str=url_arr[1] time_arr=line_arr[2].split(

Python的for循环与while语句

匿名 (未验证) 提交于 2019-12-02 22:11:45
1.for循环语句 for 循环使用的语法: for 变量 in range(10): 循环需要执行的代码 else: 全部循环结束后要执行的代码 (1) 求1~100之和 for(i=1;i<=100;i++) sum = 0 for i in range(1,101): #sum = sum +i sum += i print(sum) (2)求1~100的奇数之和 sum = 0 for i in range(1,101,2): sum += 1 print(sum) (3) 求1~100的偶数只和 sum = 0 for i in range(2,101,2): sum +=i print(sum) (4)用户输入一个数字,求该数的阶乘:3!=3 2 1 num = int(input('Num:')) res = 1 for i in range(1,num+1): res = res * i print('%d的阶乘的结果为:%d' %(num,res)) 用户登陆程序 1.输入用户名和密码 2.判断用户名和密码是否正确('name==root','passwd='westos') 3.为了防止暴力破解,登陆次数仅有三次,如果超过三次机会,报错 for i in range(3): #0 1 2 name = input('用户名:') passwd = input(

在 php 7.3 中 switch 语句中使用 continue

匿名 (未验证) 提交于 2019-12-02 22:11:45
在 php 7.3 的 switch 中使用 continue 会出现警告。 1 2 3 while ($foo) { switch ($bar) { case "baz": continue; // In PHP: Behaves like "break;" // In C: Behaves like "continue 2;" } } 最好的方式是把 continue 改为 continue 2 https://wiki.php.net/rfc/continue_on_switch_deprecation https://github.com/aces/Loris/issues/4037 https://github.com/squizlabs/PHP_CodeSniffer/pull/2086

Java基础知识学习笔记二

匿名 (未验证) 提交于 2019-12-02 21:53:52
Java是一种强类型语言 :每个变量都必须声明其类型,可以在一行声明多个变量 局部变量 :方法或语句块内部的变量 实例变量(成员变量) :方法外部、类的内部的变量。如果不初始化,这个实例变量会自动初始化成该类型的默认初始值(数值型变量初始化为0或者0.0,字符型变量初始值为16位的0,布尔型变量默认为false) final 常量 :一般用大写表示,用下划线分割。只能被初始化一次 命名规范 :1.所有变量、方法、类名:见名知意 2.变量名、方法名:首字母小写和驼峰原则 3.常量:大写字母和下划线,例如MAX_VALUE 4.类名:首字母大写和驼峰原则 JAVA语言运算符 %取余, 小数也可以取余 ,这一点需要注意 二元运算符类型提升 :参与运算会转到最终最高类型 布尔逻辑运算符(两边必须都是逻辑值) 逻辑与:&& 逻辑或:|| 逻辑非:! 逻辑或与逻辑与采用短路的方式 ,如果第一个值确定表达式的值,后面将不会再执行下去。 位运算符(布尔类型也可以按位与或,注意只能按位与或,布尔类型运算完后还是逻辑值) &按位与 |按位或 ^按位异或(相同为0相反为1) <<左移运算符(左移相当于乘2) >>右移运算符(右移相当于除2取商) ~取反(按位取反) 拓展运算符:+=,-=,%= +(特别的)可以做为字符串相连符:加号两边只要有一个字符串,则变成字符串连接,整个为字符串 控制语句 选择

When to use the 'continue' keyword in C#

我怕爱的太早我们不能终老 提交于 2019-12-02 18:52:09
Recently, I was going through an open-source project and although I have been developing for several years in .NET, I hadn't stumbled across the continue keyword before. Question: What are some best practices or areas that would benefit from using the continue keyword? Is there a reason I might not have seen it previously? Anthony Pegram You use it to immediately exit the current loop iteration and begin the next, if applicable. foreach (var obj in list) { continue; var temp = ...; // this code will never execute } A continue is normally tied to a condition, and the condition could usually be

Is it possible to use 'yield' to generate 'Iterator' instead of a list in Scala?

放肆的年华 提交于 2019-12-02 17:41:08
Is it possible to use yield as an iterator without evaluation of every value? It is a common task when it is easy to implement complex list generation, and then you need to convert it into Iterator , because you don't need some results... Sure. Actually, there are three options for non-strictness, which I list below. For the examples, assume: val list = List.range(1, 10) def compute(n: Int) = { println("Computing "+n) n * 2 } Stream . A Stream is a lazily evaluated list. It will compute values on demand, but it will not recompute values once they have been computed. It is most useful if you'll

点分治

被刻印的时光 ゝ 提交于 2019-12-02 16:56:36
1.求<=k点对数,容斥法 /* 求树中距离不超过k的点对数 暴力枚举两点,lca求的复杂度是O(n^2logn),这样很多次询问都是冗余的 那么选择重心作为根,问题分成两部分,求经过重心的距离<=k的点对+不经过重心的距离<=k的点对 先来求第一部分,计算所有点的深度,排序,O(nlogn)可以计算出距离<=k的过重心点对 但是这样还不是正确答案,因为还要容斥掉来自同一棵子树的非法点对,那么对这部分再算一次即可 再求第二部分,这部分其实等价于原问题的子问题,所以我们再去重心的每个子树里找重心,和上面一样求 如果一个点已经被当过重心了,那么给它打个vis标记,之后不再访问 这样最多递归O(logn) 次,所以总复杂度是O(n*logn*logn) */ #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define N 10005 using namespace std; struct Edge{int to,nxt,w;}e[N<<1]; int head[N],tot,n,k,ans; void add(int u,int v,int w){ e[tot].to=v;e[tot].w=w;e[tot].nxt=head[u];head[u]=tot++; } int vis[N]