TinaCristal's Blog


  • Home

  • Tags

  • Categories

  • Archives

  • Search

201604-3路径解析

Posted on 2018-12-09 | In ccf认证

问题描述
  在操作系统中,数据通常以文件的形式存储在文件系统中。文件系统一般采用层次化的组织形式,由目录(或者文件夹)和文件构成,形成一棵树的形状。文件有内容,用于存储数据。目录是容器,可包含文件或其他目录。同一个目录下的所有文件和目录的名字各不相同,不同目录下可以有名字相同的文件或目录。
  为了指定文件系统中的某个文件,需要用路径来定位。在类 Unix 系统(Linux、Max OS X、FreeBSD等)中,路径由若干部分构成,每个部分是一个目录或者文件的名字,相邻两个部分之间用 / 符号分隔。
  有一个特殊的目录被称为根目录,是整个文件系统形成的这棵树的根节点,用一个单独的 / 符号表示。在操作系统中,有当前目录的概念,表示用户目前正在工作的目录。根据出发点可以把路径分为两类:
  Ÿ 绝对路径:以 / 符号开头,表示从根目录开始构建的路径。
  Ÿ 相对路径:不以 / 符号开头,表示从当前目录开始构建的路径。

  例如,有一个文件系统的结构如下图所示。在这个文件系统中,有根目录 / 和其他普通目录 d1、d2、d3、d4,以及文件 f1、f2、f3、f1、f4。其中,两个 f1 是同名文件,但在不同的目录下。

Read more »

c++ string rfind find函数

Posted on 2018-12-09 | In c++

1)size_t find (const string& str, size_t pos = 0) const; //查找对象–string类对象
(2)size_t find (const char s, size_t pos = 0) const; //查找对象–字符串

Read more »

POJ3751 时间日期格式转换

Posted on 2018-12-09 | In poj

Description

世界各地有多种格式来表示日期和时间。对于日期的常用格式,在中国常采用格式的是“年年年年/月月/日日”或写为英语缩略表示的”yyyy/mm/dd”,此次编程大赛的启动日期“2009/11/07”就是符合这种格式的一个日期,而北美所用的日期格式则为“月月/日日/年年年年”或”mm/dd/yyyy”,如将“2009/11/07”改成这种格式,对应的则是”11/07/2009”。对于时间的格式,则常有12小时制和24小时制的表示方法,24小时制用0-24来表示一天中的24小时,而12小时制只采用1-12表示小时,再加上am/pm来表示上午或下午,比如”17:30:00”是采用24小时制来表示时间,而对应的12小时制的表示方法是”05:30:00pm”。注意12:00:00pm表示中午12点,而12:00:00am表示凌晨12点。

Read more »

leetcode 802. Find Eventual Safe States

Posted on 2018-12-08 | In leetcode , dfs

In a directed graph, we start at some node and every turn, walk along a directed edge of the graph. If we reach a node that is terminal (that is, it has no outgoing directed edges), we stop.

Now, say our starting node is eventually safe if and only if we must eventually walk to a terminal node. More specifically, there exists a natural number K so that for any choice of where to walk, we must have stopped at a terminal node in less than K steps.

Which nodes are eventually safe? Return them as an array in sorted order.

The directed graph has N nodes with labels 0, 1, …, N-1, where N is the length of graph. The graph is given in the following form: graph[i] is a list of labels j such that (i, j) is a directed edge of the graph.

Example:
Input: graph = [[1,2],[2,3],[5],[0],[5],[],[]]

Output: [2,4,5,6]

Here is a diagram of the above graph.

Illustration of graph

Note:

graph will have length at most 10000.

The number of edges in the graph will not exceed 32000.

Each graph[i] will be a sorted list of different integers, chosen within the range [0, graph.length - 1].

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


class Solution {
public:
vector<vector<int> >g;

vector<int> eventualSafeNodes(vector<vector<int>>& graph) {
int vis[10000]={0};
int m=graph.size();
g=vector<vector<int>>(m);//!!
for(int i=0;i<graph.size();i++){
for(int j=0;j<graph[i].size();j++){
g[i].push_back(graph[i][j]);
}

}
vector<int> s;
for(int i=0;i<graph.size();i++){
if(vis[i]==3) s.push_back(i);
else if(dfs(i,vis)==3) s.push_back(i);
}
return s;

}
//0:unknown 1:visiting 2:unsafe 3:safe
int dfs(int cur,int vis[]){
if(vis[cur]==1) return vis[cur]=2;
if(vis[cur]!=0) return vis[cur];
vis[cur]=1;

for(int i=0;i<g[cur].size();i++){
if(dfs(g[cur][i],vis)==2) {
// cout<<"huan:"<<cur<<" "<<g[cur][i]<<endl;
return vis[cur]=2;
}
// cout<<cur<<" "<<g[cur][i]<<endl;
}
return vis[cur]=3;
}

};

leetcode 827. Making A Large Island

Posted on 2018-12-08 | In leetcode , dfs

In a 2D grid of 0s and 1s, we change at most one 0 to a 1.

After, what is the size of the largest island? (An island is a 4-directionally connected group of 1s).

Example 1:

Read more »

leetcode 329. Longest Increasing Path in a Matrix

Posted on 2018-12-08 | In leetcode , dfs

Given an integer matrix, find the length of the longest increasing path.

From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside of the boundary (i.e. wrap-around is not allowed).

Read more »

leetcode 743. Network Delay Time

Posted on 2018-12-08 | In leetcode , dij

There are N network nodes, labelled 1 to N.

Given times, a list of travel times as directed edges times[i] = (u, v, w), where u is the source node, v is the target node, and w is the time it takes for a signal to travel from source to target.

Read more »

201803-2 碰撞的小球

Posted on 2018-12-07 | In ccf认证

数轴上有一条长度为L(L为偶数)的线段,左端点在原点,右端点在坐标L处。有n个不计体积的小球在线段上,开始时所有的小球都处在偶数坐标上,速度方向向右,速度大小为1单位长度每秒。

当小球到达线段的端点(左端点或右端点)的时候,会立即向相反的方向移动,速度大小仍然为原来大小。

当两个小球撞到一起的时候,两个小球会分别向与自己原来移动的方向相反的方向,以原来的速度大小继续移动。

现在,告诉你线段的长度L,小球数量n,以及n个小球的初始位置,请你计算t秒之后,各个小球的位置。
提示

因为所有小球的初始位置都为偶数,而且线段的长度为偶数,可以证明,不会有三个小球同时相撞,小球到达线段端点以及小球之间的碰撞时刻均为整数。

同时也可以证明两个小球发生碰撞的位置一定是整数(但不一定是偶数)。

输入格式

Read more »

leetcode 847. Shortest Path Visiting All Nodes

Posted on 2018-12-07 | In leetcode , bfs

An undirected, connected graph of N nodes (labeled 0, 1, 2, …, N-1) is given as graph.

graph.length = N, and j != i is in the list graph[i] exactly once, if and only if nodes i and j are connected.

Return the length of the shortest path that visits every node. You may start and stop at any node, you may revisit nodes multiple times, and you may reuse edges.

Read more »

leetcode 841. Keys and Rooms

Posted on 2018-12-07 | In leetcode , dfs

There are N rooms and you start in room 0. Each room has a distinct number in 0, 1, 2, …, N-1, and each room may have some keys to access the next room.

Formally, each room i has a list of keys rooms[i], and each key rooms[i][j] is an integer in [0, 1, …, N-1] where N = rooms.length. A key rooms[i][j] = v opens the room with number v.

Read more »

1…161718…45

TinaCristal

443 posts
57 categories
55 tags
GitHub E-Mail
© 2020 TinaCristal
Powered by Hexo
|
Theme — NexT.Mist v5.1.4