Skip to content

Commit 47dc99e

Browse files
authored
Merge pull request manishbisht#60 from iamdeepanshutaneja/master
Added Codeforces problems
2 parents c0285e7 + 64e452e commit 47dc99e

10 files changed

+285
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//Problem Link : https://codeforces.com/problemset/problem/1343/C
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
typedef long long ll;
6+
bool oppositesigns(ll x,ll y)
7+
{
8+
return ((x^y)<0);
9+
}
10+
bool large(ll x,ll y)
11+
{
12+
if(x>y)
13+
return 1;
14+
return 0;
15+
}
16+
int main()
17+
{
18+
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
19+
ll t,n,p,i;
20+
cin>>t;
21+
while(t--)
22+
{
23+
cin>>n;
24+
ll a[n];
25+
vector <ll> b;
26+
for(i=0;i<n;i++)
27+
cin>>a[i];
28+
p=a[0];
29+
for(i=0;i<n;i++)
30+
{
31+
if(oppositesigns(p,a[i])==0)
32+
{
33+
if(large(a[i],p)==1)
34+
p=a[i];
35+
}
36+
else
37+
{
38+
b.push_back(p);
39+
p=a[i];
40+
}
41+
}
42+
b.push_back(p);
43+
ll sum=0;
44+
for(i=0;i<b.size();i++)
45+
{
46+
sum=sum+b[i];
47+
}
48+
cout<<sum<<endl;
49+
}
50+
return 0;
51+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//Problem Link : https://codeforces.com/problemset/problem/893/B
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
typedef long long ll;
6+
int main()
7+
{
8+
ll n,i=1,j,num;
9+
vector <ll> bn;
10+
cin>>n;
11+
for(i=1;i<18;i+=2)
12+
{
13+
num=0;
14+
for(j=i;j>i/2;j--)
15+
{
16+
num+=pow(2,j-1);
17+
}
18+
bn.push_back(num);
19+
}
20+
i=1;
21+
while(i<=n)
22+
{
23+
if(n%i==0)
24+
{
25+
ll g = n/i;
26+
if(find( bn.begin(), bn.end(), g) != bn.end())
27+
{
28+
cout<<n/i<<endl;
29+
break;
30+
}
31+
}
32+
i++;
33+
}
34+
return 0;
35+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//Problem Link : https://codeforces.com/problemset/problem/447/B
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
typedef long long ll;
6+
int main()
7+
{
8+
string s;
9+
cin>>s;
10+
ll k,i,c=0;
11+
cin>>k;
12+
ll w[26];
13+
for(i=0;i<26;i++)
14+
cin>>w[i];
15+
for(i=0;i<s.size();i++)
16+
{
17+
c=c+(w[s[i]-'a']*(i+1));
18+
}
19+
sort(w,w+26);
20+
for(i=s.size()+1;i<=s.size()+k;i++)
21+
c=c+(i*w[25]);
22+
cout<<c;
23+
return 0;
24+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//Problem Link : http://codeforces.com/problemset/problem/1426/C
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
typedef long long ll;
6+
int main()
7+
{
8+
ll t;
9+
cin>>t;
10+
while(t--)
11+
{
12+
ll n,c=0;
13+
cin>>n;
14+
ll m = sqrt(n);
15+
c=m-1;
16+
if(n%m==0)
17+
cout<<c+(n/m)-1<<endl;
18+
else
19+
cout<<c+(n/m)<<endl;
20+
}
21+
return 0;
22+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//Problem Link : https://codeforces.com/problemset/problem/1140/D
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
typedef long long ll;
6+
int main()
7+
{
8+
ll n,w=0,i;
9+
cin>>n;
10+
for(i=3;i<=n;i++)
11+
w=w+(i*(i-1));
12+
cout<<w;
13+
return 0;
14+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//Problem Link : https://codeforces.com/problemset/problem/1221/C
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
typedef long long ll;
6+
int main()
7+
{
8+
ll q;
9+
cin>>q;
10+
while(q--)
11+
{
12+
ll c,m,x,d;
13+
cin>>c>>m>>x;
14+
if(c<=x||m<=x||c==0||m==0)
15+
{
16+
cout<<min(c,m)<<endl;
17+
}
18+
else
19+
{
20+
c=c-x;m=m-x;
21+
if((c+m)/3>min(c,m))
22+
x=x+min(c,m);
23+
else
24+
x=x+(c+m)/3;
25+
cout<<x<<endl;
26+
}
27+
}
28+
return 0;
29+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//Problem Link : https://codeforces.com/problemset/problem/898/B
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
typedef long long ll;
6+
int main()
7+
{
8+
ll n,a,b,i,y;
9+
cin>>n>>a>>b;
10+
for(i=0;i<=n/a;i++)
11+
{
12+
y = (n-i*a)/b;
13+
if(i*a+y*b==n)
14+
{
15+
cout<<"YES"<<endl<<i<<" "<<y;
16+
return 0;
17+
}
18+
}
19+
cout<<"NO";
20+
return 0;
21+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//Problem Link : https://codeforces.com/problemset/problem/753/A
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
typedef long long ll;
6+
int main()
7+
{
8+
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
9+
ll n,sum=0,i;
10+
cin>>n;
11+
vector <ll> b;
12+
if(n==1)
13+
{
14+
cout<<n<<endl<<n;
15+
return 0;
16+
}
17+
for(i=1;i<n;i++)
18+
{
19+
if((n-sum-i)>i)
20+
{
21+
sum+=i;
22+
b.push_back(i);
23+
}
24+
else
25+
{
26+
b.push_back(n-sum);
27+
break;
28+
}
29+
}
30+
cout<<b.size()<<endl;
31+
for(i=0;i<b.size();i++)
32+
cout<<b[i]<<" ";
33+
return 0;
34+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//Problem Link : http://codeforces.com/problemset/problem/1426/B
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
typedef long long ll;
6+
int main()
7+
{
8+
ll t;
9+
cin>>t;
10+
while(t--)
11+
{
12+
ll n,m,i,flag=0;
13+
cin>>n>>m;
14+
ll a[2*n][2];
15+
for(i=0;i<2*n;i++)
16+
cin>>a[i][0]>>a[i][1];
17+
if(m%2!=0)
18+
cout<<"NO"<<endl;
19+
else
20+
{
21+
for(i=0;i<2*n;i+=2)
22+
{
23+
if(a[i][1]==a[i+1][0])
24+
{
25+
flag=1;
26+
break;
27+
}
28+
}
29+
if(flag==1)
30+
cout<<"YES"<<endl;
31+
else
32+
cout<<"NO"<<endl;
33+
}
34+
35+
}
36+
return 0;
37+
}

Practice/Codeforces/XORinacci-1208A

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//Problem Link : https://codeforces.com/problemset/problem/1208/A
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
typedef long long ll;
6+
int main()
7+
{
8+
ll a,b,n,t;
9+
cin>>t;
10+
while(t--)
11+
{
12+
cin>>a>>b>>n;
13+
ll x[3];
14+
x[0]=a;x[1]=b;x[2]=(a^b);
15+
cout<<x[n%3]<<endl;
16+
}
17+
return 0;
18+
}

0 commit comments

Comments
 (0)