正则表达替换img里的src为v-lazy

图片说明
类似这样的img 将src替换为v-lazy

3个回答

str.replace(/\s+src=/g," v-lazy")

qq_39546266
qq_39546266 正则没问题,但是图片懒加载是不可以的,谢了
接近 2 年之前 回复

你vue模板src直接改为v-lazy不就行了?。。何必多次一举

showbo
支付宝加好友偷能量挖 回复qq_39546266: 你换掉src了得用第三方插件来加载图片才行了,要不img肯定没办法加载了
接近 2 年之前 回复
qq_39546266
qq_39546266 回复出售折扣C币Q155132206: 试了,发现没有用并不会显示loading图片而是一片空白
接近 2 年之前 回复
showbo
支付宝加好友偷能量挖 回复qq_39546266: 那不是直接replace就行了? s=s.replace(/ src=/gi,' v-lazy=')
接近 2 年之前 回复
qq_39546266
qq_39546266 回复出售折扣C币Q155132206: 对啊 我现在已经获取到数据了 肯定需要替换,数据打印出来的是一个完整的html
接近 2 年之前 回复
showbo
支付宝加好友偷能量挖 回复qq_39546266: 后台你怎么获取的,用resource那不是得到结果后替换下
接近 2 年之前 回复
qq_39546266
qq_39546266 不行啊 数据都是后台返回的 用爬虫爬出来的数据返给我的 我没办法更改
接近 2 年之前 回复

直接replace 可以了

