Skip to content

Commit 16a6c5b

Browse files
Merge branch 'smv1999:master' into master
2 parents 0c2bc16 + 416642d commit 16a6c5b

File tree

18 files changed

+1056
-76
lines changed

18 files changed

+1056
-76
lines changed

Arrays/leap.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* Title : Check whether the year entered is leap or not .
2+
If the entered year passes the conditions then it is considered to be as leap
3+
otherwise not .
4+
5+
*/
6+
import java.util.Scanner ;
7+
class leap
8+
{ int leap_year;
9+
10+
leap (int a) // Constructor
11+
{
12+
leap_year=a;
13+
}
14+
void check ()
15+
{
16+
if(leap_year%4==0)
17+
18+
{
19+
if(leap_year%100==0)
20+
{
21+
if(leap_year%400==0)
22+
{ System.out.println( " Leap year .");
23+
System.out.println( " \n 366 days in " +leap_year+ " year . \n 29 days in month of Feb . \n"); }
24+
else
25+
{
26+
System.out.println( " Not Leap year "); }
27+
}
28+
else
29+
{ System.out.println( " Leap year .");
30+
System.out.println( " \n 366 days in " + leap_year+ " year . \n 29 days in month of Feb . \n");}
31+
}
32+
33+
else
34+
{ System.out.println( " Not Leap year "); }
35+
36+
}
37+
38+
public static void main (String[] args)
39+
{
40+
int year ;
41+
Scanner in=new Scanner(System.in);
42+
year=in.nextInt();
43+
leap Y = new leap(year);
44+
Y.check();
45+
46+
}
47+
}
48+
/*
49+
1900
50+
Not Leap year .
51+
52+
2000
53+
Leap year .
54+
55+
366 days in year 2000 .
56+
29 days in month of Feb .
57+
58+
*/

Codechef Problems/MaximumArrayXOR.java

Lines changed: 0 additions & 76 deletions
This file was deleted.

