Posts

UVA 414 - Machined Surfaces Solution

# include < cstdio > # include < cstring > # include < algorithm > using namespace std ; int main ( ) { int n ; char s [ 26 ] ; while ( scanf ( " %d " , & n ) = = 1 ) { if ( ! n ) return 0 ; int max_x = 0 ; int total_x = 0 ; getchar ( ) ; for ( int i = 0 ; i < n ; i + + ) { gets ( s ) ; int cnt = 0 ; for ( int j = 0 ; j < 25 ; j + + ) { if ( s [ j ] = = 'X' ) cnt + + ; } total_x + = cnt ; max_x = max ( max_x , cnt ) ; } int ans = max_x * n - total_x ; printf ( " %d \n " , ans ) ; } return 0 ; }

UVA 10101 - Bangla Numbers Solution

# include < cstdio > # include < cstring > using namespace std ; int main ( ) { long long int tc = 0 , n ; while ( scanf ( " %lld " , & n ) ! = EOF ) { printf ( " %4lld . " , + + tc ) ; if ( n = = 0 ) { printf ( " 0 \n " ) ; continue ; } int a [ 20 ] = { 0 } , i = 14 ; while ( n ) { a [ i - - ] = n % 10 ; n / = 10 ; } //printf("%d\n",i); int b = a [ 0 ] ; if ( b ) printf ( " %d kuti " , b ) ; b = a [ 1 ] * 10 + a [ 2 ] ; if ( b ) printf ( " %d lakh " , b ) ; b = a [ 3 ] * 10 + a [ 4 ] ; if ( b ) printf ( " %d hajar " , b ) ; b = a [ 5 ] ; if ( b ) printf ( " %d shata " , b ) ; b = a [ 6 ] * 10 + a [ 7 ] ; if ( b ) printf ( " %d " , b ) ; if ( i < 7 ) printf ( " kuti " )...

UVA 11503 - Virtual Friends Solution

# include < iostream > # include < cstdio > # include < string > # include < vector > # include < map > # include < algorithm > using namespace std ; class DS { private : vector < int > parent , rank , setSize ; int numSets ; public : DS ( int n ) { numSets = n ; parent . assign ( n , 0 ) ; rank . assign ( n , 0 ) ; setSize . assign ( n , 1 ) ; for ( int i = 0 ; i < n ; i + + ) parent [ i ] = i ; } int findParent ( int i ) { return parent [ i ] = = i ? i : parent [ i ] = findParent ( parent [ i ] ) ; } bool isSame ( int i , int j ) { return findParent ( i ) = = findParent ( j ) ; } void unionSet ( int x , int y ) { int xRoot = findParent ( x ) ; int yRoot = findParent ( y ) ; if ( xRoot = = yRoot ) return ; if ( rank [ xRoot ] > rank [ yRoot ] ) { ...

Codeforces 716A Solution

# include < bits/stdc++.h > using namespace std ; int main ( ) { int n , c ; scanf ( " %d %d " , & n , & c ) ; int ans = 0 ; int d = 0 ; while ( n - - ) { int t ; scanf ( " %d " , & t ) ; if ( t - d > c ) ans = 1 ; else ans + + ; d = t ; } printf ( " %d \n " , ans ) ; return 0 ; }

UVA 10009 - All Roads Lead Where - Solution

# include < bits/stdc++.h > using namespace std ; # define pb push_back class Graph { int V ; list < int > * adj ; public : Graph ( int V ) { this - > V = V ; adj = new list < int > [ V ] ; } ~ Graph ( ) { delete [ ] adj ; } void addEdge ( int u , int v ) { adj [ u ] . pb ( v ) ; adj [ v ] . pb ( u ) ; } void BFS ( int s , int dest ) { bool visited [ V ] ; int parent [ V ] ; memset ( visited , false , sizeof ( visited ) ) ; list < int > q ; list < int > :: iterator i ; q . pb ( s ) ; visited [ s ] = true ; parent [ s ] = s ; while ( ! q . empty ( ) ) { s = q . front ( ) ; q . pop_front ( ) ; for ( i = adj [ s ] . begin ( ) ; i ! = adj [ s ] . end ( ) ; + + i ) { if ( ! visited [ * i ] ) { q . pb ...

UVA 924 - Spreading The News- Solution

# include < bits/stdc++.h > using namespace std ; # define pb push_back class Graph { int V ; list < int > * adj ; public : Graph ( int V ) { this - > V = V ; adj = new list < int > [ V ] ; } ~ Graph ( ) { delete [ ] adj ; } void addEdge ( int u , int v ) { adj [ u ] . pb ( v ) ; } void BFS ( int s ) { if ( adj [ s ] . size ( ) = = 0 ) { printf ( " 0 \n " ) ; return ; } bool visited [ V ] ; memset ( visited , false , sizeof ( visited ) ) ; int level [ V ] ; int cnt [ V ] = { 0 } ; list < int > q ; list < int > :: iterator i ; q . pb ( s ) ; visited [ s ] = true ; level [ s ] = 0 ; int d , m = 0 ; while ( ! q . empty ( ) ) { s = q . front ( ) ; q . pop_front ( ) ; cnt [ level [ s ] ] + + ; for ( i = adj [ s ] . begin ...

UVA 762 - We Ship Cheap -Solution

# include < bits/stdc++.h > using namespace std ; # define pb push_back map < string , int > msi ; map < int , string > mis ; class Graph { int V ; list < int > * adj ; public : Graph ( int V ) { this - > V = V ; adj = new list < int > [ V ] ; } ~ Graph ( ) { delete [ ] adj ; } void addEdge ( int u , int v ) { adj [ u ] . pb ( v ) ; adj [ v ] . pb ( u ) ; } void BFS ( int s , int dest ) { bool visited [ V ] ; int parent [ V ] ; memset ( visited , false , sizeof ( visited ) ) ; list < int > q ; list < int > :: iterator i ; q . pb ( s ) ; visited [ s ] = true ; parent [ s ] = s ; while ( ! q . empty ( ) ) { s = q . front ( ) ; q . pop_front ( ) ; for ( i = adj [ s ] . begin ( ) ; i ! = adj [ s ] . end ( ) ; + + i ) { if ( ...