-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
ef36cab
commit 436e6a3
Showing
4 changed files
with
76 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,44 @@ | ||
//{ Driver Code Starts | ||
// Initial Template for Java | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
class GFG { | ||
public static void main(String args[]) throws IOException { | ||
BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); | ||
int t = Integer.parseInt(read.readLine()); | ||
while (t-- > 0) { | ||
int N = Integer.parseInt(read.readLine()); | ||
Solution ob = new Solution(); | ||
int ans = ob.rectanglesInCircle(N); | ||
System.out.println(ans); | ||
} | ||
} | ||
} | ||
// } Driver Code Ends | ||
|
||
|
||
// User function Template for Java | ||
|
||
class Solution { | ||
int rectanglesInCircle(int r) { | ||
// code here | ||
double d = r*2; | ||
int cnt = 0; | ||
double area = 3.14*r*r; | ||
for(int i=1; i<=d; i++) | ||
{ | ||
for(int j=1; j<=d; j++) | ||
{ | ||
double temp = i*j; | ||
double dia = Math.sqrt(i*i+j*j); | ||
|
||
if (temp<=area && d>=dia) | ||
cnt++; | ||
} | ||
} | ||
|
||
return cnt; | ||
} | ||
}; |
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,2 @@ | ||
Time complexity - O(n^2) | ||
Space complexity - O(1) |
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,2 @@ | ||
Time complexity - O(n) | ||
Space complexity - O(n) |
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 @@ | ||
class Solution | ||
{ | ||
public int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) | ||
{ | ||
int maxDifficulty = 0; | ||
for (int d : difficulty) | ||
maxDifficulty = Math.max(maxDifficulty, d); | ||
|
||
int[] maxProfitUpToDifficulty = new int[maxDifficulty + 1]; | ||
for (int i = 0; i < difficulty.length; i++) | ||
maxProfitUpToDifficulty[difficulty[i]] = Math.max(maxProfitUpToDifficulty[difficulty[i]], profit[i]); | ||
|
||
for (int i = 1; i <= maxDifficulty; i++) | ||
maxProfitUpToDifficulty[i] = Math.max(maxProfitUpToDifficulty[i], maxProfitUpToDifficulty[i - 1]); | ||
|
||
int totalProfit = 0; | ||
for (int ability : worker) | ||
{ | ||
if (ability > maxDifficulty) | ||
totalProfit += maxProfitUpToDifficulty[maxDifficulty]; | ||
else | ||
totalProfit += maxProfitUpToDifficulty[ability]; | ||
} | ||
|
||
return totalProfit; | ||
} | ||
|
||
} |