社交网络可视化库

python: https://networkx.github.io/documentation/stable/tutorial.html

gephi软件:https://blog.csdn.net/qq_34440201/article/details/88871160

R语言:http://www.sohu.com/a/219456356_466874

Parallel Set:https://www.zhihu.com/question/350503470

Excel:NodeXL
http://www.360doc.com/content/12/0821/17/1188133_231558607.shtml

JS:VIS Network
https://visjs.github.io/vis-network/examples/

可视化库总结:https://www.jianshu.com/p/f25f2f2d759b?utm_campaign=hugo&utm_medium=reader_share&utm_content=note

Antlr4的c++版本(visual-studio)使用

官方demo

按照官网首页配置好,测试能够使用antlr4和grun命令之后:

创建自己的项目

如果要自己创建antlr4的项目,在刚才几步能正常执行之后,在【这个刚刚打开的解决方案里面】创建自己的项目:

新建项目

注意选择【添加到解决方案】。

修改以下属性:

  • 【新建的项目】里【引用】右键【添加引用】,选上antlr4cpp-vs2015
  • 添加引用
  • antlr4cpp-vs2015
  • 【源文件】-右键【添加】-【现有项】,选中上面几级目录的demo\generated文件夹下所有h、cpp文件
  • 添加generate文件
  • 新建一个main.cpp,里面复制过来antlr4cpp-demo的main.cpp
  • 在【新建的项目】上右键【属性】打开属性页面(这时,单击antlr4cpp-demo这个项目会切换到这个项目的对应属性,可以直接方便地复制粘贴),把antlr4cpp-demo的以下属性复制过来:
    • 复制【输出目录】
    • 输出目录
    • 修改【字符集】为Unicode
    • 字符集
    • 复制【C/C++】-【常规】-【附加包含目录】
    • 附加包含目录
  • 右上角【配置管理器】-找到这个项目后【编辑】,重命名为Debug DLL
  • 编辑
  • 重命名
  • 运行&改编码(选择是,因为之前把字符集改成了Unicode)
  • 改编码

之后就可以运行了!

LIB

LIB介绍:

LIB生成&使用:https://www.cnblogs.com/TenosDoIt/p/3203137.html

LIB创建

用桌面向导创建一个空的LIB

桌面向导

弹出的应用程序类型选择.lib

新建MyLIB.h

1
2
3
4
5
6
7
8
9
10
11
#pragma once
void fun(int a);

extern int k;

class testclass
{
public:
testclass();
void print();
};

MyLIB.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "stdafx.h"
#include "MyLIB.h"
#include <iostream>

void fun(int a)
{
std::cout << a << "lib gen\n";
}

int k = 222;

testclass::testclass()
{
std::cout << "123\n";
}

void testclass::print()
{
std::cout << "this is testcalss\n";
}

之后设置为启动项目,生成就可以得到lib文件:

生成lib

【输出】-【生成】可以看到目录

生成

LIB使用-引用

使用:新建空项目,添加引用,创建一个头文件把之前头文件的东西复制进来

引用&头文件

新建一个main.cpp

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include "MyLIB.h"

int main()
{
fun(4);
std::cout << k << std::endl;
testclass tc;
tc.print();
return 0;
}

LIB使用-复制LIB文件

找到lib文件,复制到main.cpp目录下,复制头文件过来,复制#pragma comment(lib, "lib.lib")到main.cpp文件中main函数上面即可。

ANTLR的lib生成

antlr4cpp-antlr2015这个项目属性里面改成配置类型-静态库,生成后复制得到的lib文件到自己的项目目录下。

复制antlr4-runtime.h等所有头文件到自己的项目目录下。

punkt

1
2
3
4
5
6
7
8
9
10
11
import nltk
import ssl

try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
pass
else:
ssl._create_default_https_context = _create_unverified_https_context

nltk.download('punkt')

————————————————
版权声明:本文为CSDN博主「huangyixian2」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/huangyixian2/article/details/84917690

下载后解压放到/venv/nltk_data/tokenizers

每日leetcode-115

Given a string S and a string T, count the number of distinct subsequences of S which equals T.

A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, “ACE” is a subsequence of “ABCDE” while “AEC” is not).

