col

pymongo helper

陌路散爱 提交于 2019-12-04 06:57:08
import pymongo import click # 数据库基本信息 db_configs = { 'type': 'mongo', 'host': '127.0.0.1', 'port': '27017', "user": "", "password": "", 'db_name': 'mafengwo' } class Mongo(): def __init__(self): self.db_name = db_configs.get("db_name") self.host = db_configs.get("host") self.port = db_configs.get("port") self.client = pymongo.MongoClient(f'mongodb://{self.host}:{self.port}', connect=False, maxPoolSize=10) self.username = db_configs.get("user") self.password = db_configs.get("passwd") if self.username and self.password: self.db = self.client[self.db_name].authenticate(self.username, self

[LeetCode] 240. Search a 2D Matrix II

对着背影说爱祢 提交于 2019-12-03 12:29:46
搜索一个二维矩阵之二。题意跟 [LeetCode] 74. Search a 2D Matrix 很接近,唯一的不同是matrix只是做到了每一行上的元素是有序的,每一列也是有序的,但是convert成一维数组后,一维数组并不能做到整体有序。例子 Example: Consider the following matrix: [ [1, 4, 7, 11, 15], [2, 5, 8, 12, 19], [3, 6, 9, 16, 22], [10, 13, 14, 17, 24], [18, 21, 23, 26, 30] ] Given target = 5 , return true . Given target = 20 , return false . 因为input的规律是每一行是有序的,每一列也是有序的,所以可以从数组的右上角(比如例子中的15好了)开始扫描,如果小于15,就往左;如果大于15,就一定在下一行。 时间O(m + n) 空间O(1) 1 /** 2 * @param {number[][]} matrix 3 * @param {number} target 4 * @return {boolean} 5 */ 6 var searchMatrix = function(matrix, target) { 7 // corner case 8 if

魔方阵

拈花ヽ惹草 提交于 2019-12-03 11:54:43
定义:     n阶矩阵(n×n),满足每一行、每一列、对角线元素的和相同,n>=3 分类: 1、奇数阶魔方阵 2、双偶数阶魔方阵(4*k) 3、单偶数阶魔方阵(4*k+2) 1、奇数阶魔方阵 1)首行的中间赋值1,arr[0][n/2]=1 2)将2到n 2 依次赋值:整体规律是 行数减一,列数加一 3)特殊情况:行标i=0时,减一后赋值最后一行i=n-1;列标j=n-1时,加一赋值第一列j=0 4)特殊情况:原位置已被占用,则下一个数放在上一个数的下面 1 void GetOddMagic(int arr[][MAX], int n) 2 { 3 int row = 0, col = n / 2, prow, pcol; 4 arr[row][col] = 1; 5 int t = 2; 6 while (t <= n*n) 7 { 8 prow = row, pcol = col;//记录row,col的副本 9 row = row>0 ? (--row) : (n - 1);//行数减一 10 col = col<(n - 1) ? (++col) : 0;//列数加一 11 if (arr[row][col]) 12 { 13 row = prow, col = pcol; 14 arr[++row][col] = t; 15 } 16 else 17 arr[row]

Tree

五迷三道 提交于 2019-12-03 11:51:18
https://loj.ac/problem/10069 题目描述   给出一张图,每条边除边权外还有颜色(黑白两色),求最小权的恰有 \(need\) 条白边的生成树。 思路   直接求最小生成树再不断删边和加边使得生成树恰有 \(need\) 条边且仍是最小权很难维护,我们可以考虑把所有白边都加上一个值,再求一遍最小生成树,可以证明这样必定可以有一种方案可以使一种求出的最小生成树恰有 \(need\) 条白边,这样就实现对白边数量的调节,而对于这个值我们可以进行二分。 代码 #include <bits/stdc++.h> using namespace std; const int MAXN=5e4+10,MAXM=1e5+10; struct Edge { int s,t,c,col; }e[MAXM]; int fa[MAXN],m,sum,n,need; bool cmp(Edge x,Edge y) { if(x.c==y.c)return x.col<y.col; else return x.c<y.c; } int find(int x) { return fa[x]==x?x:fa[x]=find(fa[x]); } bool check(int k) { for(int i=1;i<=m;i++) if(!e[i].col)e[i].c+=k; for(int

Collection接口的常用功能

允我心安 提交于 2019-12-03 11:48:02
package cn.dali2.code01; /*Collection常用的功能 * Collection是所有单列集合的父接口,因此在Collection中定义了单列集合通用的一些方法, * 这些方法可用于操作所有的单列集合,方法如下: * public boolean add(E e); 把给定的数据存储到集合当中 * public void clear(); 清空集合所有元素 * public boolean remove(E e); 把给定的数据在当前集合中删除,若是有该数据返回True,否则False * public boolean contains(E e); 判断当前集合中是否包含给定的对象 * public boolean isEmpty(); 判断当前集合是否为空 * public int size(); 返回集合中元素的个数 * public Object[] toArray(); 把集合中的元素转化为数组存储。*/ import java.util.ArrayList; import java.util.Collection; public class Demo01 { public static void main(String[] args) { Collection<String> col = new ArrayList<>();//多态写法

Table Column Formatting

拥有回忆 提交于 2019-12-03 08:45:58
问题 I'm trying to format a column in a <table/> using a <col/> element. I can set background-color , width , etc., but can't set the font-weight . Why doesn't it work? <table> <col style="font-weight:bold; background-color:#CCC;"> <col> <tr> <td>1</td> <td>2</td> </tr> <tr> <td>3</td> <td>4</td> </tr> </table> 回答1: As far as I know, you can only format the following using CSS on the <col> element: background-color border width visibility This page has more info. Herb is right - it's better to

Python Pandas - How to flatten a hierarchical index in columns

匿名 (未验证) 提交于 2019-12-03 08:30:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a data frame with a hierarchical index in axis 1 (columns) (from a groupby.agg operation): USAF WBAN year month day s_PC s_CL s_CD s_CNT tempf sum sum sum sum amax amin 0 702730 26451 1993 1 1 1 0 12 13 30.92 24.98 1 702730 26451 1993 1 2 0 0 13 13 32.00 24.98 2 702730 26451 1993 1 3 1 10 2 13 23.00 6.98 3 702730 26451 1993 1 4 1 0 12 13 10.04 3.92 4 702730 26451 1993 1 5 3 0 10 13 19.94 10.94 I want to flatten it, so that it looks like this (names aren't critical - I could rename): USAF WBAN year month day s_PC s_CL s_CD s_CNT tempf

Writing heirarchical JSON data to Excel xls from Python?

匿名 (未验证) 提交于 2019-12-03 08:28:06
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to write some data from python to xlsx. I currently have it stored as JSON, but it doesn't matter what it is going out of Python. Here's what the JSON for a single article would look like: { 'Word Count': 50 'Key Words': { ['Blah blah blah', 'Foo', ... ] } 'Frequency': { [9, 12, ... ] } 'Proper Nouns': { ['UN', 'USA', ... ] } 'Location': 'Mordor' } I checked out the XlsxWriter module but can't figure out how to translate hierarchical data that is not necessarily the same size (note the number of proper nouns between the two data

Tarjan算法之边双联通分量

隐身守侯 提交于 2019-12-03 07:48:11
定义 若一个无向连通图不存在割边,则称它为“边双连通图”。无向连通图的极大边双连通子图被称为“边双连通分量”,简记为“e-DCC” 定理 一个图为边双连通图,当且仅当任意一条边都至少包含在一个简单环中。 求法 把图中所有桥删除,剩下的都是e-DCC。 具体方法:一般用Tarjan标记所有桥边,再用dfs求出各连通块个数(遍历时不走桥)。 常和缩点搭配:把e-DCC的编号当做节点,桥当做节点间的连边,则会形成一棵树或一座森林。 例题 冗余路径 经典应用-构造边双连通分量:树的每一条边都是桥,但是给任意不同且不直接相连的两点加上一边后两点与其lca构成一个环,环上所有点为边强连通。由于题目要求连边最少,那么就使每次加的边让更多点边强连通。由上分析环的构造可知lca离两点越远对图上点贡献越多。那么每次将lca离两点最远的叶节点相连。本题不要求输出方案,所以因为每次都会 消掉两叶节点那么答案直接为(叶节点数 + 1)/2。(奇数剩余的一个点随便向其他点连边)。 #include<iostream> #include<cstdio> #include<cmath> #include<queue> #include<cstring> #include<algorithm> #define lson x<<1 #define rson x<<1|1 #define ll long long

何谓容器

半世苍凉 提交于 2019-12-03 06:46:11
容器 在学习容器之前不从一下昨天讲的 IO流中的一个对象流。 一、对象流 1. 对象流 序列化 公共流 (节点流) 2.主要用到的方法:ObjectInputStream,反序列化输入流, 新增方法 readObject();ObjectOutputStream ,序列化输出流, 新增方法 writeObject()。 3.编码示例: import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; public class ObjectDemo { public static void main(String[] args) throws FileNotFoundException, IOException,