Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f77fca7

Browse files
Added more stuff
1 parent ed86244 commit f77fca7

File tree

3 files changed

+195
-0
lines changed

3 files changed

+195
-0
lines changed

‎Graphs1/3cycle.cpp‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
int helper(int i, int** matrix, int n, int* visited, int & count){
2+
for(int j=1;j<n+1;j++){
3+
if(visited[j]==0 && matrix[i][j]==1){
4+
for(int k=1;k<n+1;k++){
5+
if(visited[k]==0 && matrix[j][k]==1 && matrix[k][i]==1){
6+
count++;
7+
// cout<<"i-"<<i<<endl;
8+
// cout<<"j-"<<j<<endl;
9+
// cout<<"k-"<<k<<endl;
10+
11+
//cout<<"Count-"<<count<<endl;
12+
}
13+
}
14+
}
15+
16+
}
17+
// cout<<"Count2-"<<count<<endl;
18+
return count/2;
19+
}
20+
int solve(int n,int m,vector<int>u,vector<int>v)
21+
{
22+
//Creating matrix
23+
int** matrix = new int*[n+1];
24+
25+
for(int i=0;i<=n;i++){
26+
matrix[i] = new int[n+1];
27+
28+
for(int j=0;j<=n;j++){
29+
matrix[i][j]=0;
30+
}
31+
32+
}
33+
34+
for(int i=0;i<m;i++){
35+
matrix[u.at(i)][v.at(i)]=1;
36+
matrix[v.at(i)][u.at(i)]=1;
37+
// cout<<"U-"<<u[i]<<endl;
38+
// cout<<"V-"<<v[i]<<endl;
39+
40+
41+
}
42+
//Make visisted matrix
43+
int* visited = new int[n+1];
44+
45+
for(int i=0;i<n+1;i++){
46+
visited[i] = 0;
47+
}
48+
49+
//Look for cycle in each element
50+
int sum=0;
51+
for(int i = 1; i<=n; i++){
52+
visited[i]=1;
53+
int count=0;
54+
sum=sum+helper(i,matrix, n,visited, count);
55+
}
56+
57+
return sum;
58+
}

‎Graphs1/Board.cpp‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
3+
Name: Mehul Chaturvedi
4+
IIT-Guwahati
5+
6+
*/
7+
/*
8+
Gary has a board of size NxM. Each cell in the board is a coloured dot. There exist only 26 colours denoted by uppercase Latin characters (i.e. A,B,...,Z). Now Gary is getting bore and wants to play a game. The key of this game is to find a cycle that contain dots of same colour. Formally, we call a sequence of dots d1, d2, ..., dk a cycle if and only if it meets the following condition:
9+
1. These k dots are different: if i ≠ j then di is different from dj.
10+
2. k is at least 4.
11+
3. All dots belong to the same colour.
12+
4. For all 1 ≤ i ≤ k - 1: di and di + 1 are adjacent. Also, dk and d1 should also be adjacent. Cells x and y are called adjacent if they share an edge.
13+
Since Gary is colour blind, he wants your help. Your task is to determine if there exists a cycle on the board.
14+
Assume input to be 0-indexed based.
15+
Input Format :
16+
Line 1 : Two integers N and M, the number of rows and columns of the board
17+
Next N lines : a string consisting of M characters, expressing colors of dots in each line. Each character is an uppercase Latin letter.
18+
Output Format :
19+
Return 1 if there is a cycle else return 0
20+
Constraints :
21+
2 ≤ N, M ≤ 50
22+
Sample Input :
23+
3 4
24+
AAAA
25+
ABCA
26+
AAAA
27+
Sample Output :
28+
1
29+
*/
30+
31+
32+
#include <bits/stdc++.h>
33+
#define MAXN 51
34+
35+
using namespace std;
36+
37+
int helper(char board[][MAXN], int n, int m, int* visited){
38+
for (int i = 0; i < n; ++i)
39+
{
40+
for (int j = 0; j < m; ++j)
41+
{
42+
if ()
43+
{
44+
/* code */
45+
}
46+
}
47+
}
48+
}
49+
int solve(char board[][MAXN],int n, int m)
50+
{
51+
int* visited = new int[n]();
52+
53+
return helper(board, n, m, visited);
54+
}
55+
56+
int main( int argc , char ** argv )
57+
{
58+
ios_base::sync_with_stdio(false) ;
59+
cin.tie(NULL) ;
60+
61+
int N,M,i;
62+
char board[MAXN][MAXN];
63+
cin>>N>>M;
64+
for(i = 0;i < N; i++){
65+
cin>>board[i];
66+
}
67+
cout<<solve(board,N,M)<<endl;
68+
}

‎Graphs1/largestpiece.cpp‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
#include<iostream>
5+
#include<vector>
6+
7+
8+
static int rowNbr[] = {-1, 1, 0, 0};
9+
static int colNbr[] = {0, 0, 1, -1};
10+
11+
12+
//To check if the index is an eligible index for our cake
13+
bool iseligible(char cake[][55], int x, int y, int** visited, int n)
14+
{
15+
// if(x == 0 && y == 4)
16+
// cout << "Chirag" << endl;
17+
//cout << x << " " << y << endl;
18+
if(x<0 || x>=n || y<0 || y>=n|| visited[x][y] == 1 || cake[x][y] == '0' ){
19+
return 0;
20+
}
21+
else
22+
return 1;
23+
}
24+
25+
//Returns the maximum peice of cake that can be taken starting from x,y
26+
int solver(int n, char cake[][55], int** visited, int x, int y){
27+
int sum=0;
28+
29+
for(int k=0;k<4;k++){
30+
if(iseligible(cake,x+rowNbr[k], y+colNbr[k], visited, n)){
31+
32+
visited[x+rowNbr[k]][y+colNbr[k]]=1;
33+
sum=sum+solver(n, cake, visited, x+rowNbr[k], y+colNbr[k]);
34+
}
35+
}
36+
return 1+sum;
37+
}
38+
39+
40+
//passes index of each one to solver as starting point and returns max of all
41+
int solve(int n,char cake[][55])
42+
{
43+
int** visited = new int*[n];
44+
for(int i=0;i<n;i++){
45+
visited[i]=new int[n];
46+
for(int j=0;j<n; j++){
47+
visited[i][j]=0;
48+
}
49+
}
50+
51+
int count=-999999;
52+
int result=0;
53+
for(int i=0;i<n;i++){
54+
55+
for(int j=0;j<n;j++){
56+
57+
if(iseligible(cake, i, j, visited, n)){
58+
59+
//cout << i << " " << j << endl;
60+
visited[i][j]=1;
61+
result = solver(n, cake, visited, i, j);
62+
63+
count = max(result, count);
64+
}
65+
}
66+
}
67+
68+
return count;
69+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /