-
Notifications
You must be signed in to change notification settings - Fork 497
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 #101 from shreenanda-8/master
Updated ladder B
- Loading branch information
Showing
4 changed files
with
245 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,47 @@ | ||
#include<bits/stdc++.h> | ||
|
||
|
||
#define ll long long | ||
#define max 1000000000 | ||
|
||
|
||
|
||
|
||
using namespace std; | ||
|
||
|
||
int32_t main() | ||
{ | ||
ios::sync_with_stdio(0); | ||
cin.tie(0); | ||
|
||
ll n, s, t; | ||
cin >> n >> s >> t; | ||
ll arr[n]; | ||
arr[0] = -1; | ||
for (ll i = 1; i <= n; i++) | ||
{ | ||
cin >> arr[i]; | ||
} | ||
ll index, value, ans = -1, cnt = 0; | ||
index = s; | ||
value = arr[index]; | ||
while (cnt < n) | ||
{ | ||
if (value == index && t != index) | ||
{ | ||
ans = -1; | ||
break; | ||
} | ||
else if (t == index) | ||
{ | ||
ans = cnt; | ||
break; | ||
} | ||
index = value; | ||
value = arr[index]; | ||
cnt++; | ||
} | ||
cout << ans; | ||
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,91 @@ | ||
#include<bits/stdc++.h> | ||
|
||
|
||
#define ll long long | ||
|
||
|
||
|
||
using namespace std; | ||
int main() | ||
{ | ||
string s; | ||
cin >> s; | ||
ll H[26] = {0}; | ||
for (ll i = 0; i < s.length(); i++) | ||
{ | ||
H[s[i] - 'a']++; | ||
} | ||
ll even = 0, odd = 0; | ||
for (ll i = 0; i < 26; i++) | ||
{ | ||
if (H[i] % 2 == 0) | ||
{ | ||
even++; | ||
} | ||
else | ||
{ | ||
odd++; | ||
} | ||
} | ||
ll cn = 0; | ||
if (odd <= 1) | ||
{ | ||
cout << "First" << "\n"; | ||
|
||
} | ||
else | ||
{ | ||
if (even % 2 == 0) | ||
{ | ||
for (ll i = 0; i < 26; i++) | ||
{ | ||
if (H[i] % 2 == 0) | ||
{ | ||
H[i]--; | ||
} | ||
} | ||
for (ll i = 0; i < 26; i++) | ||
{ | ||
if (H[i] % 2 != 0) | ||
{ | ||
cn++; | ||
} | ||
} | ||
if (cn % 2 != 0) | ||
{ | ||
cout << "First" << "\n"; | ||
} | ||
else | ||
{ | ||
cout << "Second" << "\n"; | ||
} | ||
} | ||
else | ||
{ | ||
for (ll i = 0; i < 26; i++) | ||
{ | ||
if (H[i] % 2 == 0) | ||
{ | ||
H[i]--; | ||
} | ||
} | ||
for (ll i = 0; i < 26; i++) | ||
{ | ||
if (H[i] % 2 != 0) | ||
{ | ||
cn++; | ||
} | ||
} | ||
if (cn % 2 != 0) | ||
{ | ||
cout << "Second" << "\n"; | ||
} | ||
else | ||
{ | ||
cout << "First" << "\n"; | ||
} | ||
} | ||
} | ||
|
||
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,42 @@ | ||
#include<bits/stdc++.h> | ||
|
||
|
||
#define ll long long | ||
#define mm 1000000001 | ||
|
||
using namespace std; | ||
|
||
//They are everywhere | ||
int32_t main() | ||
{ | ||
ios::sync_with_stdio(0); | ||
cin.tie(0); | ||
ll n, t; | ||
cin >> n >> t; | ||
ll arr[n]; | ||
for (ll i = 0; i < n; i++) | ||
{ | ||
cin >>arr[i]; | ||
} | ||
ll start = 0, sum = 0, cnt = 0; | ||
vector<ll>ans; | ||
for (ll i = 0; i < n; i++) | ||
{ | ||
sum += arr[i]; | ||
if (sum <= t) | ||
{ | ||
cnt++; | ||
} | ||
else | ||
{ | ||
sum -= arr[start]; | ||
ans.push_back(cnt); | ||
cnt = i - start; | ||
start++; | ||
|
||
} | ||
} | ||
ans.push_back(cnt); | ||
cout << *max_element(ans.begin(), ans.end()); | ||
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,65 @@ | ||
#include <bits/stdc++.h> | ||
#define ll long long | ||
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) | ||
using namespace std; | ||
set<ll> usinversal; | ||
ll ans = 0; | ||
ll aa = 0; | ||
|
||
|
||
int main() | ||
{ | ||
fast; | ||
|
||
ll n; | ||
cin >> n; | ||
ll sum1 = 0, sum2= 0; | ||
vector<ll> a1, a2; | ||
bool l; | ||
while (n--) | ||
{ | ||
ll x; | ||
cin >>x; | ||
if (x >= 0) | ||
{ | ||
sum1 += x; | ||
a1.push_back(x); | ||
l = true; | ||
} | ||
else | ||
{ | ||
sum2 += -1 *x; | ||
a2.push_back(-1 * x); | ||
l = false; | ||
} | ||
} | ||
|
||
if (sum1 >sum2) | ||
{ | ||
cout << "first" << "\n"; | ||
} | ||
else if (sum2 > sum1) | ||
{ | ||
cout << "second" << "\n"; | ||
} | ||
else | ||
{ | ||
if (a1 > a2) | ||
{ | ||
cout << "first" << "\n"; | ||
} | ||
else if (a1 < a2) | ||
{ | ||
cout <<"second" << "\n"; | ||
} | ||
else if (l) | ||
{ | ||
cout << "first" << "\n"; | ||
} | ||
else | ||
{ | ||
cout << "second" << "\n"; | ||
} | ||
} | ||
return 0; | ||
} |