Codechef Problems/TheLeadGame.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
The game of billiards involves two players knocking 3 balls around on a green baize table. Well, there is more to it, but for our purposes this is sufficient.
3+
4+
The game consists of several rounds and in each round both players obtain a score, based on how well they played. Once all the rounds have been played, the total score of each player is determined by adding up the scores in all the rounds and the player with the higher total score is declared the winner.
5+
6+
The Siruseri Sports Club organises an annual billiards game where the top two players of Siruseri play against each other. The Manager of Siruseri Sports Club decided to add his own twist to the game by changing the rules for determining the winner. In his version, at the end of each round, the cumulative score for each player is calculated, and the leader and her current lead are found. Once all the rounds are over the player who had the maximum lead at the end of any round in the game is declared the winner.
7+
8+
Consider the following score sheet for a game with 5 rounds:
9+
10+
Round Player 1 Player 2
11+
1 140 82
12+
2 89 134
13+
3 90 110
14+
4 112 106
15+
5 88 90
16+
The total scores of both players, the leader and the lead after each round for this game is given below:
17+
18+
Round Player 1 Player 2 Leader Lead
19+
1 140 82 Player 1 58
20+
2 229 216 Player 1 13
21+
3 319 326 Player 2 7
22+
4 431 432 Player 2 1
23+
5 519 522 Player 2 3
24+
Note that the above table contains the cumulative scores.
25+
26+
The winner of this game is Player 1 as he had the maximum lead (58 at the end of round 1) during the game.
27+
28+
Your task is to help the Manager find the winner and the winning lead. You may assume that the scores will be such that there will always be a single winner. That is, there are no ties.
29+
30+
Input
31+
The first line of the input will contain a single integer N (N ≤ 10000) indicating the number of rounds in the game. Lines 2,3,...,N+1 describe the scores of the two players in the N rounds. Line i+1 contains two integer Si and Ti, the scores of the Player 1 and 2 respectively, in round i. You may assume that 1 ≤ Si ≤ 1000 and 1 ≤ Ti ≤ 1000.
32+
Output
33+
Your output must consist of a single line containing two integers W and L, where W is 1 or 2 and indicates the winner and L is the maximum lead attained by the winner.
34+
Example
35+
Input:
36+
5
37+
140 82
38+
89 134
39+
90 110
40+
112 106
41+
88 90
42+
Output:
43+
1 58
44+
*/
45+
#include <bits/stdc++.h>
46+
using namespace std;
47+
int main()
48+
{
49+
int n, lead=INT_MIN,p1=0,p2=0,winner=0;
50+
cin >> n;
51+
for (int i = 0; i < n; i++)
52+
{
53+
int a,b;
54+
cin>>a>>b;
55+
//Adding the scores of player1 and player2 so that we can store there cumulative score sum in p1 and p2
56+
p1+=a;
57+
p2+=b;
58+
//If the cumulative sum of p1 is greater than p2
59+
if(p1>p2){
60+
//and their difference is greater than lead than the winner will be player 1
61+
if(p1-p2>lead){
62+
lead=p1-p2;
63+
winner=1;
64+
}
65+
}
66+
67+
else{
68+
//if their difference is greater than lead than the winner will be player 2
69+
if(p2-p1>lead){
70+
lead=p2-p1;
71+
winner=2;
72+
}
73+
}
74+
}
75+
cout<<winner<<" "<<lead;
76+
return 0;
77+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
Implementation of Bridge edge in Graph problem
3+
4+
Problem statement:
5+
Given an undirected graph of V vertices and E edges and another edge (c-d), the task is to
6+
find if the given edge is a bridge in graph, i.e., removing the edge disconnects the graph.
7+
8+
Link to the problem: https://practice.geeksforgeeks.org/problems/bridge-edge-in-graph/1
9+
10+
*/
11+
12+
#include<bits/stdc++.h>
13+
using namespace std;
14+
15+
16+
class Solution
17+
{
18+
public:
19+
20+
void dfs( vector<int> adj[],vector<int>&v,int i)
21+
{
22+
//marking visited
23+
v[i]=1;
24+
25+
//traversing adjacent node
26+
for(auto x:adj[i])
27+
{
28+
if(!v[x])
29+
dfs(adj,v,x);
30+
31+
}
32+
33+
}
34+
35+
bool connected(vector<int>adj[],int n,int c,int d)
36+
{
37+
vector<int>v(n,0);
38+
39+
// dfs from edge c
40+
dfs(adj,v,c);
41+
42+
//if edge d is not visited means not connected
43+
if(v[d]==0)
44+
return false;
45+
46+
return true;
47+
48+
}
49+
50+
//Function to find if the given edge is a bridge in graph.
51+
int isBridge(int n, vector<int>adj[], int c, int d)
52+
{
53+
//if graph is not connected
54+
if(!connected(adj,n,c,d))
55+
return 0;
56+
57+
else
58+
{
59+
//removing edge c and d
60+
adj[c].erase(remove(adj[c].begin(), adj[c].end(), d), adj[c].end());
61+
adj[d].erase(remove(adj[d].begin(), adj[d].end(), c), adj[d].end());
62+
63+
//if connected means no bridge
64+
if(connected(adj,n,c,d))
65+
return 0;
66+
else
67+
return 1;
68+
}
69+
70+
}
71+
};
72+
73+
// Driver Code Starts
74+
int main()
75+
{
76+
int t;
77+
cin >> t;
78+
while (t--)
79+
{
80+
int V, E;
81+
cin >> V >> E;
82+
vector<int> adj[V];
83+
int i=0;
84+
while (i++<E)
85+
{
86+
int u, v;
87+
cin >> u >> v;
88+
adj[u].push_back (v);
89+
adj[v].push_back (u);
90+
}
91+
92+
int c,d;
93+
cin>>c>>d;
94+
95+
Solution obj;
96+
cout << obj.isBridge(V, adj, c, d) << "\n";
97+
}
98+
99+
return 0;
100+
}
101+
102+
103+
/*
104+
Time Complexity : O(V+E)
105+
Space Complexity : O(V)
106+
107+
Input:
108+
t=1
109+
V=4 E=3
110+
0 1
111+
1 2
112+
2 3
113+
c=1 d=2
114+
115+
Output: 1
116+
117+
Explanation:
118+
From the graph, we can clearly see that
119+
removing the edge 1-2 will result in
120+
disconnection of the graph. So, it is
121+
a bridge Edge and thus the Output 1.
122+
123+
*/

0 commit comments

Comments
 (0)