Posts

Showing posts from 2020

Multiset remove single element by value

  https://stackoverflow.com/questions/9167745/in-stdmultiset-is-there-a-function-or-algorithm-to-erase-just-one-sample-unic

Number of 1 in a binary number of a decimal number

 https://codeforces.com/blog/entry/13134

Round to fixed decimal while calculating

  https://stackoverflow.com/questions/14369673/round-double-to-3-points-decimal

Trapezium area formula

https://en.m.wikipedia.org/wiki/Trapezoid#Area

log x based n

 https://stackoverflow.com/questions/18874255/log-base-n-of-x

Pow function 1 less value

 https://stackoverflow.com/questions/35658441/power-function-returns-1-less-result

Finding sin cos values

 https://stackoverflow.com/questions/40013267/finding-sine-and-cosine-values-of-an-angle-in-c

Floyd cycle detection algorithm for linera time and linear space

inline int FloydCycleFind ( int x0 ){ x0 %= m ; if ( ! k ) return x0 ; int hare = f ( f ( x0 )), tortoise = f ( x0 ); while ( tortoise != hare ){ hare = f ( f ( hare )); tortoise = f ( tortoise ); } int mu = 0 ; hare = x0 ; while ( tortoise != hare ){ hare = f ( hare ); tortoise = f ( tortoise ); mu ++ ; if ( mu == k ) return hare ; } k -= mu ; int lambda = 1 ; hare = f ( tortoise ); while ( hare != tortoise ) hare = f ( hare ), lambda ++ ; k %= lambda ; while ( k ) tortoise = f ( tortoise ), k -- ; return tortoise ; } https://toph.co/p/not-my-fault

Geeks that save time

https://www.geeksforgeeks.org/find-the-number-occurring-odd-number-of-times/

ALL Number product resulted number divisor count

Problem:  https://acm.timus.ru/problem.aspx?space=1&num=1049 # include <bits/stdc++.h> using namespace std ; typedef long long ll; # define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0); int status[ 100000000 / 32 ]; bool Check ( int N, int pos) { return ( bool )(N & ( 1 <<pos));} int Set ( int N, int pos) { return N=N | ( 1 <<pos);} long long int arr[ 10000000 ]; long long int l= 0 ,a,b= 100000 ,n; void sieve () { long long int i,j,sqrtN; sqrtN = int ( sqrt ( b ) ); for ( i= 3 ; i<=sqrtN; i+= 2 ) { if ( Check(status[i/ 32 ],i% 32 )== 0 ) { for (j=i*i; j<=b; j+= 2 *i) { status[j/ 32 ]=Set(status[j/ 32 ],j% 32 ); } } } arr[ 0 ]= 2 ; l= 1 ; for (i= 3 ;i<=b;i+= 2 ) { if (Check(status[i/ 32 ],i% 32 )== 0 ) { arr[l]=i; l++; } } } long lo...

UVA 10004

#include<bits/stdc++.h> #define rep0(i,n) for(i=0;i<n;i++) #define rep(i,n) for(i=1;i<=n;i++) #define reps(i,a,n) for(i=a;i<=n;i++) #define mem(ara,n) memset(ara,n,sizeof(ara)) #define memb(ara) memset(ara,false,sizeof(ara)) #define all(x) (x).begin(),(x).end() #define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0); #define eb              emplace_back #define em              emplace #define pb              push_back #define Mp              make_pair #define ff              first #define ss              second #define mod 1000000007 typedef long long ll; using namespace std; const int M = (int)(2e6 + 239); void decitobinbitodeci() {     string binary = bitset<8>(128).to_string(); //to binary     cou...

Convert number to string

int-  https://stackoverflow.com/questions/5590381/easiest-way-to-convert-int-to-string-in-c double -  https://stackoverflow.com/questions/332111/how-do-i-convert-a-double-into-a-string-in-c ll-  https://stackoverflow.com/questions/947621/how-do-i-convert-a-long-to-a-string-in-c

Combinatorics

1. Regular odd polygon total intersection point=     https://math.stackexchange.com/questions/1010591/what-is-the-number-of-intersections-of-diagonals-in-a-convex-equilateral-polygon Problem:  https://toph.co/p/irregular-is-tough-regular-is-easy 2. Given two side of a triangle, how many valid possible value of third side- 2*(min(a,b))-1 problem:  https://toph.co/p/geometry-forever n ( n − 1 ) ( n − 2 ) ( n − 3 ) 24 n ( n − 1 ) ( n − 2 ) ( n − 3 ) 24

Matrix Operation

struct matrix { int n ; vector < vector < int > > t ; matrix ( ) { } matrix ( int _n , int val ) { n = _n ; t . assign ( n , vector < int > ( n , val ) ) ; } matrix ( int _n ) { n = _n ; t . assign ( n , vector < int > ( n , 0 ) ) ; } matrix ( vector < vi > v ) { n = v . size ( ) ; t = v ; } matrix unit ( int _n ) { matrix ans = matrix ( _n , 0 ) ; for ( int i = 0 ; i < _n ; i ++ ) ans . t [ i ] [ i ] = 1 ; return ans ; } ///make sure to erase mod if not needed matrix operator * ( matrix b ) { matrix c = matrix ( n , 0 ) ; for ( int i = 0 ; i < n ; i ++ ) for ( int k = 0 ; k < n ; k ++ ) for ( int j = 0 ; j < n ; j ++ ) c . t [ i ] [ j ] = ( c . t [ i ] [ j ] + 1LL * t [ i ] [ k ] * b . t [ k ] [ j ] % mod ) % mod ; return c ; } matrix operator | ( matrix b ) { matrix c = matrix ( n , - inf ) ; for ( int i =...