Skip to content

Commit c780cbf

Browse files
committed
First set of 300 problems added
0 parents  commit c780cbf

File tree

237 files changed

+10099
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

237 files changed

+10099
-0
lines changed

01 Game.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
// Easy Solution (Inspired by tmwilliamlin)
5+
void solve() {
6+
string s;
7+
cin >> s;
8+
int c[] = {0, 0};
9+
for (char d : s)
10+
c[d - '0']++;
11+
cout << ((min(c[0], c[1]) & 1) ? "DA\n" : "NET\n");
12+
}
13+
14+
// Complex Solution
15+
void solve2() {
16+
string s;
17+
cin >> s;
18+
char f = s[0];
19+
int ctr = 0;
20+
stack<char> st;
21+
st.push(s[0]);
22+
for (int i = 1; i < int(s.length()); i++) {
23+
if (s[i] == f)
24+
st.push(s[i]);
25+
else {
26+
if (!st.empty()) {
27+
st.pop();
28+
ctr++;
29+
}
30+
else {
31+
f = s[i];
32+
st.push(s[i]);
33+
}
34+
}
35+
}
36+
if (ctr % 2 == 0)
37+
cout << "NET\n";
38+
else
39+
cout << "DA\n";
40+
}
41+
42+
int main() {
43+
ios::sync_with_stdio(0);
44+
cin.tie(0);
45+
#ifndef ONLINE_JUDGE
46+
freopen("input.txt", "r", stdin);
47+
freopen("output.txt", "w", stdout);
48+
#endif
49+
int t;
50+
cin >> t;
51+
while (t--)
52+
solve();
53+
return 0;
54+
}

A cookie for You.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
using namespace std::chrono;
4+
typedef long long ll;
5+
6+
// unhackable custom hash for unordered_map
7+
// Credits : neil
8+
struct custom_hash {
9+
size_t operator()(uint64_t x) const {
10+
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
11+
return x + FIXED_RANDOM;
12+
}
13+
};
14+
15+
void solve() {
16+
ll a, b, n, m;
17+
cin >> a >> b >> n >> m;
18+
if (a + b >= m + n && m <= min(a, b))
19+
cout << "Yes\n";
20+
else
21+
cout << "No\n";
22+
}
23+
24+
int main() {
25+
ios::sync_with_stdio(0);
26+
cin.tie(0);
27+
#ifndef ONLINE_JUDGE
28+
freopen("input.txt", "r", stdin);
29+
freopen("output.txt", "w", stdout);
30+
#endif
31+
int t;
32+
cin >> t;
33+
while (t--)
34+
solve();
35+
return 0;
36+
}

ADASHOP2.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <iostream>
2+
#include <vector>
3+
using namespace std;
4+
5+
int main() {
6+
ios::sync_with_stdio(0);
7+
cin.tie(0);
8+
int t, r, c;
9+
cin>>t;
10+
while(t--) {
11+
cin>>r>>c;
12+
vector<int> set_of_moves[18]={
13+
{8, 8},{7,7},{8, 6},{3,1},
14+
{4,2},{5,1},{8,4},{7,3},{8,2},
15+
{7,1},{1,7},{2,8},{3,7},{4,8},
16+
{1,5},{2,4},{1,3},{6,8}
17+
};
18+
if(r!=1 || c!=1) {
19+
if(r==c) {
20+
cout<<"19\n";
21+
cout<<"1 1\n";
22+
}
23+
else {
24+
cout<<"20\n";
25+
cout<<(r+c)/2<<" "<<(r+c)/2<<"\n";
26+
cout<<"1 1\n";
27+
}
28+
}
29+
else
30+
cout<<"18\n";
31+
for(int i=0;i<18;i++) {
32+
for(int j=0; j<2; j++) {
33+
cout<<set_of_moves[i][j]<<" ";
34+
}
35+
cout<<"\n";
36+
}
37+
}
38+
return 0;
39+
}

ADTRI.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long ll;
4+
5+
const ll N=5000002;
6+
7+
bool isPrime[N], isHyp[N];
8+
vector<ll> prime;
9+
10+
void ansfunc() {
11+
for(ll i=0;i<N;i++) {
12+
isHyp[i]=false;
13+
isPrime[i]=true;
14+
}
15+
//Sieve of Eratosthenes
16+
isPrime[0] = isPrime[1] =false;
17+
for(ll i=2; i<N; i++) {
18+
if(isPrime[i])
19+
for(ll j=i*2;j<N;j+=i)
20+
isPrime[j]=false;
21+
}
22+
for(ll i=2;i<N;i++) {
23+
if(isPrime[i] == true && i%4==1)
24+
prime.push_back(i);
25+
}
26+
for(ll i=0;i<prime.size();i++) {
27+
for(ll j=prime[i]; j<N; j+=prime[i])
28+
isHyp[j]=true;
29+
}
30+
}
31+
int main() {
32+
ios::sync_with_stdio(0);
33+
cin.tie(0);
34+
ansfunc();
35+
ll t;
36+
cin>>t;
37+
while(t--) {
38+
ll n;
39+
cin>>n;
40+
if(isHyp[n])
41+
cout<<"YES\n";
42+
else
43+
cout<<"NO\n";
44+
}
45+
return 0;
46+
}

