match

Codeforces - Match Points

蓝咒 提交于 2020-02-22 20:45:38
题目链接: Codeforces - Match Points 首先考虑二分答案。 怎么check呢?肯定是最小的mid个和最大的mid个匹配。 然后就做完了。 AC代码: # pragma GCC optimize("-Ofast","-funroll-all-loops") # include <bits/stdc++.h> //#define int long long using namespace std ; const int N = 2e5 + 10 ; int n , z , x [ N ] ; inline int check ( int mid ) { for ( int i = 1 ; i <= mid ; i ++ ) if ( x [ n - mid + i ] - x [ i ] < z ) return 0 ; return 1 ; } signed main ( ) { cin >> n >> z ; for ( int i = 1 ; i <= n ; i ++ ) scanf ( "%d" , & x [ i ] ) ; sort ( x + 1 , x + 1 + n ) ; int l = 0 , r = n / 2 ; while ( l < r ) { int mid = l + r + 1 >> 1 ; if ( check ( mid

ElasticSearch: How to search for a value in any field, across all types, in one or more indices?

我们两清 提交于 2020-02-21 13:25:42
问题 I have two indices my_index_1 and my_index_2 . Within these indices, I have the following document types: my_index_1 : people organizations roles skills my_index_2 : products services patents trademarks servicemarks Each of the types has different fields. My Question: What is the best way to query for the string "abc" in any field of any type, across any one or even both indices? I don't see anything in the documentation that facilitates such a search. Is there something that might look like:

ElasticSearch: How to search for a value in any field, across all types, in one or more indices?

♀尐吖头ヾ 提交于 2020-02-21 13:23:05
问题 I have two indices my_index_1 and my_index_2 . Within these indices, I have the following document types: my_index_1 : people organizations roles skills my_index_2 : products services patents trademarks servicemarks Each of the types has different fields. My Question: What is the best way to query for the string "abc" in any field of any type, across any one or even both indices? I don't see anything in the documentation that facilitates such a search. Is there something that might look like:

rails 表单路由设置以及rails4.0 create引起的ActiveModel::ForbiddenAttributesError错误

半世苍凉 提交于 2020-02-21 04:49:27
表单路由设置:post '/ads/create‘=>’ads#create' 表单页面路由设置:get'/ads/new'=>'ads#new' map . connect ':controller/:action/:id' 和 map . connect ':controller/:action/:id.:format' 在rails3里为match ':controller(/:action(/:id(/:format)))',via:[:get,:post] map.connect 'products/:id' , :controller => 'catalog' , :action => 'view' 在rails 3里为 match 'products/:id' , :to => 'catalog#view' map.logout 'logout' , :controller => 'sessions' , :action => ''在rails 3里为 match 'logout' , :to => 'sessions#destroy' , :as => 'logout' map.root :controller => 'welcome' , :action => 'show'在rails 3里为root :to => 'welcome#show' match

Material Design学习(二)——滑动菜单

瘦欲@ 提交于 2020-02-20 17:58:03
拷贝一份昨天的项目,并改名 day20_SlidingMenu 一、 DrawerLayout 抽屉布局 DrawerLayout 是个抽屉布局,可以放入两个子控件。第一个子控件是主屏幕显示的内容,第二个子控件是滑动菜单中显示的内容 主布局: <?xml version="1.0" encoding="utf-8"?> < androidx.drawerlayout.widget.DrawerLayout xmlns: android = " http://schemas.android.com/apk/res/android " xmlns: app = " http://schemas.android.com/apk/res-auto " android: id = " @+id/drawer_layout " android: layout_width = " match_parent " android: layout_height = " match_parent " > < FrameLayout android: layout_width = " match_parent " android: layout_height = " match_parent " > < androidx.appcompat.widget.Toolbar android: id = " @

js 正则 match

你说的曾经没有我的故事 提交于 2020-02-20 11:54:20
1. 全局匹配    全局匹配时,数组里的数据是匹配到的所有符合正则表达式的字符串。 2.非全局匹配    非全局匹配时,数据里的数据则是 第一个匹配的值 以及正则表达式的 子分组匹配到的值【以第一个值为输入值】 , 【该数组的第 0 个元素存放的是匹配文本,而其余的元素存放的是与正则表达式的子表达式匹配的文本】 再附加上三个属性:    groups :一个捕获组数组或者 undefined(如果没有定义命名捕获组)。    index :匹配结果的开始位置。    input :进行匹配的原字符串。 例子: 1 2 3 4 5 6 7 8 9 10 var patt = /\(([a-z]*([\d]*)[a-z]*)\)/; var pattg = /\(([a-z]*([\d]*)[a-z]*)\)/g; var testStr = '(aaaaa11111(bbbbbb2222222bbaa)bbb(sss333sss)asdbas123bd)' ; var result = testStr.match(patt); var resultg = testStr.match(pattg); console.log(result);   //=> ["(bbbbbb2222222bbaa)", "bbbbbb2222222bbaa", "2222222", index: 11

