-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
370,825 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
//#include<iostream> | ||
//#include<vector> | ||
//#include <list> | ||
//#include<string> | ||
//#include <stack> | ||
//#include<fstream> | ||
//#define INF INT_MAX | ||
//using namespace std; | ||
// | ||
//struct neighbor{ | ||
// int vnum;//vertex number | ||
// int weight; //edge weight | ||
//}; | ||
//struct graph{ | ||
// vector< list<neighbor> > edges; | ||
// vector<neighbor> vertices; | ||
//}; | ||
//int nodeCount; | ||
//vector<bool> visited; | ||
//graph G; | ||
//bool makeGraph(string fname){ | ||
// ifstream fin; | ||
// fin.open(fname); | ||
// bool start = true; | ||
// string str; | ||
// if (fin.is_open()){ | ||
// while (!fin.eof()){ | ||
// if (start) | ||
// { | ||
// getline(fin, str); | ||
// nodeCount = str[0] - '0'; | ||
// start = false; | ||
// } | ||
// else{ | ||
// getline(fin, str); | ||
// // cout << str<<endl; | ||
// int i = 2; | ||
// neighbor n; | ||
// n.weight = 1; | ||
// n.vnum = str[0] - '0'; | ||
// G.vertices.push_back(n); | ||
// bool v = false; | ||
// visited.push_back(v); | ||
// list<neighbor> neighborsList; | ||
// while (i < str.length()){ | ||
// if (str[i] != ' '){ | ||
// neighbor n1; | ||
// n1.weight = 1; | ||
// n1.vnum = str[i] - '0'; | ||
// // cout << "neightbours:" << n1.vnum; | ||
// neighborsList.push_back(n1); | ||
// } | ||
// i++; | ||
// } | ||
// // cout << endl; | ||
// G.edges.push_back(neighborsList); | ||
// } | ||
// } | ||
// fin.close(); | ||
// return true; | ||
// } | ||
// return false; | ||
//} | ||
//vector<int> dist; | ||
//vector<neighbor> parent; | ||
//stack<neighbor>s; | ||
//void explore(neighbor v){ | ||
// visited[v.vnum] = true; | ||
// for (list<neighbor>::iterator iter = G.edges[v.vnum].begin(); iter != G.edges[v.vnum].end(); iter++){ | ||
// if (!visited[iter->vnum]){ | ||
// explore(*iter); | ||
// } | ||
// } | ||
// int i = INF; | ||
// dist.push_back(i); | ||
// neighbor n; | ||
// parent.push_back(n); | ||
// s.push(v); | ||
// | ||
//} | ||
//void topologicalSort(){ | ||
// for (int i = 0; i < G.vertices.size(); i++){ | ||
// // cout << "DFS:"<<G.vertices[i].vnum; | ||
// if (!visited[i]){ | ||
// explore(G.vertices[i]); | ||
// } | ||
// } | ||
//} | ||
// | ||
//void shortestPathDAG(neighbor source, int m){ | ||
// topologicalSort(); | ||
// stack<neighbor>ss = s; | ||
// while (s.top().vnum != source.vnum){ | ||
// // cout << endl<<"n:"<<s.top().vnum; | ||
// int i = INF; | ||
// neighbor n; | ||
// n.vnum = -1; | ||
// dist[s.top().vnum] = i; | ||
// parent[s.top().vnum] = n; | ||
// s.pop(); | ||
// } | ||
// //s.pop(); //pop source | ||
// dist[source.vnum] = 0; | ||
// neighbor p; | ||
// p.vnum = -1; | ||
// parent[source.vnum] = p; | ||
// while (!s.empty()){ | ||
// neighbor n; | ||
// n = s.top(); | ||
// s.pop(); | ||
// for (list<neighbor>::iterator iter = G.edges[n.vnum].begin(); iter != G.edges[n.vnum].end(); iter++){ | ||
// if (dist[iter->vnum] > dist[n.vnum] + n.weight){ | ||
// dist[iter->vnum] = dist[n.vnum] + n.weight; | ||
// parent[iter->vnum] = n; | ||
// } | ||
// } | ||
// } | ||
// while (!ss.empty()){ | ||
// cout << endl << "distance of node " << ss.top().vnum << ":" << dist[ss.top().vnum] << " and parent = " << parent[ss.top().vnum].vnum; | ||
// ss.pop(); | ||
// } | ||
// cout << endl; | ||
//} | ||
//int main(){ | ||
// string filename = "graph.txt"; | ||
// // cout << filename << endl; | ||
// bool c = makeGraph(filename); | ||
// neighbor n; | ||
// n.vnum = 0; | ||
// if(c) | ||
// shortestPathDAG(n, 1); | ||
// system("Pause"); | ||
// return 0; | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
//#include<iostream> | ||
//#include<vector> | ||
//#include <list> | ||
//#include<string> | ||
//#include <stack> | ||
//#include<fstream> | ||
//#define INF INT_MAX | ||
//using namespace std; | ||
// | ||
//struct neighbor{ | ||
// int vnum;//vertex number | ||
// int weight; //edge weight | ||
//}; | ||
//struct graph{ | ||
// vector< list<neighbor> > edges; | ||
// vector<neighbor> vertices; | ||
//}; | ||
//int nodeCount; | ||
//vector<bool> visited; | ||
//graph G; | ||
//bool makeGraph(string fname){ | ||
// ifstream fin; | ||
// fin.open(fname); | ||
// bool start = true; | ||
// string str; | ||
// if (fin.is_open()){ | ||
// while (!fin.eof()){ | ||
// if (start) | ||
// { | ||
// getline(fin, str); | ||
// nodeCount = str[0] - '0'; | ||
// start = false; | ||
// } | ||
// else{ | ||
// getline(fin, str); | ||
// // cout << str<<endl; | ||
// int i = 2; | ||
// neighbor n; | ||
// n.weight = 1; | ||
// n.vnum = str[0] - '0'; | ||
// G.vertices.push_back(n); | ||
// bool v = false; | ||
// visited.push_back(v); | ||
// list<neighbor> neighborsList; | ||
// while (i < str.length()){ | ||
// if (str[i] != ' '){ | ||
// neighbor n1; | ||
// n1.weight = 1; | ||
// n1.vnum = str[i] - '0'; | ||
// // cout << "neightbours:" << n1.vnum; | ||
// neighborsList.push_back(n1); | ||
// } | ||
// i++; | ||
// } | ||
// // cout << endl; | ||
// G.edges.push_back(neighborsList); | ||
// } | ||
// } | ||
// fin.close(); | ||
// return true; | ||
// } | ||
// return false; | ||
//} | ||
//vector<int> dist; | ||
//vector<neighbor> parent; | ||
//stack<neighbor>s; | ||
//void explore(neighbor v){ | ||
// visited[v.vnum] = true; | ||
// for (list<neighbor>::iterator iter = G.edges[v.vnum].begin(); iter != G.edges[v.vnum].end(); iter++){ | ||
// if (!visited[iter->vnum]){ | ||
// explore(*iter); | ||
// } | ||
// } | ||
// int i = INF; | ||
// dist.push_back(i); | ||
// neighbor n; | ||
// parent.push_back(n); | ||
// s.push(v); | ||
// | ||
//} | ||
//void topologicalSort(){ | ||
// for (int i = 0; i < G.vertices.size(); i++){ | ||
// // cout << "DFS:"<<G.vertices[i].vnum; | ||
// if (!visited[i]){ | ||
// explore(G.vertices[i]); | ||
// } | ||
// } | ||
//} | ||
// | ||
//void shortestPathDAG(neighbor source, int m){ | ||
// topologicalSort(); | ||
// stack<neighbor>ss = s; | ||
// while (s.top().vnum != source.vnum){ | ||
// // cout << endl<<"n:"<<s.top().vnum; | ||
// int i = INF; | ||
// neighbor n; | ||
// n.vnum = -1; | ||
// dist[s.top().vnum] = i; | ||
// parent[s.top().vnum] = n; | ||
// s.pop(); | ||
// } | ||
// //s.pop(); //pop source | ||
// dist[source.vnum] = 0; | ||
// neighbor p; | ||
// p.vnum = -1; | ||
// parent[source.vnum] = p; | ||
// int i = 0; | ||
// while (!s.empty()){ | ||
// neighbor n; | ||
// n = s.top(); | ||
// s.pop(); | ||
// i++; | ||
// | ||
// for (list<neighbor>::iterator iter = G.edges[n.vnum].begin(); iter != G.edges[n.vnum].end(); iter++){ | ||
// if (i <= m){ | ||
// if (dist[iter->vnum] > dist[n.vnum] + n.weight){ | ||
// dist[iter->vnum] = dist[n.vnum] + n.weight; | ||
// parent[iter->vnum] = n; | ||
// } | ||
// } | ||
// } | ||
// } | ||
// while (!ss.empty()){ | ||
// if (dist[ss.top().vnum]!=INF) | ||
// cout << endl << "distance of node " << ss.top().vnum << ":" << dist[ss.top().vnum] << " and parent = " << parent[ss.top().vnum].vnum; | ||
// else | ||
// cout << endl << "distance of node " << ss.top().vnum << ": Infinity"; | ||
// ss.pop(); | ||
// } | ||
// cout << endl; | ||
//} | ||
//int main(){ | ||
// string filename = "graph.txt"; | ||
// // cout << filename << endl; | ||
// bool c = makeGraph(filename); | ||
// neighbor n; | ||
// n.vnum = 0; | ||
// if(c) | ||
// shortestPathDAG(n, 2); | ||
// system("Pause"); | ||
// return 0; | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//#include<iostream> | ||
//using namespace std; | ||
// | ||
//int matFloor(int k){ | ||
// int prev1 = 1, prev2 = 2; // for vertical case(2x1) and 2x2 case (2 horizontal or 2 vertical) | ||
// int val = 0; | ||
// if (k == 1) | ||
// return prev1; | ||
// else if (k == 2) | ||
// return prev2; | ||
// else{ | ||
// for (int i = 3; i <= k; i++){ | ||
// val = prev1 + prev2; | ||
// prev1 = prev2; | ||
// prev2 = val; | ||
// } | ||
// return val; | ||
// } | ||
//} | ||
// | ||
//int main(){ | ||
// int k = -1; | ||
// cout << "Enter value of k: "; | ||
// cin >> k; | ||
// cout << "Ther are " << matFloor(k) << " posssible ways to mat a 2x" << k << " floor"<<endl; | ||
// system("Pause"); | ||
// return 0; | ||
//} |
Oops, something went wrong.