Codeforces 1345B B. Card Constructions Solution

Solution in C++:

///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.  
  6. int t,i,j,a,s,ar[100000],n,v,f,cn,s1,k;
  7. cin>>t;
  8. while(t--)
  9. {
  10. s=2,v=1,cn=0;
  11. ar[0]=2;
  12. cin>>n;
  13. if(n<2)
  14. cout<<"0"<<endl;
  15. else if(n<4)
  16. cout<<"1"<<endl;
  17. else
  18. {
  19. for(i=2; s<=n; i++)
  20. {
  21. s=s+((2*i)+(i-1));
  22. ar[v]=s;
  23. v++;
  24. }
  25. for(j=v-1; j>=0; j--)
  26. {
  27. if(ar[j]<=n)
  28. {
  29. n=n-ar[j];
  30. cn++;
  31. j++;
  32. }
  33. }
  34. cout<<cn<<endl;
  35.  
  36. }
  37.  
  38. }
  39. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.