virtualbox上使用linux server版才是最佳实践。速度快、无bug。

当然,这样做的话,virtualbox里面是非常不方便复制粘贴的,因此ssh连接virtualbox里的linux server, 连接里的是通过路由转发实现ssh的。但其实可以直接把网络设置成为桥接模式,效果相当于多了台设备连接路由器、进入内网

接着再在Clion等的toolchain里设置remote host, 不要太爽

另外clion还可以直接打开remote的文件、文件夹

Access a remote server
Open the Remote Host tool window by choosing Tools | Deployment | Browse Remote Host from the main menu.
Select the required deployment server from the list. The tool window shows a tree view of files and folders under the server root. If no relevant server is available in the list, click.

uiautomator dump可能会提示ERROR: null root node returned by UiTestAutomationBridge.

解决方案是写个循环多试几(十)次

函数的csdn博客教程

函数示例:

DELIMITER $$
create function periodtos(kini int)
returns varchar(30)
no sql
deterministic
begin
	declare mout varchar(30);
	case kini
		when 1 then
			set mout='上午';
		when 2 then
			set mout='下午';
		else
			set mout='未知';
	end case;
	return mout;
end$$
DELIMITER ;

函数说明1:

  • When you create a stored function, you must declare either that it is deterministic or that it does not modify data. Otherwise, it may be unsafe for data recovery or replication.
  • By default, for a CREATE FUNCTION statement to be accepted, at least one of DETERMINISTIC, NO SQL, or READS SQL DATA must be specified explicitly. Otherwise an error occurs

函数说明2:

DETERMINISTIC A routine is considered “deterministic” if it always produces the same result for the same input parameters and NOT DETERMINISTIC otherwise. This is mostly used with string or math processing, but not limited to that.

NOT DETERMINISTIC Opposite of “DETERMINISTIC”. “If neither DETERMINISTIC nor NOT DETERMINISTIC is given in the routine definition, the default is NOT DETERMINISTIC. To declare that a function is deterministic, you must specify DETERMINISTIC explicitly.“. So it seems that if no statement is made, MySQl will treat the function as “NOT DETERMINISTIC”. This statement from manual is in contradiction with other statement from another area of manual which tells that: ” When you create a stored function, you must declare either that it is deterministic or that it does not modify data. Otherwise, it may be unsafe for data recovery or replication. By default, for a CREATE FUNCTION statement to be accepted, at least one of DETERMINISTIC, NO SQL, or READS SQL DATA must be specified explicitly. Otherwise an error occurs

I personally got error in MySQL 5.5 if there is no declaration, so i always put at least one declaration of “DETERMINISTIC”, “NOT DETERMINISTIC”, “NO SQL” or “READS SQL DATA” regardless other declarations i may have.

READS SQL DATA This explicitly tells to MySQL that the function will ONLY read data from databases, thus, it does not contain instructions that modify data, but it contains SQL instructions that read data (e.q. SELECT).

MODIFIES SQL DATA This indicates that the routine contains statements that may write data (for example, it contain UPDATE, INSERT, DELETE or ALTER instructions).

NO SQL This indicates that the routine contains no SQL statements.

CONTAINS SQL This indicates that the routine contains SQL instructions, but does not contain statements that read or write data. This is the default if none of these characteristics is given explicitly. Examples of such statements are SELECT NOW(), SELECT 10+@b, SET @x = 1 or DO RELEASE_LOCK(‘abc’), which execute but neither read nor write data.

Note that there are MySQL functions that are not deterministic safe, such as: NOW(), UUID(), etc, which are likely to produce different results on different machines, so a user function that contains such instructions must be declared as NOT DETERMINISTIC. Also, a function that reads data from an unreplicated schema is clearly NONDETERMINISTIC. *


其他:删除函数: drop function f1;

删除过程: drop procedure p1;

记录录路径:开一个pre数组,在每次松弛bai边的时候(就是在执行duif d[j]+cost[k]<d[i] then d[i]:=d[j]+cost[k]的时候),这时如果d[i]被更新了,就将pre[i]:=j,表示当前到zhii点的最短路dao径中,j是i的前驱结点。在做完spfa时,
对于结点i,不断地i:=pre[i]直到i=源点,这途中的点即为路径。

判断负权环:因为用了队列版维护d数组,如果i结点入队次数大于等于n次,则有负权权环

vis的目的其实并不是已经访问过哪些节点,而是记录【[在当前步骤] 或 [之前的步骤]】中已经访问过的状态。因为之前已经访问过了这些状态,而之前那些访问用的步骤更少,因此之后就没必要再次访问这些状态了。

当用bfs用于记录到达某个状态的步骤时,则若某个节点 【曾经访问过】或【通步骤的其他状态已经将这个节点加入队列】,则不用再将这个节点加入队列:

 while (!sourceq.empty()) {
      level_count = sourceq.size();
      while ((level_count--) > 0) {
        auto p = sourceq.front();
        sourceq.pop(); 
        for (int i=0; i<4; i++) {
          int subx = p.first + dx[i];
          int suby = p.second + dy[i];
          if (subx >= 0 && suby >= 0 && subx < m && suby < n) {
            if (A[subx][suby] == 1) {
              return step;
            } else if (A[subx][suby] == 0 && vis2[subx][suby] == 0){
              sourceq.push({subx,suby});
              vis2[subx][suby]=1;
            }
          }
        }
      }

或者:

while (!sourceq.empty()) {
      level_count = sourceq.size();
      while ((level_count--) > 0) {
        auto p = sourceq.front();
        sourceq.pop();
        if (vis2[p.first][p.second] == 1) {
          continue;
        }
        vis2[p.first][p.second] = 1;
        for (int i=0; i<4; i++) {
          int subx = p.first + dx[i];
          int suby = p.second + dy[i];
          if (subx >= 0 && suby >= 0 && subx < m && suby < n) {
            if (A[subx][suby] == 1) {
              return step;
            } else if (A[subx][suby] == 0){
              sourceq.push({subx,suby});
            }
          }
        }
      }
      step++;
    }

但不能这样:

 while (!sourceq.empty()) {
      level_count = sourceq.size();
      while ((level_count--) > 0) {
        auto p = sourceq.front();
        sourceq.pop();
        // 1:
        if (vis2[p.first][p.second] == 1) {
          continue;
        }
        vis2[p.first][p.second] = 1;
        for (int i=0; i<4; i++) {
          int subx = p.first + dx[i];
          int suby = p.second + dy[i];
          if (subx >= 0 && suby >= 0 && subx < m && suby < n) {
            if (A[subx][suby] == 1) {
              return step;
            } else if (A[subx][suby] == 0 && vis2[subx][suby] == 0){
              // 2:
              sourceq.push({subx,suby});
              vis2[subx][suby]=1;
            }
          }
        }
      }

这样做的话,因为2处已经将vis2[subx][suby]设置为1,则访问这个节点时,因为1处代码的存在,会直接跳过访问这个节点。

另外,若有多个起始状态的bfs出现了tle,可能的原因是:队列中的起始状态有重复的,不妨试试没有重复时可不可以度过难关。做leetcode::934::最短的桥时就因为这种原因tle了