qq_39546266
qq_39546266 嗯 试了 但是不会显示loading的那个图片而是一个空白
接近 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
用正则表达式获取src里面的内容
现在有一段img标签我可以获取 但是img标签里面有一个data-src和src 我用正则去匹配src 但是获取到的是data-src里面的内容 如何过滤掉获取第二次出现的src内容 ``` <img class="loadingclass" id="loading_jd4ln1ka" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/FJYxahcppx2C9jyw4hJQKH9R9Ws8LdPicmrAvfw7kS1Tau6PuLP7eOBjqybtiaT9icJo9OupL9ibMdAIFBnR2wtvSQ/640?wx_fmt=jpeg" src="https://mmbiz.qpic.cn/mmbiz_jpg/FJYxahcppx2C9jyw4hJQKH9R9Ws8LdPicmrAvfw7kS1Tau6PuLP7eOBjqybtiaT9icJo9OupL9ibMdAIFBnR2wtvSQ/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1&retryload=1" dataLabel="1,2,3" title="正在上传..."/> ``` ``` String group = matcher.group(); Pattern srcText = Pattern.compile("(src|SRC)=(\"|\')(.*?)(\"|\')");//匹配图片的地址 Pattern srcText2 = Pattern.compile("(data-src|DATA-SRC)=(\"|\')(.*?)(\"|\')");//匹配图片的地址 Matcher matcher2 = srcText2.matcher(group); Matcher matcher3 = srcText.matcher(group); ```
Lazy Evaluation 怎么实现
Problem Description Most of the programming languages used in practice perform strictevaluation. When a function is called, the expressions passed in the function arguments (for instance a + b in f (a + b, 3)) are evaluated first,and the resulting values are passed to the function. However, this is not the only way how expressions can be evaluated, and in fact, even such a mainstream language as C++ is sometimes performing lazy evaluation: the operators && and jj evaluate only those arguments that are needed to determine the value of the expression. Pal Christian is now working on a comparative study of the performance of the lazy and strict evaluation. Pal wants to evaluate in both ways a set of expressions that follow this simplied syntax: --an expression is either a constant, a name, or a function call --a constant is a signed 32-bit integer; for example, 3, 0, -2, 123 are constants; --a name is a name of a built-in or user-dened function, for example, f , or add are names; names are words containing up to 32 lowercase letters from the English alphabet; --function call has the form: ( f unction arg1 . . . argN ), where f unction is an expression that evaluates to some function of N arguments, and arg1 . . . argN are expressions that evaluate to arguments passed to the function. For example, ( f 3 5 ) , or ( add 2 ( add 1 2 )) are valid function calls. Expressions are evaluated according to the following simple rules: --constants evaluate to themselves --names evaluate to the functions they denote --function calls: in lazy evaluation: the first expression is evaluated first to obtain a function, whose function body, with formal parameters substituted for the expressions provided as the arguments, is evaluated; however, whenever some argument gets evaluated while evaluating the function body, the resulting value will replace all occurences of the same parameter in that function body. In other words, the expression passed in the argument is never evaluated more than once. in strict evaluation: all expressions are evaluated first: the first expression should evaluate to a function, the remaining to values that are used as function arguments; the result is the result of evaluating the corresponding function body, where all occurences of formal parameters are replaced by the values obtained by evaluating the arguments. The following built-in functions are available: add x y - sum of the constants x and y, sub x y - returns the value x-y, mult x y - product of x and y, div x y - integer division, and rem x y - remainder (same semantics as '/' and '%' in C, C++ or Java), true x y - always returns x, f alse x y - always returns y , eq x y - returns true if x and y is the same constant, otherwise returns f alse, gt x y - returns true if x is greater than y, otherwise returns f alse. User-defined functions are defined using the following syntax: f unction name arg1 . . . argN = body, where arg1 . . . argN are distinct words (up to 32 English lowercase letters), denoting the formal parameters of the function, and the body is an expression. The formal parameters can occur in the body of the function in place of constants or names. The function name and the formal parameters are separated by a single space. There is one space on both sides of the "=". Functions with zero (no) rguments are legal. Note that the formal parameters can overshadow the function names (i.e. op in definition of not in sample input overshadows the function name op), but each function must have a unique name. Input The first part of the input contains (less than 1000) lines with one function denition each, followed by a single empty line. Forward references (that is, referring to functions dened later in the input) and recursion are legal. The second part of the input contains less than 1000 test expressions. Each test expression is an expresion occupying a single line. Function names and the arguments are always separated by a single space, but there are no extra spaces around parentheses (see sample input). There is an empty line after the last expression. Expressions are to be evaluated by both the lazy and the strict evaluation. You can assume that all function definitions and expressions are syntactically correct, and that the arithmetic built-in functions (add, sub, mult, div, rem, eq, gt) will always be called with integers only, and no division by 0 occurs. Overows outside the 32-bit integer range are legal and do not require any special treatment (just use the value produced by C, C++, or Java operators +, -, *, /, or %). In strict evaluation, built-in functions evaluate all their arguments too. In lazy evaluation, arithmetic built-in functions always evaluate all their arguments. All lines on the input contain no more than 255 characters including spaces. Output The program should produce a table in exactly the following format: operator lazy_evaluation strict_evaluation add addlazy addstrict sub sublazy substrict mult multlazy multstrict div divlazy divstrict rem remlazy remstrict where each is an integer - how many times op has been executed in lazy evaluation of all expressions, and is the number of evaluations of in strict evaluation. Spaces can occur arbitrarily. If the evaluation of a test expression does not terminate after a total of 2345 function evaluations , you can assume that it is in an innite loop, the program should skip that expression, and do not count it into the totals (omit counting operations both in lazy and strict evaluation of this expression). Sample Input if cond truepart elsepart = (cond truepart elsepart) fact x = (facta x 1) facta x a = (if (eq x 0) a (facta (sub x 1) (mult a x))) and x y = (x y false) ident x = x two = 2 op op x = ((if (eq op 1) add sub) op x) not op = (op false true) sum n = (suma n 0) suma n a = (((gt n 1) suma false) (sub n 1) (add a n)) (true (add 1 2) (mult 1 2)) 5 true (and (gt (op (sub 2 1) 1) 5) (eq (two) (op 1 1))) (false (sub 1 2) (sum 4)) ((eq (true 1 2) (false 2 1)) (add 1 2) (sub 1 2)) (fact 3) Sample Output operator lazy_evaluation strict_evaluation add 7 8 sub 4 7 mult 0 1 div 0 0 rem 0 0
css 布局如何去掉这种空白
![图片说明](https://img-ask.csdn.net/upload/201911/01/1572590851_29508.png) ![图片说明](https://img-ask.csdn.net/upload/201911/01/1572590885_712519.png) <div class="w-container"> <div id="main" class="w-waterfall"> <div tapmode @click="fnDetail(item)" class = "w-box" v-for="(item,index) in list" :key="index"> <div class = "w-pic"><div class="w-pics" :style="1 == item.type && index%2 == 0 ? 'max-height:9rem': 'max-height:12rem'"><div class="imgBoxDiv"> <img v-lazy="item.attachment[0].full_url" /> </div> </div> </div> </div> </div> </div> .w-container { width: 100%; margin: 0 auto; } .w-waterfall { -moz-column-count: 2; -webkit-column-count: 2; column-count: 2; -moz-column-gap: 0.25rem; -webkit-column-gap: 0.25rem; column-gap: 0.25rem; width: 98%; margin: auto; } .w-box { margin: 0 0 0.2rem 0; break-inside: avoid; border-radius: 0.2rem; background-color: #fff; text-shadow: 0px 0px 10px #9d9d9d; overflow: hidden; box-sizing: border-box; } .w-pics1{max-height: 12rem;overflow: hidden;border-radius: 0.2rem 0.2rem 0 0;} .imgBoxDiv1 img{width: 100%; margin-top: -60%; border: none; } .imgBoxDiv1 { height: 0; width: 100%; padding: 60% 0; }
Alice and Bob's Trip
Problem Description Alice and Bob are going on a trip. Alice is a lazy girl who wants to minimize the total travelling distance, while Bob as an active boy wants to maximize it. At the same time, they cannot let the value to be less than a given integer L since that will make them miss too much pleasure, and they cannot let the value to be greater than a given integer R since they don't want to get too exhausted. The city they are visiting has n spots and the spots are connected by directed edges. The spots are connected in such a way that they form a tree and the root will always be at spot 0. They take turns to select which edge to go. Both of them choose optimally. Bob will go first. Input There are multiple test cases. For every test case, the first line has three integers, n, L and R (1<=n<=500000, 0<=L, R<=1000000000). The next n-1 lines each has three integers a, b and c, indicating that there is an edge going from spot a to spot b with length c (1<=c<=1000). The spots are labeled from 0 to n-1. There is a blank line after each test case. Proceed to the end of file. Output If the total distance is not within the range [L, R], print "Oh, my god!" on a single line. Otherwise, print the most value Bob can get. Sample Input 3 2 4 0 1 1 0 2 5 7 2 8 0 1 1 0 2 1 1 3 1 1 4 10 2 5 1 2 6 5 7 4 8 0 1 1 0 2 1 1 3 1 1 4 2 2 5 1 2 6 5 4 2 6 0 1 1 1 2 1 1 3 5 Sample Output Oh, my god! 2 6 2
lazy gege 具体的思路
Problem Description Gege hasn't tidied his desk for long,now his desk is full of things. This morning Gege bought a notebook,while to find somewhise to put it troubles him. He wants to tidy a small area of the desk, leaving an empty area, and put the notebook there, the notebook shouldn't fall off the desk when putting there. The desk is a square and the notebook is a rectangle, area of the desk may be smaller than the notebook. here're two possible conditions: Can you tell Gege the smallest area he must tidy to put his notebook? Input T(T<=100) in the first line is the case number. The next T lines each has 3 real numbers, L,A,B(0< L,A,B <= 1000). L is the side length of the square desk. A,B is length and width of the rectangle notebook. Output For each case, output a real number with 4 decimal(printf("%.4lf",ans) is OK), indicating the smallest area Gege should tidy. Sample Input 3 10.1 20 10 3.0 20 10 30.5 20.4 19.6 Sample Output 25.0000 9.0000 96.0400
Travelling 旅行的问题
Problem Description After coding so many days,Mr Acmer wants to have a good rest.So travelling is the best choice!He has decided to visit n cities(he insists on seeing all the cities!And he does not mind which city being his start station because superman can bring him to any city at first but only once.), and of course there are m roads here,following a fee as usual.But Mr Acmer gets bored so easily that he doesn't want to visit a city more than twice!And he is so mean that he wants to minimize the total fee!He is lazy you see.So he turns to you for help. Input There are several test cases,the first line is two intergers n(1<=n<=10) and m,which means he needs to visit n cities and there are m roads he can choose,then m lines follow,each line will include three intergers a,b and c(1<=a,b<=n),means there is a road between a and b and the cost is of course c.Input to the End Of File. Output Output the minimum fee that he should pay,or -1 if he can't find such a route. Sample Input 2 1 1 2 100 3 2 1 2 40 2 3 50 3 3 1 2 3 1 3 4 2 3 10 Sample Output 100 90 7
Dogs 代码的计算
Problem Description Prairie dog comes again! Someday one little prairie dog Tim wants to visit one of his friends on the farmland, but he is as lazy as his friend (who required Tim to come to his place instead of going to Tim's), So he turn to you for help to point out how could him dig as less as he could. We know the farmland is divided into a grid, and some of the lattices form houses, where many little dogs live in. If the lattices connect to each other in any case, they belong to the same house. Then the little Tim start from his home located at (x0, y0) aim at his friend's home ( x1, y1 ). During the journey, he must walk through a lot of lattices, when in a house he can just walk through without digging, but he must dig some distance to reach another house. The farmland will be as big as 1000 * 1000, and the up left corner is labeled as ( 1, 1 ). Input The input is divided into blocks. The first line in each block contains two integers: the length m of the farmland, the width n of the farmland (m, n ≤ 1000). The next lines contain m rows and each row have n letters, with 'X' stands for the lattices of house, and '.' stands for the empty land. The following two lines is the start and end places' coordinates, we guarantee that they are located at 'X'. There will be a blank line between every test case. The block where both two numbers in the first line are equal to zero denotes the end of the input. Output For each case you should just output a line which contains only one integer, which is the number of minimal lattices Tim must dig. Sample Input 6 6 ..X... XXX.X. ....X. X..... X..... X.X... 3 5 6 3 0 0 Sample Output 3
Lazy Math Instructor
Description A math instructor is too lazy to grade a question in the exam papers in which students are supposed to produce a complicated formula for the question asked. Students may write correct answers in different forms which makes grading very hard. So, the instructor needs help from computer programmers and you can help. You are to write a program to read different formulas and determine whether or not they are arithmetically equivalent. Input The first line of the input contains an integer N (1 <= N <= 20) that is the number of test cases. Following the first line, there are two lines for each test case. A test case consists of two arithmetic expressions, each on a separate line with at most 80 characters. There is no blank line in the input. An expression contains one or more of the following: Single letter variables (case insensitive). Single digit numbers. Matched left and right parentheses. Binary operators +, - and * which are used for addition, subtraction and multiplication respectively. Arbitrary number of blank or tab characters between above tokens. Note: Expressions are syntactically correct and evaluated from left to right with equal precedence (priority) for all operators. The coefficients and exponents of the variables are guaranteed to fit in 16-bit integers. Output Your program must produce one line for each test case. If input expressions for each test data are arithmetically equivalent, "YES", otherwise "NO" must be printed as the output of the program. Output should be all in upper-case characters. Sample Input 3 (a+b-c)*2 (a+a)+(b*2)-(3*c)+c a*2-(a+c)+((a+c+e)*2) 3*a+c+(2*e) (a-b)*(a-b) (a*a)-(2*a*b)-(b*b) Sample Output YES YES NO
Magic Potion 代码的思想
Problem Description In a distant magic world, there is a powerful magician aswmtjdsj. One day,aswmtjdsj decide to teach his prentice ykwd to make some magic potions. The magic potion is made by 8 kinds of materials, what aswmtjdsj need to do is to tell ykwd how many each kind of materials is required. In order to prevent others from stealing these formulas, he decide to encrypt the formula. Assuming the amount of the eight kinds of materials are x1, x2, ... x8, aswmtjdsj will use a number m to encrypt, and finally tell ykwd nine numbers:x1 xor m, x2 xor m ,...., x8 xor m, (x1 + x2 +...+ x8) xor m . ykwd is too lazy,however,to calculate the value of the number m, so he asks you to help him to find the number m. Input The first line is an integer t, the number of test cases. Each of the next t lines contains 9 integers, respectively, x1 xor m, x2 xor m ,...., x8 xor m, (x1 + x2 +...+ x8) xor m, each of the 9 numbers is less or equal to 231-1. Output For each test case you should output the value of m in a single line, you can assume that 0 <= m <= 231-1. Sample Input 2 1 2 3 4 5 6 7 8 36 5 5 5 5 5 5 5 5 123 Sample Output 0 11
Lazy Pianist 音乐算法的问题
Description Music and mathematics always had a close relationship. Since Pythagoras, it is known that tonal harmony is closely related to the numerical relation of the frequencies. A lazy pianist, that uses to play VEERY LAARGE melodies composed by Kindermann, has taken advantage of this narrow relationship. However, this pianist commonly plays only the half or a quarter of the total notes. Amazingly, the audience never has realized his trick. The main reason is that this pianist always plays melodies that have a particular characteristic that is better described by the sequence of melody shown in figure 1. Figure 1. A sequence generated by Kindermann As you can see, the complete sequence is: DO DO RE DO RE RE MI DO RE RE MI RE MI MI FA DO However, if we choose only even notes, we can obtain the following sequence: DO DO RE DO RE RE MI DO RE RE MI RE MI MI FA DO DO DO RE DO RE RE MI DO This is exactly the same melody. Even more, we can observe that choosing only every fourth note, we obtain: DO DO RE … And, this is exactly the same melody. The lazy pianist would like to continue playing this kind of melodies, but he does not know how to complete the melody shown in figure 1. You must construct an algorithm in order to complete that melody. A useful tip to do the job would be to assume that every note should be represented by an integer. Thus, DO=1, RE=2, MI=3, etc. Thus, sequence presented earlier could be seen as: A possible algorithm for generating the sequence is shown in table 1. Every decimal number is expressed by its binary representation, and then we add the number of 1's that exist in that representation. This value indicates the note. Input Input consists of a list of three positive integers (total, cant, pos), preceded by an integer number that means the total of cases. Where total means total of tones to generate, cant means how many tones should be shown as a result, and pos means the start point. In this way, if cant=2, and pos=1, then this mean that it is needed to generate a sequence of 2 values starting from position number one. It is not allowed that pos has a value greater than total, and obviously neither that ((pos + cant ) -1) > total. Output A sequence of positive integers separated by a space. Each integer means one note of the melody . Sample Input 5 16 3 10 2 2 1 5 5 2 8 1 8 15 15 1 Sample Output Case 1: 2 3 2 Case 2: 1 1 Case 3: It cannot be solved. Case 4: 1 Case 5: 1 1 2 1 2 2 3 1 2 2 3 2 3 3 4
关于Hibernate的二级缓存配置
配置二级缓存时在实体xx.hbm.xml中配置的 ``` <cache usage="read-only" include="non-lazy" region="personCache"/> ``` 关于这个include属性,我看官方文档上说all是对所有属性就行缓存,non-lazy是对不是lazy加载的属性缓存,问题是我怎么判断它到底有没有对lazy="true"的属性缓存呢?
python flask_sqlalchemy如何维护一个全局查询结果
在我的webapp中,每个页面都要用到同一个一般不会变化的查询结果,为避免每次访问都需查询一次这个变量,我在views.py中弄了一个全局变量ADMIN_NOTES ``` ADMIN_NOTES=Note.query.filter_by(author_id=ADMIN.id).all() ``` 而当ADMIN_NOTE会发生变化时,如此时管理员又写入了一个新note,则重新查询数据库获得最新的ADMIN_NOTE的值,尽量减少访问数据库的次数 我本想这么实现的(中间部分不重要的代码省略了) ``` #全局变量 ADMIN_NOTES=Note.query.filter_by(author_id=ADMIN.id).all() #写入新note的函数1 @app.route('/new_note',methods=['GET','POST']) def new_note(): global ADMIN_NOTES data=json.loads(request.get_data()) note=Note(title=data['note_title'],upload_time=datetime.utcnow()) db.session.add(note) db.session.commit() #若是管理员写入新note,则重新查询并修改全局变量ADMIN_NOTES if note.author.nickname=='ADMIN': ADMIN_NOTES=Note.query.filter_by(author_id=ADMIN.id).all() KAFENUT_NOTES[0].author.nickname #能正确访问ADMIN_NOTES print(len(ADMIN_NOTES)) #正确访问ADMIN_NOTES resp['success']=True resp['text']='Upload successfully!' resp['url']=url_for('note',note_id=note.id,nickname=note.author.nickname) #浏览器接受到服务器的json之后跳转到,resp[url]所指示的页面,即下面这个页面 return json.dumps(resp) #返回note页面的函数2 @app.route('/<nickname>/note/<note_id>',methods=['GET','POST']) def note(nickname,note_id): global ADMIN_NOTES user=User.query.filter_by(nickname=nickname).first() note=Note.query.filter_by(id=note_id).first() if request.method=='GET': note.view_num+=1 db.session.add(note) db.session.commit() for nnote in ADMIN_NOTES: print(nnote.author.nickname) #出错位置 return render_template('note_page.html',note=note,admin_notes=ADMIN_NOTES) ``` 然而问题也正出在这里,当管理员写入新的note之后(即ADMIN_NOTES这个全局变量发生变化之后)重新查询的语句虽然在函数1中执行了(print出的note数量是写入新note之后的数量,)。但当用户根据函数1返回的json跳转到函数2的时候,函数2内就无法正确访问ADMIN_NOTES,准确来说无法访问nnote.author.nickname,其中author是note表用author_id这个外键连接到user表得到的,错误栈如下 ``` Traceback (most recent call last): File "C:\Users\MSI-1\Anaconda3\lib\site-packages\flask\app.py", line 1997, in __call__ return self.wsgi_app(environ, start_response) File "C:\Users\MSI-1\Anaconda3\lib\site-packages\flask\app.py", line 1985, in wsgi_app response = self.handle_exception(e) File "C:\Users\MSI-1\Anaconda3\lib\site-packages\flask\app.py", line 1540, in handle_exception reraise(exc_type, exc_value, tb) File "C:\Users\MSI-1\Anaconda3\lib\site-packages\flask\_compat.py", line 33, in reraise raise value File "C:\Users\MSI-1\Anaconda3\lib\site-packages\flask\app.py", line 1982, in wsgi_app response = self.full_dispatch_request() File "C:\Users\MSI-1\Anaconda3\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request rv = self.handle_user_exception(e) File "C:\Users\MSI-1\Anaconda3\lib\site-packages\flask\app.py", line 1517, in handle_user_exception reraise(exc_type, exc_value, tb) File "C:\Users\MSI-1\Anaconda3\lib\site-packages\flask\_compat.py", line 33, in reraise raise value File "C:\Users\MSI-1\Anaconda3\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request rv = self.dispatch_request() File "C:\Users\MSI-1\Anaconda3\lib\site-packages\flask\app.py", line 1598, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "E:\vs\python\AwesomeWebApp\AwesomeWebApp\app\views.py", line 232, in note print(nnote.author.nickname) #let author.id be preloaded File "C:\Users\MSI-1\Anaconda3\lib\site-packages\sqlalchemy\orm\attributes.py", line 282, in __get__ return self.impl.get(instance_state(instance), dict_) File "C:\Users\MSI-1\Anaconda3\lib\site-packages\sqlalchemy\orm\attributes.py", line 710, in get value = self.callable_(state, passive) File "C:\Users\MSI-1\Anaconda3\lib\site-packages\sqlalchemy\orm\strategies.py", line 688, in _load_for_state % (orm_util.state_str(state), self.key) sqlalchemy.orm.exc.DetachedInstanceError: Parent instance <Note at 0x26de5f41198> is not bound to a Session; lazy load operation of attribute 'author' cannot proceed (Background on this error at: http://sqlalche.me/e/bhk3) ``` sqlalchemy报出detached错误 sqlalchemy.orm.exc.DetachedInstanceError: Parent instance <Note at 0x26de5f41198> is not bound to a Session; lazy load operation of attribute 'author' cannot proceed (Background on this error at: http://sqlalche.me/e/bhk3) 这该怎么解决?或者还有什么其他方法实现:在我的webapp中,每个页面都要用到同一个一般不会变化的查询结果,为避免每次访问都需查询一次这个一般不会变量,我在views.py中弄了一个全局变量ADMIN_NOTES。而当ADMIN_NOTE会发生变化时,如此时管理员又写入了一个新note,则重新查询数据库获得最新的ADMIN_NOTE的值,尽量减少访问数据库的次数
Little Sheep 程序设计问题
Problem Description As we all know, sheep are very lazy, they don’t like move and just want to enjoy delicious food. So, Mr. LittleSheep who is in charge of a farm which owns lots of sheep is extremely tired in feeding these sheep. Mr. LittleSheep’s farm is like a circle consists of n corrals, each corral has a certain number of sheep, and every corral has a door for feeding. When it comes to feeding time, Mr. LittleSheep has to decide in which orders should he open those doors, because he can just open one door every time, otherwise these tricky sheep would run away. When the door is opened, the lazy sheep whose distance to the open door less or equal to k will go out, the distance to the open door is defined by the number of corrals between the open door and sheep’s corral. Due to the narrow door, it is allowed just one sheep to leave per minute. In order to let other lazy sheep get fed, Mr. LittleSheep has to move to anther corral to open the door, we assume the distance between the current corral and the destination is D, and the maximum amount of sheep among the rest corrals is M, then it takes D*M minute to move. (Because every step Mr. LittleSheep moves, it takes M minute to calm down the largest group of sheep), Now the question is how Mr. LittleSheep should move to use the least time for feeding all these lazy sheep. Mr. LittleSheep always started his work at 1st corral. Input The first line is two integers n, k which indicates the number of corrals and the longest distance which sheep are willing to go. The second line is n positive integers which describe the amount of sheep in each corral. The ith number a[i] is the number of sheep in ith corral. (1 <= a[i] <= 10000)(1 <= n <= 2000, 1 <= k <= 500 ,k <= n/2 ) Output The minimum minutes Mr. LittleSheep should take to feed all sheep. Sample Input 6 1 4 1 2 3 1 3 Sample Output 21
flask-sqlalchemy一对多的问题
``` class CmfUser(db.Model): id = db.Column(db.Integer, primary_key=True) user_nickname = db.Column(db.String(80), unique=True) user_email = db.Column(db.String(120)) favorites = db.relationship('CmfUserFavorite', backref='user', lazy='dynamic') class CmfUserFavorite(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100)) user_id = db.Column(db.Integer, db.ForeignKey('cmf_user.id')) ``` ``` u = CmfUserFavorite.query.filter(CmfUserFavorite.title == '222').first() # ✅ u.user返回正确 ``` 就是用户的爱好查询用户可以,但是查询用户再查询关联的爱好列表,就不不对。。 返回的一条语句 ``` f = CmfUser.query.filter(CmfUser.user_nickname == 'eddy').first() # ❌ f.favorites 返回错误 ``` ``` SELECT cmf_user_favorite.id AS cmf_user_favorite_id, cmf_user_favorite.title AS cmf_user_favorite_title, cmf_user_favorite.user_id AS cmf_user_favorite_user_id FROM cmf_user_favorite WHERE %(param_1)s = cmf_user_favorite.user_id ```
小程序多层渲染出现数据重复渲染问题,请问该怎么改?
![图片说明](https://img-ask.csdn.net/upload/201910/13/1570936628_317916.png) ``` <block class="goods" bindtap="goto" id="{{item.id}}" wx:for="{{list}}" wx:key="{{item._id}}"> <view wx:for="{{item}}" wx:for-item="child"> <view wx:for="{{child}}" wx:for-item="childs"> <image lazy-load="true" class="good-img" src="{{childs.image}}"></image> <view class="good-cont"> <text class="good-title">{{childs.title}}</text> <view class="good-price"> ¥{{childs.price}} <!-- <view>{{item._id}}</view> --> <view class="cart" data-item="{{childs}}" catchtap="addCart"> + </view> </view> </view> </view> </view> </block> ``` 数据是有的,但是显示不出来 ![图片说明](https://img-ask.csdn.net/upload/201910/13/1570936743_640236.png)
unity ios 模拟器运行 dyld: Symbol not found: _luaL_newstate
是unity版本5.6 模拟器运行构建场景的时候 报错。 报错信息如下 dyld: lazy symbol binding failed: Symbol not found: _luaL_newstate Referenced from: /Users/apple/Library/Developer/CoreSimulator/Devices/B0CB5474-7819-4921-A2F9-B53C300991B2/data/Containers/Bundle/Application/A66D2A95-C7DE-4DC0-9137-AC7695228344/xhl.app/xhl Expected in: flat namespace dyld: Symbol not found: _luaL_newstate Referenced from: /Users/apple/Library/Developer/CoreSimulator/Devices/B0CB5474-7819-4921-A2F9-B53C300991B2/data/Containers/Bundle/Application/A66D2A95-C7DE-4DC0-9137-AC7695228344/xhl.app/xhl Expected in: flat namespace ![图片说明](https://img-ask.csdn.net/upload/201911/11/1573451112_959038.jpg)
工作量的计算算法,A Lazy Worker
Description There is a worker who may lack the motivation to perform at his peak level of efficiency because he is lazy. He wants to minimize the amount of work he does (he is Lazy, but he is subject to a constraint that he must be busy when there is work that he can do.) We consider a set of jobs 1, 2,..., n having processing times t1, t2,...,tn respectively. Job i arrives at time ai and has its deadline at time di. We assume that ti, ai, and di have nonnegative integral values. The jobs have hard deadlines, meaning that each job i can only be executed during its allowed interval Ii=[ai, di]. The jobs are executed by the worker, and the worker executes only one job at a time. Once a job is begun, it must be completed without interruptions. When a job is completed, another job must begin immediately, if one exists to be executed. Otherwise, the worker is idle and begins executing a job as soon as one arrives. You should note that for each job i, the length of Ii, di - ai, is greater than or equal to ti, but less than 2*ti. Write a program that finds the minimized total amount of time executed by the worker. Input The input consists of T test cases. The number of test cases (T ) is given in the first line of the input file. The number of jobs (0<=n<=100) is given in the first line of each test case, and the following n lines have each job's processing time(1<=ti<=20),arrival time(0<=ai<=250), and deadline time (1<=di<=250) as three integers. Output Print exactly one line for each test case. The output should contain the total amount of time spent working by the worker. Sample Input 3 3 15 0 25 50 0 90 45 15 70 3 15 5 20 15 25 40 15 45 60 5 3 3 6 3 6 10 3 14 19 6 7 16 4 4 11 Sample Output 50 45 15
Magic Potion 的具体编写
Problem Description In a distant magic world, there is a powerful magician aswmtjdsj. One day,aswmtjdsj decide to teach his prentice ykwd to make some magic potions. The magic potion is made by 8 kinds of materials, what aswmtjdsj need to do is to tell ykwd how many each kind of materials is required. In order to prevent others from stealing these formulas, he decide to encrypt the formula. Assuming the amount of the eight kinds of materials are x1, x2, ... x8, aswmtjdsj will use a number m to encrypt, and finally tell ykwd nine numbers:x1 xor m, x2 xor m ,...., x8 xor m, (x1 + x2 +...+ x8) xor m . ykwd is too lazy,however,to calculate the value of the number m, so he asks you to help him to find the number m. Input The first line is an integer t, the number of test cases. Each of the next t lines contains 9 integers, respectively, x1 xor m, x2 xor m ,...., x8 xor m, (x1 + x2 +...+ x8) xor m, each of the 9 numbers is less or equal to 231-1. Output For each test case you should output the value of m in a single line, you can assume that 0 <= m <= 231-1. Sample Input 2 1 2 3 4 5 6 7 8 36 5 5 5 5 5 5 5 5 123 Sample Output 0 11
Lazy Cows
Description Farmer John regrets having applied high-grade fertilizer to his pastures since the grass now grows so quickly that his cows no longer need to move around when they graze. As a result, the cows have grown quite large and lazy... and winter is approaching. Farmer John wants to build a set of barns to provide shelter for his immobile cows and believes that he needs to build his barns around the cows based on their current locations since they won't walk to a barn, no matter how close or comfortable. The cows' grazing pasture is represented by a 2 x B (1 <= B <= 15,000,000) array of cells, some of which contain a cow and some of which are empty. N (1 <= N <= 1000) cows occupy the cells in this pasture: ------------------------------------------------------- | | cow | | | | cow | cow | cow | cow | ------------------------------------------------------- | | cow | cow | cow | | | | | | ------------------------------------------------------- Ever the frugal agrarian, Farmer John would like to build a set of just K (1 <= K <= N) rectangular barns (oriented with walls parallel to the pasture's edges) whose total area covers the minimum possible number of cells. Each barn covers a rectangular group of cells in their entirety, and no two barns may overlap. Of course, the barns must cover all of the cells containing cows. By way of example, in the picture above if K=2 then the optimal solution contains a 2x3 barn and a 1x4 barn and covers a total of 10 units of area. Input * Line 1: Three space-separated integers, N, K, and B. * Lines 2..N+1: Two space-separated integers in the range (1,1) to (2,B) giving the coordinates of the cell containing each cow. No cell contains more than one cow. Output * Line 1: The minimum area required by the K barns in order to cover all of the cows. Sample Input 8 2 9 1 2 1 6 1 7 1 8 1 9 2 2 2 3 2 4 Sample Output 10
终于明白阿里百度这样的大公司,为什么面试经常拿ThreadLocal考验求职者了
点击上面↑「爱开发」关注我们每晚10点,捕获技术思考和创业资源洞察什么是ThreadLocalThreadLocal是一个本地线程副本变量工具类,各个线程都拥有一份线程私...
《奇巧淫技》系列-python!!每天早上八点自动发送天气预报邮件到QQ邮箱
将代码部署服务器,每日早上定时获取到天气数据,并发送到邮箱。 也可以说是一个小人工智障。 思路可以运用在不同地方,主要介绍的是思路。
加快推动区块链技术和产业创新发展,2019可信区块链峰会在京召开
11月8日,由中国信息通信研究院、中国通信标准化协会、中国互联网协会、可信区块链推进计划联合主办,科技行者协办的2019可信区块链峰会将在北京悠唐皇冠假日酒店开幕。   区块链技术被认为是继蒸汽机、电力、互联网之后,下一代颠覆性的核心技术。如果说蒸汽机释放了人类的生产力,电力解决了人类基本的生活需求,互联网彻底改变了信息传递的方式,区块链作为构造信任的技术有重要的价值。   1...
阿里面试官问我:如何设计秒杀系统?我的回答让他比起大拇指
你知道的越多,你不知道的越多 点赞再看,养成习惯 GitHub上已经开源 https://github.com/JavaFamily 有一线大厂面试点脑图和个人联系方式,欢迎Star和指教 前言 Redis在互联网技术存储方面使用如此广泛,几乎所有的后端技术面试官都要在Redis的使用和原理方面对小伙伴们进行360°的刁难。 作为一个在互联网公司面一次拿一次Offer的面霸,打败了...
C语言魔塔游戏
很早就很想写这个,今天终于写完了。 游戏截图: 编译环境: VS2017 游戏需要一些图片,如果有想要的或者对游戏有什么看法的可以加我的QQ 2985486630 讨论,如果暂时没有回应,可以在博客下方留言,到时候我会看到。 下面我来介绍一下游戏的主要功能和实现方式 首先是玩家的定义,使用结构体,这个名字是可以自己改变的 struct gamerole { char n...
面试官问我:什么是消息队列?什么场景需要他?用了会出现什么问题?
你知道的越多,你不知道的越多 点赞再看,养成习惯 GitHub上已经开源 https://github.com/JavaFamily 有一线大厂面试点脑图、个人联系方式和人才交流群,欢迎Star和完善 前言 消息队列在互联网技术存储方面使用如此广泛,几乎所有的后端技术面试官都要在消息队列的使用和原理方面对小伙伴们进行360°的刁难。 作为一个在互联网公司面一次拿一次Offer的面霸...
Android性能优化(4):UI渲染机制以及优化
文章目录1. 渲染机制分析1.1 渲染机制1.2 卡顿现象1.3 内存抖动2. 渲染优化方式2.1 过度绘制优化2.1.1 Show GPU overdraw2.1.2 Profile GPU Rendering2.2 卡顿优化2.2.1 SysTrace2.2.2 TraceView 在从Android 6.0源码的角度剖析View的绘制原理一文中,我们了解到View的绘制流程有三个步骤,即m...
微服务中的Kafka与Micronaut
今天,我们将通过Apache Kafka主题构建一些彼此异步通信的微服务。我们使用Micronaut框架,它为与Kafka集成提供专门的库。让我们简要介绍一下示例系统的体系结构。我们有四个微型服务:订单服务,行程服务,司机服务和乘客服务。这些应用程序的实现非常简单。它们都有内存存储,并连接到同一个Kafka实例。 我们系统的主要目标是为客户安排行程。订单服务应用程序还充当网关。它接收来自客户的请求...
致 Python 初学者们!
作者| 许向武 责编 | 屠敏 出品 | CSDN 博客 前言 在 Python 进阶的过程中,相信很多同学应该大致上学习了很多 Python 的基础知识,也正在努力成长。在此期间,一定遇到了很多的困惑,对未来的学习方向感到迷茫。我非常理解你们所面临的处境。我从2007年开始接触 Python 这门编程语言,从2009年开始单一使用 Python 应对所有的开发工作,直至今...
究竟你适不适合买Mac?
我清晰的记得,刚买的macbook pro回到家,开机后第一件事情,就是上了淘宝网,花了500元钱,找了一个上门维修电脑的师傅,上门给我装了一个windows系统。。。。。。 表砍我。。。 当时买mac的初衷,只是想要个固态硬盘的笔记本,用来运行一些复杂的扑克软件。而看了当时所有的SSD笔记本后,最终决定,还是买个好(xiong)看(da)的。 已经有好几个朋友问我mba怎么样了,所以今天尽量客观...
程序员一般通过什么途径接私活?
二哥,你好,我想知道一般程序猿都如何接私活,我也想接,能告诉我一些方法吗? 上面是一个读者“烦不烦”问我的一个问题。其实不止是“烦不烦”,还有很多读者问过我类似这样的问题。 我接的私活不算多,挣到的钱也没有多少,加起来不到 20W。说实话,这个数目说出来我是有点心虚的,毕竟太少了,大家轻喷。但我想,恰好配得上“一般程序员”这个称号啊。毕竟苍蝇再小也是肉,我也算是有经验的人了。 唾弃接私活、做外...
字节跳动面试官这样问消息队列:分布式事务、重复消费、顺序消费,我整理了一下
你知道的越多,你不知道的越多 点赞再看,养成习惯 GitHub上已经开源 https://github.com/JavaFamily 有一线大厂面试点脑图、个人联系方式和人才交流群,欢迎Star和完善 前言 消息队列在互联网技术存储方面使用如此广泛,几乎所有的后端技术面试官都要在消息队列的使用和原理方面对小伙伴们进行360°的刁难。 作为一个在互联网公司面一次拿一次Offer的面霸...
Python爬虫爬取淘宝,京东商品信息
小编是一个理科生,不善长说一些废话。简单介绍下原理然后直接上代码。 使用的工具(Python+pycharm2019.3+selenium+xpath+chromedriver)其中要使用pycharm也可以私聊我selenium是一个框架可以通过pip下载 pip installselenium -ihttps://pypi.tuna.tsinghua.edu.cn/simple/ ...
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
Java工作4年来应聘要16K最后没要,细节如下。。。
前奏: 今天2B哥和大家分享一位前几天面试的一位应聘者,工作4年26岁,统招本科。 以下就是他的简历和面试情况。 基本情况: 专业技能: 1、&nbsp;熟悉Sping了解SpringMVC、SpringBoot、Mybatis等框架、了解SpringCloud微服务 2、&nbsp;熟悉常用项目管理工具:SVN、GIT、MAVEN、Jenkins 3、&nbsp;熟悉Nginx、tomca...
SpringBoot2.x系列教程(三十六)SpringBoot之Tomcat配置
Spring Boot默认内嵌的Tomcat为Servlet容器,关于Tomcat的所有属性都在ServerProperties配置类中。同时,也可以实现一些接口来自定义内嵌Servlet容器和内嵌Tomcat等的配置。 关于此配置,网络上有大量的资料,但都是基于SpringBoot1.5.x版本,并不适合当前最新版本。本文将带大家了解一下最新版本的使用。 ServerProperties的部分源...
Python绘图,圣诞树,花,爱心 | Turtle篇
每周每日,分享Python实战代码,入门资料,进阶资料,基础语法,爬虫,数据分析,web网站,机器学习,深度学习等等。 公众号回复【进群】沟通交流吧,QQ扫码进群学习吧 微信群 QQ群 1.画圣诞树 import turtle screen = turtle.Screen() screen.setup(800,600) circle = turtle.Turtle()...
作为一个程序员,CPU的这些硬核知识你必须会!
CPU对每个程序员来说,是个既熟悉又陌生的东西? 如果你只知道CPU是中央处理器的话,那可能对你并没有什么用,那么作为程序员的我们,必须要搞懂的就是CPU这家伙是如何运行的,尤其要搞懂它里面的寄存器是怎么一回事,因为这将让你从底层明白程序的运行机制。 随我一起,来好好认识下CPU这货吧 把CPU掰开来看 对于CPU来说,我们首先就要搞明白它是怎么回事,也就是它的内部构造,当然,CPU那么牛的一个东...
破14亿,Python分析我国存在哪些人口危机!
一、背景 二、爬取数据 三、数据分析 1、总人口 2、男女人口比例 3、人口城镇化 4、人口增长率 5、人口老化(抚养比) 6、各省人口 7、世界人口 四、遇到的问题 遇到的问题 1、数据分页,需要获取从1949-2018年数据,观察到有近20年参数:LAST20,由此推测获取近70年的参数可设置为:LAST70 2、2019年数据没有放上去,可以手动添加上去 3、将数据进行 行列转换 4、列名...
听说想当黑客的都玩过这个Monyer游戏(1~14攻略)
第零关 进入传送门开始第0关(游戏链接) 请点击链接进入第1关: 连接在左边→ ←连接在右边 看不到啊。。。。(只能看到一堆大佬做完的留名,也能看到菜鸡的我,在后面~~) 直接fn+f12吧 &lt;span&gt;连接在左边→&lt;/span&gt; &lt;a href="first.php"&gt;&lt;/a&gt; &lt;span&gt;←连接在右边&lt;/span&gt; o...
在家远程办公效率低?那你一定要收好这个「在家办公」神器!
相信大家都已经收到国务院延长春节假期的消息,接下来,在家远程办公可能将会持续一段时间。 但是问题来了。远程办公不是人在电脑前就当坐班了,相反,对于沟通效率,文件协作,以及信息安全都有着极高的要求。有着非常多的挑战,比如: 1在异地互相不见面的会议上,如何提高沟通效率? 2文件之间的来往反馈如何做到及时性?如何保证信息安全? 3如何规划安排每天工作,以及如何进行成果验收? ...... ...
作为一个程序员,内存和磁盘的这些事情,你不得不知道啊!!!
截止目前,我已经分享了如下几篇文章: 一个程序在计算机中是如何运行的?超级干货!!! 作为一个程序员,CPU的这些硬核知识你必须会! 作为一个程序员,内存的这些硬核知识你必须懂! 这些知识可以说是我们之前都不太重视的基础知识,可能大家在上大学的时候都学习过了,但是嘞,当时由于老师讲解的没那么有趣,又加上这些知识本身就比较枯燥,所以嘞,大家当初几乎等于没学。 再说啦,学习这些,也看不出来有什么用啊!...
这个世界上人真的分三六九等,你信吗?
偶然间,在知乎上看到一个问题 一时间,勾起了我深深的回忆。 以前在厂里打过两次工,做过家教,干过辅导班,做过中介。零下几度的晚上,贴过广告,满脸、满手地长冻疮。 再回首那段岁月,虽然苦,但让我学会了坚持和忍耐。让我明白了,在这个世界上,无论环境多么的恶劣,只要心存希望,星星之火,亦可燎原。 下文是原回答,希望能对你能有所启发。 如果我说,这个世界上人真的分三六九等,...
2020年全新Java学习路线图,含配套视频,学完即为中级Java程序员!!
新的一年来临,突如其来的疫情打破了平静的生活! 在家的你是否很无聊,如果无聊就来学习吧! 世上只有一种投资只赚不赔,那就是学习!!! 传智播客于2020年升级了Java学习线路图,硬核升级,免费放送! 学完你就是中级程序员,能更快一步找到工作! 一、Java基础 JavaSE基础是Java中级程序员的起点,是帮助你从小白到懂得编程的必经之路。 在Java基础板块中有6个子模块的学...
B 站上有哪些很好的学习资源?
哇说起B站,在小九眼里就是宝藏般的存在,放年假宅在家时一天刷6、7个小时不在话下,更别提今年的跨年晚会,我简直是跪着看完的!! 最早大家聚在在B站是为了追番,再后来我在上面刷欧美新歌和漂亮小姐姐的舞蹈视频,最近两年我和周围的朋友们已经把B站当作学习教室了,而且学习成本还免费,真是个励志的好平台ヽ(.◕ฺˇд ˇ◕ฺ;)ノ 下面我们就来盘点一下B站上优质的学习资源: 综合类 Oeasy: 综合...
爬取薅羊毛网站百度云资源
这是疫情期间无聊做的爬虫, 去获取暂时用不上的教程 import threading import time import pandas as pd import requests import re from threading import Thread, Lock # import urllib.request as request # req=urllib.request.Requ...
如何优雅地打印一个Java对象?
你好呀,我是沉默王二,一个和黄家驹一样身高,和刘德华一样颜值的程序员。虽然已经写了十多年的 Java 代码,但仍然觉得自己是个菜鸟(请允许我惭愧一下)。 在一个月黑风高的夜晚,我思前想后,觉得再也不能这么蹉跎下去了。于是痛下决心,准备通过输出的方式倒逼输入,以此来修炼自己的内功,从而进阶成为一名真正意义上的大神。与此同时,希望这些文章能够帮助到更多的读者,让大家在学习的路上不再寂寞、空虚和冷。 ...
雷火神山直播超两亿,Web播放器事件监听是怎么实现的?
Web播放器解决了在手机浏览器和PC浏览器上播放音视频数据的问题,让视音频内容可以不依赖用户安装App,就能进行播放以及在社交平台进行传播。在视频业务大数据平台中,播放数据的统计分析非常重要,所以Web播放器在使用过程中,需要对其内部的数据进行收集并上报至服务端,此时,就需要对发生在其内部的一些播放行为进行事件监听。 那么Web播放器事件监听是怎么实现的呢? 01 监听事件明细表 名...
3万字总结,Mysql优化之精髓
本文知识点较多,篇幅较长,请耐心学习 MySQL已经成为时下关系型数据库产品的中坚力量,备受互联网大厂的青睐,出门面试想进BAT,想拿高工资,不会点MySQL优化知识,拿offer的成功率会大大下降。 为什么要优化 系统的吞吐量瓶颈往往出现在数据库的访问速度上 随着应用程序的运行,数据库的中的数据会越来越多,处理时间会相应变慢 数据是存放在磁盘上的,读写速度无法和内存相比 如何优化 设计...
HTML5适合的情人节礼物有纪念日期功能
前言 利用HTML5,css,js实现爱心树 以及 纪念日期的功能 网页有播放音乐功能 以及打字倾诉感情的画面,非常适合情人节送给女朋友 具体的HTML代码 具体只要修改代码里面的男某某和女某某 文字段也可自行修改,还有代码下半部分的JS代码需要修改一下起始日期 注意月份为0~11月 也就是月份需要减一。 当然只有一部分HTML和JS代码不够运行的,文章最下面还附加了完整代码的下载地址 &lt;!...
相关热词 c# 为空 判断 委托 c#记事本颜色 c# 系统默认声音 js中调用c#方法参数 c#引入dll文件报错 c#根据名称实例化 c#从邮件服务器获取邮件 c# 保存文件夹 c#代码打包引用 c# 压缩效率
立即提问