一个简单的动态规划即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public:
int numDistinct(string s, string t) {
int lens = s.size(), lent = t.size();
vector<vector<int>> dp(lens + 1, vector<int>(lent + 1, 0));
for (int i = 0; i <= lens; i++) {
dp[i][0] = 1;
}
for (int i = 1; i <= lens; i++) {
for (int j = 1; j <= i && j <= lent; j++) {
dp[i][j] = (int)((long long)(s[i - 1] == t[j - 1] ? dp[i - 1][j - 1] : 0) + dp[i - 1][j]);
}
}
return dp[lens][lent];
}
};

js模拟输入

1
2
3
4
5
6
7
8
9
10
11
window.___inputValue = function (dom, st) {
var evt = new InputEvent('input', {
inputType: 'insertText',
data: st,
dataTransfer: null,
isComposing: false
});
dom.value = st;
dom.dispatchEvent(evt);
}
window.___inputValue(xxx, 'aa');

每日leetcode-99

  1. Recover Binary Search Tree

Two elements of a binary search tree (BST) are swapped by mistake.

Recover the tree without changing its structure.

Follow up:

A solution using O(n) space is pretty straight forward.
Could you devise a constant space solution?

其实就相当于说全部排好序后,看第一个比右边大的和最后一个比左边小的,交换一下。

如果直接把它们全都放到数组里面,扫描一遍就行。这里是在遍历的时候进行操作。

要注意stack的pop是没有返回值的!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
void recoverTree(TreeNode* root) {
// find the first > right and last < left
// mid order
stack<TreeNode*> t;
TreeNode* now = root;
TreeNode *last = NULL;
TreeNode *first;
bool found_first = false;
TreeNode *last_ill_smaller_than_left;
while (now || !t.empty()) {
if (!now) {
now = t.top();
t.pop();
// visit now
if (last && last->val > now->val) {
last_ill_smaller_than_left = now;
if (!found_first) {
first = last;
found_first = true;
}
}
last = now;
now = now->right;
}
else {
t.push(now);
// visit its left
now = now->left;
}
}
int temp = first->val;
first->val = last_ill_smaller_than_left->val;
last_ill_smaller_than_left->val = temp;
}
};

空间消耗是O(树的高度),也就是O(lgn)

O(1)空间复杂度的是一个叫做Morris 遍历的方法。

https://www.cnblogs.com/grandyang/p/4297300.html

A binary tree is threaded by making all right child pointers that would normally be null point to the inorder successor of the node (if it exists), and all left child pointers that would normally be null point to the inorder predecessor of the node.

就是说螺纹二叉树实际上是把所有原本为空的右子节点指向了中序遍历顺序之后的那个节点,把所有原本为空的左子节点都指向了中序遍历之前的那个节点,具体例子可以点击这里。那么这道题跟这个螺纹二叉树又有啥关系呢?由于我们既不能用递归,又不能用栈,那我们如何保证访问顺序是中序遍历的左-根-右呢。原来我们需要构建一个螺纹二叉树,需要将所有为空的右子节点指向中序遍历的下一个节点,这样中序遍历完左子结点后,就能顺利的回到其根节点继续遍历了。

  1. 初始化指针 cur 指向 root
  2. 当 cur 不为空时
      - 如果 cur 没有左子结点
      a) 打印出 cur 的值
       b) 将 cur 指针指向其右子节点
      - 反之
      将 pre 指针指向 cur 的左子树中的最右子节点 
        * 若 pre 不存在右子节点
        a) 将其右子节点指回 cur
         b) cur 指向其左子节点
        * 反之
          a) 将 pre 的右子节点置空
          b) 打印 cur 的值
          c) 将 cur 指针指向其右子节点
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Solution {
public:
void recoverTree(TreeNode* root) {
TreeNode *first = nullptr, *second = nullptr, *cur = root, *pre = nullptr ;
while (cur) {
if (cur->left){
TreeNode *p = cur->left;
while (p->right && p->right != cur) p = p->right; // 左子树的最右节点
if (!p->right) {
p->right = cur;
cur = cur->left;
continue;
} else { // 【1】else的时候是p->right == cur
p->right = NULL;
}
}
if (pre && cur->val < pre->val){
if (!first) first = pre;
second = cur;
}
pre = cur;
cur = cur->right; // 所以后续会到【1】的位置,走到【1】的else里面
}
swap(first->val, second->val);
}
};

