Posts

Showing posts from August, 2019

UVA 621

/* ID: Nipun Paul LANG: C++ PROB: God knows */ #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() {     /*ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);*/     ll a;     cin>>a;     for(int i=0; i<a; i++)     {         string b;         cin>>b;         if(b=="1" || b=="4" || b=="78")         {             cout<<"+"<<endl;         }         else if(b[b.size()-1]=='5' && b[b.size()-2]=='3')         {             cout<<"-"<<endl;         }         else if(b[0]=='9' && b[b.size()-1]=='4')         {            ...

UVA 11498

/* ID: Nipun Paul LANG: C++ PROB: God knows */ #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ll a,b,c,d,e;     while(cin>>a)     {         if(a==0)         {             break;         }         cin>>b>>c;         for(int i=0; i<a; i++)         {             cin>>d>>e;             if(d==b || e==c)             {                 cout<<"divisa"<<endl;             }             else if(d>b && e>c)   ...

UVA 10550

/* ID: Nipun Paul LANG: C++ PROB: God knows */ #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ll a,b,c,d;     while(cin>>a>>b>>c>>d)     {         if(a+b+c+d==0)         {             break;         }         ll sum=0,b1=0,c1=0,d1=0;         if(a>=b)         {             a=40+(b+1)-(a+1);             b1=0;         }         else         {             b1=b;         }         if(b<=c)         {     ...

UVA 272

/* ID: Nipun Paul LANG: C++ PROB: God knows */ #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int flag=0;     string a;     while(getline(cin,a))     {         for(int i=0; i<a.size(); i++)         {             if(a[i]=='"' && flag==0)             {                 cout<<"``";                 flag=1;             }             else if(a[i]=='"' && flag==1)             {                 cout<<"''";               ...

Algorithm on how to find the day of a week

https://www.hackerearth.com/blog/developers/how-to-find-the-day-of-a-week/

Prefix sum or for fixed range summation

https://codeforces.com/problemset/problem/433/B https://codeforces.com/problemset/problem/313/B DP catagory solution where accumulate sum not possible in this kind of problem because of test cases and time limit.So if we do sum and insert it in an array previously,just use a vector and subtract from upper trange to lower range we'll get the answer.

Codeforces 295(Div 2) B

https://codeforces.com/problemset/problem/520/B Editorial from blog- Its quite simple . First understand if m<n then ans is n-m  else  make m less than or equal to n by dividing it by 2 , increase the count by one and if at any moment it becomes odd increase the count by 1 and increase m by 1 . e.g  4 17  1. 17->18  2. 18->9  3. 9->10  4. 10->5  5. 5->6  6. 6->3  then 3 is smaller than 4 so ans is 6+(4-3) = 7  * Fully reverse of what the question said to do and have a alternative main solution using  breadth-first search.

Big sum(nsu question)

Image
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() {     int c,d,e,l,x,y;     string a,b;     char f[1000],g[1000];     cin>>a>>b;     c=a.size();     d=b.size();     if(c>d)     {         e=c-d;         for(int i=0; i<e; i++)         {             f[i]='0';         }         l=0;         for(int i=e; i<e+d; i++)         {             f[i]=b[l];             l++;         }         l=0;         int temp=0;         int temp1=0;         for(int i=c-1; i>=0; i--)         {   ...

UVA 10432 & About Polygon and sin() function

Polygon-  https://www.mathopenref.com/polygonregulararea.html Sin()- It work's with radian rather than degree,so we first have to convert the given degree to radian by multiplying (PI/180). Then calling the function. /* ID: Nipun Paul LANG: C++ PROB: God knows */ #include<bits/stdc++.h> using namespace std; int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     double a,b,c,d;     while(cin>>a>>b)     {         d=(360/b*1.0)*(M_PI/180);         c=((a*a*b)*(sin(d)))/2;         printf("%.3f\n",c);     } }

Spoj-PRIME GENERATOR (Using segmented sieve print billion range primes)

https://www.spoj.com/problems/PRIME1/ https://www.geeksforgeeks.org/segmented-sieve-print-primes-in-a-range/ #include <bits/stdc++.h> using namespace std; // This functions finds all primes smaller than limit // using simple sieve of eratosthenes.  It stores found // primes in vector prime[] void simpleSieve(int limit, vector<int>& prime) {     bool mark[limit + 1];     memset(mark, false, sizeof(mark));     for (int i = 2; i <= limit; ++i) {         if (mark[i] == false) {             // If not marked yet, then its a prime             prime.push_back(i);             for (int j = i; j <= limit; j += i)                 mark[j] = true;         }     } } // Finds all prime numbers in given range using // segmented sieve void primes...

C++ output manipulators like endl,setw

https://www.includehelp.com/cpp-tutorial/cpp-manipulators-endl-setw-setprecision-setf-cpp-programming-tutorial.aspx

UVA 382

/* ID: Nipun Paul LANG: C++ PROB: God knows */ #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int a,b,c,sum=0;     int v[100000];     int flag=1;     while(cin>>a)     {         if(flag==1)         {             cout<<"PERFECTION OUTPUT"<<endl;             flag=0;         }         if(a==0)         {             break;         }         int l=0;         v[l]=a;         l++;         for(int i=0; i<l; i++)         {         ...

UVA 10469

/* ID: Nipun Paul LANG: C++ PROB: God knows */ #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ll a,b,c,d,l=0,m=0,sum=0;     while(cin>>a>>b)     {         vector<int>v,v1,v3;         c=a;         d=b;         while(c!=0)         {             v.push_back(c%2);             c=c/2;             l++;         }         while(d!=0)         {             v1.push_back(d%2);             d=d/2;             m++;         }   ...

UVA 494

/* ID: Nipun Paul LANG: C++ PROB: God knows */ #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int sum=0,flag;     string a;     while(getline(cin,a)){     //cout<<a<<endl;     for(int i=0; i<a.size(); i++)     {         if((a[i]>='a' && a[i]<='z') || (a[i]>='A' && a[i]<='Z'))         {             flag=0;         }         else         {             if(flag==0)             {                 sum++;             }             flag=1; ...

UVA 10929 (multiple of 11)

/* ID: Nipun Paul LANG: C++ PROB: God knows */ #include<bits/stdc++.h> using namespace std; typedef long long ll; vector<int> v; int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int sum=0,b;     char a[1005];     while(cin>>a)     {         if(strlen(a)==1 && a[0]=='0')         {             break;         }         for(int i=0; i<strlen(a); i++)         {             b=a[i]-'0';             if((i+1)%2==0)             {                 b=(-1)*b;             }             sum=sum+b;         } ...