-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCF_LikeMe.cpp
More file actions
133 lines (116 loc) · 1.97 KB
/
Copy pathCF_LikeMe.cpp
File metadata and controls
133 lines (116 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int binomialCoeff(int n, int k) ;
//this code still gives tle... hence do not use pascles triangle concept... reffer to the submisison
int calcoeff(long long int l,long long int d,long long int s,long long int c)
{
int i,flag=0;
long long int ans=0;
long long int u=d,p;
// Every line has number of
// integers equal to line
// number
if (d==1)
{
flag=1;
ans=s;
if(ans>=l)
{
cout<<"ALIVE AND KICKING\n";
}
else
{
cout<<"DEAD AND ROTTING\n";
}
}
else if(d>=2)
{
ans=ans+ (s*(pow(c,d-1)))+s;
if(ans>=l)
{
d=0;
flag=1;
cout<<"ALIVE AND KICKING\n";
}
}
for ( i = 1; i <d-1; i++)
{
p=binomialCoeff(d-1, i);
ans=ans+s*(p*pow(c,u-2));
if(ans>=l)
{
flag=1;
cout<<"ALIVE AND KICKING\n";
break;
}
u--;
}
if(flag!=1)
{
cout<<"DEAD AND ROTTING\n";
}
return ans;
}
int binomialCoeff(int n, int k)
{
int i;
int res = 1;
if (k > n - k)
k = n - k;
for ( i = 0; i < k; ++i)
{
res *= (n - i);
res /= (i + 1);
}
return res;
}
//so the concept apart form brute fore is that ihe coefficients follow the pascles triangle pattern!!
int main()
{
int t,i;
long long int ans;
long long int l,d,s,c;
cin>>t;
while(t--)
{
cin>>l>>d>>s>>c;
calcoeff(l,d,s,c);
}
}
/*
//BRUTE FORCE
int likes(long long int d,long long int s,long long int c)
{
if(d==0)
{
return s;
}
else
{
s= c*s+s;
likes(d-1,s,c);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t,i;
cin>>t;
while(t--)
{
long long int l,s,d,ans,c;
cin>>l>>d>>s>>c;
ans=likes(d-1,s,c);
if(ans>=l)
{
cout<<"ALIVE AND KICKING\n";
}
else
{
cout<<"DEAD AND ROTTING\n";
}
}
}*/