docker pull mysql:5.7

docker run --name ContainerName -p 13307:3306 -v /home/mjh/mysqls/1/datadir:/var/lib/mysql -v /home/mjh/mysqls/1/home:/home -e MYSQL_ROOT_PASSWORD=MyRootPassword -d mysql:5.7

// 方法一:
SELECT USER,SUBSTRING_INDEX(HOST,':',1) AS IP,COUNT(1) AS Total FROM INFORMATION_SCHEMA.PROCESSLIST GROUP BY IP ORDER BY Total DESC;

// 方法二:
SELECT substring_index(host, ':',1) AS host_name,state,count(*) FROM information_schema.processlist GROUP BY state,host_name;

除了将bitmap转化为int之类的,还可以直接用string.

同时可以用unordered_map<string,bool>记录状态是否访问过。

同时注意string的一个char的范围不只是0、1,因此还可以用来计数之类的

  1. maven换镜像、换中央仓库

vim ~/.m2/settings.xml

 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                          https://maven.apache.org/xsd/settings-1.0.0.xsd">
      <mirrors>
        <mirror>
		<id>alimaven</id>
		<name>aliyun maven</name>
		<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
		<mirrorOf>central</mirrorOf>
	</mirror>
      </mirrors>
      <repositories>
        <repository>

        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        </repository>
      </repositories>
    </settings>

或者:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository/>
  <interactiveMode/>
  <usePluginRegistry/>
  <offline/>
  <pluginGroups/>
  <servers/>
  <mirrors>
    <mirror>
     <id>aliyunmaven</id>
     <mirrorOf>central</mirrorOf>
     <name>阿里云公共仓库</name>
     <url>https://maven.aliyun.com/repository/central</url>
    </mirror>
    <mirror>
      <id>repo1</id>
      <mirrorOf>central</mirrorOf>
      <name>central repo</name>
      <url>http://repo1.maven.org/maven2/</url>
    </mirror>
    <mirror>
     <id>aliyunmaven</id>
     <mirrorOf>apache snapshots</mirrorOf>
     <name>阿里云阿帕奇仓库</name>
     <url>https://maven.aliyun.com/repository/apache-snapshots</url>
    </mirror>
  </mirrors>
  <proxies/>
  <activeProfiles/>
  <profiles>
    <profile>  
        <repositories>
           <repository>
                <id>aliyunmaven</id>
                <name>aliyunmaven</name>
                <url>https://maven.aliyun.com/repository/public</url>
                <layout>default</layout>
                <releases>
                        <enabled>true</enabled>
                </releases>
                <snapshots>
                        <enabled>true</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>MavenCentral</id>
                <url>http://repo1.maven.org/maven2/</url>
            </repository>
            <repository>
                <id>aliyunmavenApache</id>
                <url>https://maven.aliyun.com/repository/apache-snapshots</url>
            </repository>
        </repositories>             
     </profile>
  </profiles>
</settings>

2. docker换源

vim /etc/docker/daemon.json 

{
  "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn", "http://hub-mirror.c.163.com","https://registry.docker-cn.com"]
}

3. gradle换源

nano ~/.gradle/init.gradle

allprojects{
    repositories {
        def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/public/'
        def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter/'
        def ALIYUN_GOOGLE_URL = 'https://maven.aliyun.com/repository/google/'
        def ALIYUN_GRADLE_PLUGIN_URL = 'https://maven.aliyun.com/repository/gradle-plugin/'
        all { ArtifactRepository repo ->
            if(repo instanceof MavenArtifactRepository){
                def url = repo.url.toString()
                if (url.startsWith('https://repo1.maven.org/maven2/')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
                    remove repo
                }
                if (url.startsWith('https://jcenter.bintray.com/')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
                    remove repo
                }
                if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GOOGLE_URL."
                    remove repo
                }
                if (url.startsWith('https://plugins.gradle.org/m2/')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GRADLE_PLUGIN_URL."
                    remove repo
                }
            }
        }
        maven { url ALIYUN_REPOSITORY_URL }
        maven { url ALIYUN_JCENTER_URL }
        maven { url ALIYUN_GOOGLE_URL }
        maven { url ALIYUN_GRADLE_PLUGIN_URL }
    }
}

auto it = hand.begin();
while (true) {
// 假设序列x,y。it指向x
// 这个y可能是list的end

// 备份 值
int bak_val = *it;
// 移除当前it所指,执行完后it指向y。执行完后序列变成y
hand.erase(it++);


// 之前备份的值 被插到y之前,执行完后序列变成了x,y。it指向y
hand.insert(it, bak_val);

// 若y是end,则该退出了
bool bre = false;
if (it == hand.end()) {
bre = true;
}
if (bre) {
break;
}
}

  1. 记录 已经搜索过的节点 的结果值。当下次访问到这个节点时,直接返回。
  2. 将当前已经进行过的步骤,与 已经计算出来的、可能不是最优解的 结果 进行对比,以便剪枝。
  3. 将节点排好序,以便2.能够发挥更好的剪枝效果

dfs可以分两种,一种自上而下的将结果传递给下层,如采用already_count之类的.

第二种则是像这样:dfs()返回整个问题的答案,而一个问题可以分解为多个子问题。如果可以这样,那么这样更好,因为感觉像这样dfs更容易缕清思路。

dfs时注意记忆化。

dfs时,一种更好的实践是在父节点要向下递归时,不判断子节点是否为空。而是在访问当前节点时,判断是否为空。这种将事情推给子节点自己去判断 比较思路清晰。

dfs时超时,可考虑将原先的数据排序,看能否加快

最近继续做bfs tag的题,有了一些新的思索。

  1. 每次bfs的时候,我们总把新元素放到队列后面。但其实我们常常遇到的这种情况 是另外一种情况的简化版,在那一种hard模式的版本中,队列是用的双端队列。
    1. 若新元素与当前相比 并没有实际的进展,则新元素被放到队首,反之放到队尾。这时,整个双端队列分为两级、分为两部分,前面的是同一级的,后面的下一级的。具体题型见lc1263 推箱子

2. 在bfs时,我们使用vis来标记某个元素是否曾经访问过。在一个图中,若这种遍历边 并 判断是否曾经访问过的行为就有很多时间开销了,那我们就可以采用list来记录某个节点的边们,并将访问过的边去掉,具体题目见lc1345 跳跃游戏IV。list相关代码如下:

        auto it = list.begin();
        while (it != list.end()) {
          int next_x = (*it);
          if (!vis[next_x]) {
            vis[next_x] = true;
            q.push(next_x);
            if (next_x == desi) {
              return step;
            }
            list.erase(it++);
          } else {
            it++;
          }
        }