Oracle&django

在windows下安装了oracle,之后还需要下载64位的instantclient(https://download.oracle.com/otn_software/nt/instantclient/19300/instantclient-basic-windows.x64-19.3.0.0.0dbru.zip),解压后把这个的解压后的目录放在Path环境变量中。

11g对应的django只能是1.11以及之下!!!!!!!!!!!!cx_Oracle 7不行!!!!!!换6就可以了!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

之后要安装cx_Oracle库

oracle的sql的记录查看&oracle的创建用户:

1
2
3
4
5
6
7
8
9
10
select * from (select SQL_TEXT, FIRST_LOAD_TIME from v$sql order by FIRST_LOAD_TIME desc) where rownum<=10;


SQL> create user root IDENTIFIED BY root;

用户已创建。

SQL> grant connect, resource to root;

授权成功。

数据库database默认有一个orcl(最后一个是小写字母l,不是大写的I也不是1),可以通过select name from v$database;查看。

创建的用户默认就是这个数据库的,可以通过

1
2
3
4
5
6
7
8
SELECT 
a.TABLE_NAME,b.COMMENTS
FROM
user_tables a,user_tab_comments b
WHERE
a.TABLE_NAME=b.TABLE_NAME
ORDER BY
TABLE_NAME

查看所有的表。

之后可以drop table xxx来删除表,但是数据库不能这么删除。

cx_oracle版本问题导致:
···
The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “manage.py”, line 22, in
execute_from_command_line(sys.argv)
File “G:\django_test_oracle\venv\lib\site-packages\django\core\management_init_.py”, line 364, in execute_from_command_line
utility.execute()
File “G:\django_test_oracle\venv\lib\site-packages\django\core\management_init_.py”, line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File “G:\django_test_oracle\venv\lib\site-packages\django\core\management\base.py”, line 283, in run_from_argv
self.execute(*args, **cmd_options)
File “G:\django_test_oracle\venv\lib\site-packages\django\core\management\base.py”, line 330, in execute
output = self.handle(*args, **options)
File “G:\django_test_oracle\venv\lib\site-packages\django\core\management\commands\migrate.py”, line 204, in handle
fake_initial=fake_initial,
File “G:\django_test_oracle\venv\lib\site-packages\django\db\migrations\executor.py”, line 115, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File “G:\django_test_oracle\venv\lib\site-packages\django\db\migrations\executor.py”, line 145, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File “G:\django_test_oracle\venv\lib\site-packages\django\db\migrations\executor.py”, line 244, in apply_migration
state = migration.apply(state, schema_editor)
File “G:\django_test_oracle\venv\lib\site-packages\django\db\migrations\migration.py”, line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File “G:\django_test_oracle\venv\lib\site-packages\django\db\migrations\operations\models.py”, line 97, in database_forwards
schema_editor.create_model(model)
File “G:\django_test_oracle\venv\lib\site-packages\django\db\backends\base\schema.py”, line 319, in create_model
self.execute(sql, params or None)
File “G:\django_test_oracle\venv\lib\site-packages\django\db\backends\base\schema.py”, line 136, in execute
cursor.execute(sql, params)
File “G:\django_test_oracle\venv\lib\site-packages\django\db\backends\utils.py”, line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File “G:\django_test_oracle\venv\lib\site-packages\django\db\backends\utils.py”, line 64, in execute
return self.cursor.execute(sql, params)
File “G:\django_test_oracle\venv\lib\site-packages\django\db\utils.py”, line 94, in exit
six.reraise(dj_exc_type, dj_exc_value, traceback)
File “G:\django_test_oracle\venv\lib\site-packages\django\utils\six.py”, line 685, in reraise
raise value.with_traceback(tb)
File “G:\django_test_oracle\venv\lib\site-packages\django\db\backends\utils.py”, line 62, in execute
return self.cursor.execute(sql)
File “G:\django_test_oracle\venv\lib\site-packages\django\db\backends\oracle\base.py”, line 497, in execute
return self.cursor.execute(query, self._param_generator(params))
django.db.utils.DatabaseError: ORA-00955: name is already used by an existing object
···