AMMEAT.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
ios_base::sync_with_stdio(false);
8+
cin.tie(NULL);
9+
cout.tie(NULL);
10+
int t, n, m, i;
11+
cin>>t;
12+
while(t--)
13+
{
14+
cin>>n >>m;
15+
long p[100];
16+
for(i=0;i<n;i++)
17+
{
18+
cin>>p[i];
19+
}
20+
sort(p,p+n,greater<long>());
21+
long totalMeatBall=0;
22+
for(i=0;i<n;i++)
23+
{
24+
totalMeatBall+=p[i];
25+
if(totalMeatBall >= m)
26+
{
27+
cout<<i+1<<"\n";
28+
break;
29+
}
30+
else if(i==n-1)
31+
cout<<"-1\n";
32+
}
33+
}
34+
return 0;
35+
}

AMSGAME.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int gcd(int a,int b)
5+
{
6+
if(b==0)
7+
return a;
8+
else
9+
return(gcd(b,a%b));
10+
}
11+
int main()
12+
{
13+
int t,i,n;
14+
cin>>t;
15+
while(t--)
16+
{
17+
cin>>n;
18+
int a[n];
19+
for(i=0;i<n;i++)
20+
{
21+
cin>>a[i];
22+
}
23+
if(n==1)
24+
cout<<a[0]<<"\n";
25+
else if(n==2)
26+
cout<<gcd(a[0],a[1])<<"\n";
27+
else
28+
{
29+
int g;
30+
g=gcd(a[0],a[1]);
31+
for(i=2;i<n;i++)
32+
{
33+
g=gcd(g,a[i]);
34+
}
35+
cout<<g<<"\n";
36+
}
37+
}
38+
return 0;
39+
}

ANSLEAK.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <iostream>
2+
#include <vector>
3+
using namespace std;
4+
5+
int main() {
6+
ios_base::sync_with_stdio(0);
7+
cin.tie(0);
8+
int t, n, m, k, x;
9+
cin>>t;
10+
while(t--) {
11+
cin>>n>>m>>k;
12+
vector<vector<int> > c(n);
13+
for(int i=0; i<n; i++) {
14+
for(int j=0; j<k; j++) {
15+
cin>>x;
16+
c[i].push_back(x);
17+
}
18+
}
19+
for(int i=0; i<n; i++) {
20+
int ma,ctr=0,max_ctr=0;
21+
for(int j=1; j<=m; j++) {
22+
ctr=0;
23+
for(int l=0; l<k; l++) {
24+
if(c[i][l]==j)
25+
ctr++;
26+
}
27+
if(ctr>=max_ctr) {
28+
max_ctr=ctr;
29+
ma=j;
30+
}
31+
}
32+
cout<<ma<<" ";
33+
}
34+
cout<<"\n";
35+
}
36+
return 0;
37+
}

ANUBTG.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
ios_base::sync_with_stdio(false);
8+
cin.tie(NULL);
9+
cout.tie(NULL);
10+
long t,n,i,ans=0;
11+
cin>>t;
12+
while(t--)
13+
{
14+
cin>>n;
15+
long a[1000];
16+
for(i=0;i<n;i++)
17+
{
18+
cin>>a[i];
19+
}
20+
sort(a,a+n,greater<long>());
21+
for(i=0;i<n;i++)
22+
{
23+
if(i%4<2)
24+
ans+=a[i];
25+
}
26+
cout<<ans<<"\n";
27+
ans=0;
28+
}
29+
return 0;
30+
}

ANUDTC.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int t,n,i;
7+
cin>>t;
8+
while(t--)
9+
{
10+
cin>>n;
11+
if (360 % n == 0)
12+
cout<<"y ";
13+
else
14+
cout<<"n ";
15+
if(n<=360)
16+
cout<<"y ";
17+
else
18+
cout<<"n ";
19+
if (n*(n+1)/2 <=360)
20+
cout<<"y ";
21+
else
22+
cout<<"n ";
23+
cout<<"\n";
24+
}
25+
}

ANUWTA.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
ios_base::sync_with_stdio(false);
7+
cin.tie(NULL);
8+
long t,n,s;
9+
cin>>t;
10+
while(t--)
11+
{
12+
cin>>n;
13+
s=0;
14+
if(n==0){
15+
cout<<n<<"\n";
16+
continue;
17+
}
18+
else{
19+
s=n+((n*(n+1))/2);
20+
cout<<s<<"\n";
21+
}
22+
}
23+
return 0;
24+
}

0 commit comments

Comments
 (0)