Elasticsearch——查询//过滤详细总结

拜拜、爱过 提交于 2020-02-17 15:00:03
https://blog.csdn.net/donghaixiaolongwang/article/details/57418306 查询分为两种:字符串查询和DSL查询 1、字符串查询详细总结,此种方法一般用于简单测试。想要更加灵活,功能更加强大的查询功能还是得用DSL。但是这个字符串查询用起来还是挺方便的。切记不可将这种查询语句给你的客户。除非这个客户是你非常信任的。要不然这种语句会给你的集群带来致命的危险!!!!! 1>GET /index/tweet/_search?q=tweet:elasticsearch #查询index索引 (相当于数据库)、tweet类型(相当于数据库中的表)、tweet字段中包含elasticsearch关键词的文章。 2>GET /index/tweet /_search?q=% 2Bname% 3Ajohn+% 2Btweet% 3Amary # +name:john +tweet:mary 查询name字段包含john 同时tweet字段包含mary。%2B 是“+”,%3A是“:” "+" 前缀表示语句匹配条件必须被满足。类似的 "-" 前缀表示条件必须不被满足。所有条件如果没有 + 或 - 表示是可选的——匹配越多,相关的文档就越多。 3>更复杂的例子: name 字段包含 "mary" 或 "john" date 晚于 2014-09

滑动窗口算法技巧

冷暖自知 提交于 2020-02-17 10:28:26
本文详解「滑动窗口」这种高级双指针技巧的算法框架,带你秒杀几道高难度的子字符串匹配问题。 LeetCode 上至少有 9 道题目可以用此方法高效解决。但是有几道是 VIP 题目,有几道题目虽不难但太复杂,所以本文只选择点赞最高,较为经典的,最能够讲明白的三道题来讲解。第一题为了让读者掌握算法模板,篇幅相对长,后两题就基本秒杀了。 本文代码为 C++ 实现,不会用到什么编程方面的奇技淫巧,但是还是简单介绍一下一些用到的数据结构,以免有的读者因为语言的细节问题阻碍对算法思想的理解: unordered_map 就是哈希表(字典),它的一个方法 count(key) 相当于 containsKey(key) 可以判断键 key 是否存在。 可以使用方括号访问键对应的值 map[key]。需要注意的是,如果该 key 不存在,C++ 会自动创建这个 key,并把 map[key] 赋值为 0。 所以代码中多次出现的 map[key]++ 相当于 Java 的 map.put(key, map.getOrDefault(key, 0) + 1) 。 本文大部分代码都是图片形式,可以点开放大,更重要的是可以左右滑动方便对比代码。下面进入正题。 一、最小覆盖子串 题目不难理解,就是说要在 S(source) 中找到包含 T(target) 中全部字母的一个子串,顺序无所谓

python正则表达式(3)--match方法

孤街醉人 提交于 2020-02-17 08:02:45
1.re.match函数 re.match 尝试从字符串的起始位置匹配一个模式,如果不是起始位置匹配成功的话,match()就返回None。 (1)函数语法 :   re.match(pattern, string, flags=0)   函数参数说明:     pattern 匹配的正则表达式     string 要匹配的字符串     flgs 标志位,用于控制正则表达式的匹配方式   我们可以使用group(num) 或 groups() 匹配对象函数来获取匹配表达式。   group(num=0) 获取匹配结果的各个分组的字符串,group() 可以一次输入多个组号,此时返回一个包含那些组所对应值的元组。   groups() 返回一个包含所有分组字符串的元组。   注意:如果未匹配成功, match ()返回值为None,此时再使用group()、groups() 方法会报错。       应该先获取匹配对象,然后判断匹配对象是否非空,当非空时在使用group()、groups() 方法获取匹配结果。见实例2 (2)实例 例1 import re print ( re . match (r ' How ' , ' How are you ' ) . span ( ) ) # 在起始位置匹配 print ( re . match (r ' are ' , ' How

Android Studio学习路程(11)

99封情书 提交于 2020-02-17 00:33:55
今天没有学习新的知识,把前面所学的复习了一下,今天做了一个简单的记账APP,实现了它的登录和界面之间的跳转的功能。下面是一些代码,我还没有做完。 1 package com.example.hp.jizhang; 2 3 import android.content.Context; 4 import android.content.Intent; 5 import android.content.SharedPreferences; 6 import android.support.v7.app.ActionBarActivity; 7 import android.os.Bundle; 8 import android.text.Editable; 9 import android.text.TextWatcher; 10 import android.util.Log; 11 import android.view.View; 12 import android.widget.CheckBox; 13 import android.widget.CompoundButton; 14 import android.widget.EditText; 15 16 public class MainActivity extends ActionBarActivity