forked from satyajeetramnit/Placement-2023
-
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.
Merge pull request satyajeetramnit#3 from AnkitRajCode/main
Public Sapient, Verdis, Relevel (Fetch Movie API Update)
- Loading branch information
Showing
10 changed files
with
351 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,24 @@ | ||
def saleOrder(df): | ||
|
||
orders = {} | ||
for _, row in df.iterrows(): | ||
date = row['date_added'] | ||
sizes = [int(x) for x in input(row['sizes'].split('/'))] | ||
typ = row['type'] | ||
if typ == 'Received': | ||
if date not in orders.keyset(): | ||
orders[date] = sum(sizes) | ||
else: | ||
orders[date] += sum(sizes) | ||
else: | ||
if date not in orders.keyset(): | ||
orders[date] = -sum(sizes) | ||
else: | ||
orders[date] -= sum(sizes) | ||
|
||
for key in orders.keyset(): | ||
if orders[key] < 0: | ||
return 'Impossible' | ||
return 'Possible' | ||
|
||
#NOTE: all test case is not passed in it 2 left in readme alltest case passed code is put in the code section |
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,124 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define rep(i,a,b) for(int i=a;i<b;i++) | ||
#define pll pair<ll,ll> | ||
#define ppl pair<ll,pair<ll,ll>> | ||
#define mem1(a) memset(a,-1,sizeof(a)) | ||
#define mem0(a) memset(a,0,sizeof(a)) | ||
#define maxHeap(T) priority_queue <T> | ||
#define minHeap(T) priority_queue <T, vector<T>, greater<T>> | ||
#define fast ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); | ||
#define deb(x) cout<<#x<<" "<<x<<"\n" | ||
#define uid(l,r) uniform_int_distribution<int>(l,r); // to use auto temp= uid(l,r). int x= temp(rng); to generate from [L,R] | ||
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;} // only use in equations like sum=max(sum,x) its equivalent ot amax(sum,x) => sums is changed automatically | ||
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;} | ||
template<typename T> using pbds =tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; // *s.find_by_order(x)=> xth element on 0 based indexing , s.order_of_key(x) => no of elements strictly smaller | ||
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); | ||
//----------------------------------STRESS TESTING -------------------------------------- | ||
#ifdef krish_murarka | ||
#include "debug.hpp" | ||
#else | ||
#define debug(...) | ||
#define testcases(...) | ||
#endif | ||
void debugger(){ | ||
#ifdef krish_murarka | ||
freopen("error/errorA.txt", "w", stderr); | ||
#else | ||
#endif | ||
} | ||
|
||
// --------------------------------------TO TAKE INPUT -------------------------------------- | ||
void read_input() | ||
{ | ||
#ifdef krish_murarka | ||
freopen("input/inputA.txt","r",stdin); | ||
freopen("output/outputA.txt","w",stdout); | ||
freopen("error/errorA.txt","w",stderr); | ||
#endif | ||
|
||
} | ||
|
||
// --------------------------------------CODE STARTS ------------------------------------------ | ||
const int mod = 1e9+7; | ||
ll fact[100005]; | ||
void precompute() | ||
{ | ||
fact[0]=1; | ||
for(int i=1;i<1e5;i++){ | ||
fact[i]=(fact[i-1]*i%mod)%mod; | ||
// cout<<fact[i] | ||
} | ||
} | ||
|
||
void solving() | ||
{ | ||
|
||
int n; | ||
cin>>n; | ||
int m; | ||
cin>>m; | ||
//strign s; cin>>s; | ||
vector<ll> a(m,0); | ||
queue<int> q; | ||
vector<int> vis(n+1,0); | ||
precompute(); | ||
for(int i=0;i<m;i++){ | ||
cin>>a[i]; | ||
a[i]--; | ||
q.push(a[i]); | ||
vis[a[i]]=1; | ||
} | ||
ll ans=1; | ||
while(q.size()>0){ | ||
|
||
int count =0; | ||
|
||
int sz = q.size(); | ||
// cout<<sz<<"\n"; | ||
for(int i=0;i<sz;i++){ | ||
int p = q.front(); | ||
q.pop(); | ||
|
||
if((p+1)<n && !vis[p+1]){ | ||
q.push(p+1); | ||
vis[p+1]=1; | ||
count++; | ||
} | ||
if((p-1)>=0 && !vis[p-1]){ | ||
q.push(p-1); | ||
vis[p-1]=1; | ||
count++; | ||
} | ||
} | ||
// cout<<count<<" "<<fact[count]<<"\n"; | ||
ans = (ans *fact[count])%mod; | ||
|
||
} | ||
cout<<ans<<"\n"; | ||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
|
||
int main() | ||
{ | ||
fast; | ||
debugger(); | ||
// read_input(); | ||
int t=1; | ||
// cin>>t; | ||
for(int i=1;i<=t;i++) | ||
{ | ||
testcases("Case #",i); | ||
//cout<<"Case #"<<i<<": "; | ||
solving(); | ||
|
||
} | ||
|
||
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,31 @@ | ||
># Q1 | ||
<img src="https://imgur.com/sJZHRrO.png" /> | ||
<img src="https://imgur.com/VBCK4MV.png" /> | ||
<img src="https://imgur.com/xi1wIM9.png" /> | ||
|
||
<br/><br/> | ||
|
||
>## Solution :: 2 Test case not passed | ||
<img src="https://imgur.com/EW0ei5V.png" /> | ||
<img src="https://imgur.com/I2891ox.png" /> | ||
<br/><br/> | ||
|
||
>## Solution :: with all Test Case Pass | ||
<img src="https://imgur.com/ByDbGTS.png" /> | ||
<img src="https://imgur.com/XBYFGyw.png" /> | ||
<br/> | ||
|
||
># Q2 | ||
<img src="https://imgur.com/yyMlZYl.png" /> | ||
<img src="https://imgur.com/oWmvL5I.png" /> | ||
<img src="https://imgur.com/L5OnzzI.png" /> | ||
<img src="https://imgur.com/fYPe7Gi.png" /> | ||
<br/><br/> | ||
>## Solution | ||
<img src="https://imgur.com/mL6bmzI.png" /> | ||
<img src="https://imgur.com/mVlVx5Q.png" /> | ||
<img src="https://imgur.com/atdXFUz.png" /> |
Submodule Round 3 (Fetch Movie API)
added at
f3e95d
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,91 @@ | ||
import java.io.IOException; | ||
import java.util.Scanner; | ||
|
||
// This codes solves the puzzle WORD1 + WORD2 = WORD3 | ||
// The simpler version (SEND MORE MONEY) will require less code. | ||
|
||
public class SendMoreMoney { | ||
|
||
public static void main(String[] args) throws IOException { | ||
|
||
Scanner sc = new Scanner(System.in); | ||
String w1 = sc.next(); // SEND | ||
String w2 = sc.next(); // MORE | ||
String w3 = sc.next(); // MONEY | ||
|
||
solve(w1, w2, w3); | ||
} | ||
|
||
static void solve(String w1, String w2, String w3) // w1 + w2 = w3 | ||
{ | ||
usedLetter = new boolean[26]; // usedLetter[i] = true iff letter i appears in w1, w2 or w3 | ||
usedDigit = new boolean[26]; // usedDigit[i] = true iff digit i is used by a letter (used in backtracking) | ||
assignedDigit = new int[26]; // assignedDigiti[i] = digit assigned to letter i (used in backtracking) | ||
markLetters(w1); markLetters(w2); markLetters(w3); | ||
backtrack(0, w1, w2, w3); | ||
System.out.println("No more solutions :("); | ||
} | ||
|
||
static boolean[] usedLetter; | ||
static boolean[] usedDigit; | ||
static int[] assignedDigit; | ||
|
||
// mark the letters appeared in w1, w2 and w3 to use them in the search. | ||
static void markLetters(String w) | ||
{ | ||
for(int i = 0; i < w.length(); ++i) | ||
usedLetter[w.charAt(i) - 'A'] = true; | ||
} | ||
|
||
static boolean check(String w1, String w2, String w3) | ||
{ | ||
if(leadingZero(w1) || leadingZero(w2) || leadingZero(w3)) | ||
return false; | ||
return value(w1) + value(w2) == value(w3); | ||
} | ||
|
||
static boolean leadingZero(String w) { return assignedDigit[w.charAt(0) - 'A'] == 0; } | ||
|
||
// if w = ABCD, then the function returns A * 1000 + B * 100 + C * 10 + D. | ||
static int value(String w) | ||
{ | ||
int val = 0; | ||
for(int i = 0; i < w.length(); ++i) | ||
val = val * 10 + assignedDigit[w.charAt(i) - 'A']; | ||
return val; | ||
} | ||
|
||
// do the backtracking (brute force) | ||
static void backtrack(int char_idx, String w1, String w2, String w3) | ||
{ | ||
if(char_idx == 26) | ||
{ | ||
// finished assigning values for the 26 letters | ||
if(check(w1, w2, w3)) | ||
{ | ||
System.out.println("Found a solution!"); | ||
for(int i = 0; i < 26; ++i) | ||
if(usedLetter[i]) | ||
System.out.printf("[%c = %d]", (char)(i + 'A'), assignedDigit[i]); | ||
System.out.println("\n------"); | ||
} | ||
return; | ||
} | ||
|
||
if(!usedLetter[char_idx]) | ||
{ | ||
// skip this letter, it was not used in the input. | ||
backtrack(char_idx + 1, w1, w2, w3); | ||
return; | ||
} | ||
// try assigning different digits for this letter | ||
for(int digit = 0; digit < 10; ++digit) | ||
if(!usedDigit[digit]) // this condition guarantees that no digit is used for more than one letter | ||
{ | ||
usedDigit[digit] = true; | ||
assignedDigit[char_idx] = digit; | ||
backtrack(char_idx + 1, w1, w2, w3); | ||
usedDigit[digit] = false; | ||
} | ||
} | ||
} |
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,19 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
int solve(int n) | ||
{ | ||
if(n==0) | ||
return 0; | ||
if(n==1) | ||
return 0; | ||
float rec=n; | ||
return (solve(ceil(rec/3.0))+1); | ||
} | ||
int main() | ||
{ | ||
int n; | ||
cout<<"Enter the number of coins:-\n"; | ||
cin>>n; | ||
cout<<"Minimum Number of weighing required:-\n"; | ||
cout<<solve(n)<<endl; | ||
} |
Binary file not shown.
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,60 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
void create(map<int, vector<int>> mp) | ||
{ | ||
// file pointer | ||
fstream fout; | ||
|
||
// opens an existing csv file or creates a new file. | ||
fout.open("verdis_q3.csv", ios::out | ios::app); | ||
|
||
for (auto i : mp) | ||
{ | ||
cout << i.first << "="; | ||
for (int j = 0; j < i.second.size(); j++) | ||
{ | ||
fout << i.second[j] << " "; | ||
} | ||
cout << endl; | ||
} | ||
|
||
|
||
} | ||
int main() | ||
{ | ||
int n, k; | ||
cout << "Enter the number of bottles:-\n"; | ||
cin >> n; | ||
cout << "Enter the number of prisoners:-\n"; | ||
cin >> k; | ||
map<int, vector<int>> mp; | ||
for (int i = 1; i <= n; i++) | ||
{ | ||
int j = i; | ||
int bit = 0; | ||
while (j > 0) | ||
{ | ||
if (j % 2) | ||
mp[bit + 1].push_back(i); | ||
j = j / 2; | ||
bit++; | ||
} | ||
} | ||
|
||
create(mp); | ||
|
||
cout << "Enter the death and alive sequence-" << endl; | ||
string seq; | ||
cin >> seq; | ||
int ans = 0; | ||
for (int i = seq.size() - 1; i >= 0; i--) | ||
{ | ||
if (seq[i] == '1') | ||
{ | ||
ans += pow(2, seq.size() - 1 - i); | ||
} | ||
} | ||
cout << "Poisioned bottle is:-" << endl; | ||
cout << ans << endl; | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.