HERE I SOLVE /PRACTICE PROGRAMMING EXERCISES FROM VARIOUS sources ENJOY!
about outsourcing - russian opinion
Другая проблема, которая стала ясна: аутсорсинг — бессмысленная модель для роста бизнеса. Это линейный рынок, ты продаёшь не сложность работы, а часы. То есть чтобы увеличить выручку, нужно либо работать в два раза больше часов, либо делать час в два раза дороже. А это нецелесообразно, так как ты перестанешь выдерживать конкуренцию. Этот рынок плоский, он имеет чёткую отсечку, там нет экспоненты. А бизнесу нужна экспонента. Стало ясно: нужно разрабатывать свои решения, которые ты отдашь людям, и они начнут генерировать доход и прибыль.
Posted by
erjan
my solution to dp uva 136 - ugly numbers with debugging statements
#include <iostream>
#include <cstdio>
//#include <windows.h>
using namespace std;
int main(){
long array[1500] ;
array[0] = 1 ;
int pointer_2 = 0;
int pointer_3 = 0;
int pointer_5 = 0;
for(int i = 1 ; i <=1500 ; i++){
// cout << "====== i:" << i << " ============================================================" <<endl ;
int test1 = 2 * array[pointer_2] ;
int test2 = 3 * array[pointer_3] ;
int test3 = 5 * array[pointer_5] ;
int chosen = min(test1, min(test2,test3)) ;
/*
cout << "test 1 = 2 * " << array[pointer_2] << " = "<< 2 * array[pointer_2] <<endl ;
cout << "test 2 = 3 * " << array[pointer_3] << " = "<<3 * array[pointer_3] <<endl ;
cout << "test 3 = 5 * " << array[pointer_5] << " = "<< 5 * array[pointer_5] <<endl ;
*/
if(chosen == test1){array[i] = test1 ; pointer_2++ ;
// cout << "pointer 2 updated , :" << pointer_2 <<endl ;
}
if(chosen == test2){array[i] = test2 ; pointer_3++ ;
// cout << "pointer 3 updated , :" << pointer_3 <<endl ;
}
if(chosen == test3){array[i] = test3 ; pointer_5++ ;
// cout << "pointer 5 updated , :" << pointer_5 <<endl ;
}
// cout << "NUMBER ADDED " << chosen << endl ;
// Sleep(10) ;
}
cout << "The 1500'th ugly number is " << array[1499] << "." <<endl ;
// Sleep(8000000) ;
return 0 ;
}
#include <cstdio>
//#include <windows.h>
using namespace std;
int main(){
long array[1500] ;
array[0] = 1 ;
int pointer_2 = 0;
int pointer_3 = 0;
int pointer_5 = 0;
for(int i = 1 ; i <=1500 ; i++){
// cout << "====== i:" << i << " ============================================================" <<endl ;
int test1 = 2 * array[pointer_2] ;
int test2 = 3 * array[pointer_3] ;
int test3 = 5 * array[pointer_5] ;
int chosen = min(test1, min(test2,test3)) ;
/*
cout << "test 1 = 2 * " << array[pointer_2] << " = "<< 2 * array[pointer_2] <<endl ;
cout << "test 2 = 3 * " << array[pointer_3] << " = "<<3 * array[pointer_3] <<endl ;
cout << "test 3 = 5 * " << array[pointer_5] << " = "<< 5 * array[pointer_5] <<endl ;
*/
if(chosen == test1){array[i] = test1 ; pointer_2++ ;
// cout << "pointer 2 updated , :" << pointer_2 <<endl ;
}
if(chosen == test2){array[i] = test2 ; pointer_3++ ;
// cout << "pointer 3 updated , :" << pointer_3 <<endl ;
}
if(chosen == test3){array[i] = test3 ; pointer_5++ ;
// cout << "pointer 5 updated , :" << pointer_5 <<endl ;
}
// cout << "NUMBER ADDED " << chosen << endl ;
// Sleep(10) ;
}
cout << "The 1500'th ugly number is " << array[1499] << "." <<endl ;
// Sleep(8000000) ;
return 0 ;
}
Posted by
erjan
another hint(INSPIRED from dp problem 136 - ugly numbers)
When you initalize array , make sure it has the right values :
if you look for min , make sure array values are not 0!
if you look for max - same
Know your values ahead!
min ( value1, value2 , value3 )
value2 = 0 , value 3 = 10 , value1 = 5 ; value2 MUST NOT be 0!
so i get this errors! - i can't find min
=========================================
omg, another insight -
know the index your for loop starts from!
my bug:
for(int i = 2 ; i < 1500 ; i++){
a[i] =......................
}
because of this i had zeros appearing in the computation!
"number added 2"
"number added 0"
"number added 3"
"number added 0"
"number added 4"
"number added 0"
"number added 5"
"number added 0"
"number added 6"
"number added 0"
"number added 8"
"number added 0"
"number added 10"
"number added 0"
the zeros were the bug - but i could not find them! Why because my array [1500] - were all zeros,
array:
1 0 0 0 0 0 0 0 0 0 0 0 0 0.............................
i started from here:
^
1 0 0 0 0 0 0 0 0 0 0 0 0 0.............................
but i should start from index 1 :
^
1 0 0 0 0 0 0 0 0 0 0 0 0 0.............................
if you look for min , make sure array values are not 0!
if you look for max - same
Know your values ahead!
min ( value1, value2 , value3 )
value2 = 0 , value 3 = 10 , value1 = 5 ; value2 MUST NOT be 0!
so i get this errors! - i can't find min
=========================================
omg, another insight -
know the index your for loop starts from!
my bug:
for(int i = 2 ; i < 1500 ; i++){
a[i] =......................
}
because of this i had zeros appearing in the computation!
"number added 2"
"number added 0"
"number added 3"
"number added 0"
"number added 4"
"number added 0"
"number added 5"
"number added 0"
"number added 6"
"number added 0"
"number added 8"
"number added 0"
"number added 10"
"number added 0"
the zeros were the bug - but i could not find them! Why because my array [1500] - were all zeros,
array:
1 0 0 0 0 0 0 0 0 0 0 0 0 0.............................
i started from here:
^
1 0 0 0 0 0 0 0 0 0 0 0 0 0.............................
but i should start from index 1 :
^
1 0 0 0 0 0 0 0 0 0 0 0 0 0.............................
Posted by
erjan
Odd sum uva 10783 - my solution with debugging statements
#include <iostream>
//#include <windows.h>
#include <stdio.h>
using namespace std ;
int main(){
int T ;
cin >> T ;
int a ;
int b ;
int test_case = 1;
for(int i = 0 ; i < T ; i++){
cin >> a ;
cin >> b ;
int sum = 0;
// cout << "sum " <<sum <<endl ;
for(int j = a ; j <= b ;j++ ) {
if( j % 2 != 0){//cout << "this aded: " << j <<endl ;
sum = sum + j ;}
}
printf("Case %d: %d\n", test_case,sum ) ;
test_case++ ;
// Sleep(20000) ;
}
return 0 ;
}
//#include <windows.h>
#include <stdio.h>
using namespace std ;
int main(){
int T ;
cin >> T ;
int a ;
int b ;
int test_case = 1;
for(int i = 0 ; i < T ; i++){
cin >> a ;
cin >> b ;
int sum = 0;
// cout << "sum " <<sum <<endl ;
for(int j = a ; j <= b ;j++ ) {
if( j % 2 != 0){//cout << "this aded: " << j <<endl ;
sum = sum + j ;}
}
printf("Case %d: %d\n", test_case,sum ) ;
test_case++ ;
// Sleep(20000) ;
}
return 0 ;
}
Posted by
erjan
lumberjack - found mistake uva 10973
#include <iostream>
//#include <windows.h>
using namespace std ;
bool check_increasing(int a[]){
// cout << "INCREASING " <<endl ;
for(int i = 0 ; i < 10 -1; i++){
// cout << "cmparing : " << a[i] << " < " << a[i+1] <<endl ;
if( a[i] > a[i+1] ) return false ;
}
return true ;
}
bool check_decreasing(int a[]){
for(int i = 0 ; i < 10-1 ; i++){
// cout << "cmparing : " << a[i] << " > " << a[i+1] <<endl ;
if( a[i] < a[i+1] ) return false ;
}
return true ;
}
int main(){
/*
int test1[] = {100, 88 , 65, 43 ,34,2003,11,7,6,5} ;
int test2[] = {1,2,3,4,5,2,7,8,9,10} ;
int test3[] = {13 ,25, 39, 40, 55 ,62, 68, 77, 88, 95 } ;
int test4[] = {88, 62, 77, 20, 40, 10, 99, 56, 45, 36 } ;
int test5[] = {91 ,78, 61, 59, 54, 49, 43, 33, 26, 18} ;
/*
3
13 25 39 40 55 62 68 77 88 95
88 62 77 20 40 10 99 56 45 36
91 78 61 59 54 49 43 33 26 18
bool x = check_decreasing(test5);
if(x) cout << "decre" <<endl ;
else cout << "wrong" <<endl ;
bool y = check_increasing(test3);
if(y) cout << "increasing " <<endl ;
else cout << "wrong" <<endl ;
*/
// Sleep(20000) ;
int N ;
cin >> N ;
cout << "Lumberjacks:" <<endl ;
for(int i = 0 ; i < N ; i++){
int beards[10] = {0} ;
for(int j = 0 ; j < 10 ; j++){
cin >> beards[j] ;
}
bool inc = check_increasing(beards) ;
bool dec = check_decreasing(beards) ;
if(inc || dec) cout << "Ordered"<<endl;
else cout << "Unordered"<<endl;
}
// Sleep(20000) ;
}
//#include <windows.h>
using namespace std ;
bool check_increasing(int a[]){
// cout << "INCREASING " <<endl ;
for(int i = 0 ; i < 10 -1; i++){
// cout << "cmparing : " << a[i] << " < " << a[i+1] <<endl ;
if( a[i] > a[i+1] ) return false ;
}
return true ;
}
bool check_decreasing(int a[]){
for(int i = 0 ; i < 10-1 ; i++){
// cout << "cmparing : " << a[i] << " > " << a[i+1] <<endl ;
if( a[i] < a[i+1] ) return false ;
}
return true ;
}
int main(){
/*
int test1[] = {100, 88 , 65, 43 ,34,2003,11,7,6,5} ;
int test2[] = {1,2,3,4,5,2,7,8,9,10} ;
int test3[] = {13 ,25, 39, 40, 55 ,62, 68, 77, 88, 95 } ;
int test4[] = {88, 62, 77, 20, 40, 10, 99, 56, 45, 36 } ;
int test5[] = {91 ,78, 61, 59, 54, 49, 43, 33, 26, 18} ;
/*
3
13 25 39 40 55 62 68 77 88 95
88 62 77 20 40 10 99 56 45 36
91 78 61 59 54 49 43 33 26 18
bool x = check_decreasing(test5);
if(x) cout << "decre" <<endl ;
else cout << "wrong" <<endl ;
bool y = check_increasing(test3);
if(y) cout << "increasing " <<endl ;
else cout << "wrong" <<endl ;
*/
// Sleep(20000) ;
int N ;
cin >> N ;
cout << "Lumberjacks:" <<endl ;
for(int i = 0 ; i < N ; i++){
int beards[10] = {0} ;
for(int j = 0 ; j < 10 ; j++){
cin >> beards[j] ;
}
bool inc = check_increasing(beards) ;
bool dec = check_decreasing(beards) ;
if(inc || dec) cout << "Ordered"<<endl;
else cout << "Unordered"<<endl;
}
// Sleep(20000) ;
}
Posted by
erjan
easy C to F conversion problem - uva , my implementation 11984
#include <iostream>
#include <stdio.h>
using namespace std ;
int main(){
int T ;
cin >> T ;
int i = T ;
int C ;
int d ;
float F ;
int num = 1 ;
while( i!= 0 ){
cin >> C ;
cin >> d ;
F = 9./5. * C + 32 ;
F = F + d ;
printf( "Case %d: %.2f\n",num, (5*F - 160 )/9. ) ;
num++ ;
i-- ;
}
return 0 ;
}
#include <stdio.h>
using namespace std ;
int main(){
int T ;
cin >> T ;
int i = T ;
int C ;
int d ;
float F ;
int num = 1 ;
while( i!= 0 ){
cin >> C ;
cin >> d ;
F = 9./5. * C + 32 ;
F = F + d ;
printf( "Case %d: %.2f\n",num, (5*F - 160 )/9. ) ;
num++ ;
i-- ;
}
return 0 ;
}
Posted by
erjan
Writing vs software eng. What is important?
If you say - i m a professional writer, and you never written any books BUT YOU VE READ 10K books in your life - and you are very proud of this list and show it to people.
What does it say about you ? People will know you are not a writer at all!
Writer's success is his books.
Same with developer! Learning is must for developer, but you get paid not for Knowledge, but for PROJECTS, RESULTS, APPS, business!
Posted by
erjan
I keep working understanding dp uva 147 -
This is a good table to see your results - nicely formatted!
public static void print_table( int table[][] ){
System.out.println( "\n\nPRINTING TABLE ") ;
System.out.println("\t\tm") ;
System.out.print("\n ") ;
for(int column = 0 ; column <= MAX_AMOUNT; column++){
System.out.print( column + " \t" ) ;
}
System.out.print("\n----------------------------------------------------------------------------------------------------------------------------------") ;
System.out.println("----------------------------------------------------------") ;
for(int i = 0 ; i <= NCHANGES ;i++){
System.out.print("[" + i + "]: ") ;
for(int j = 0 ; j <= MAX_AMOUNT ; j++){
System.out.print(table[i][j] + "\t") ;
}
System.out.println() ;
}
}
Posted by
erjan
Make very detailed debugging statements! uva 147 - dp solution with explanation
I figure out when i program - it is better to PRINT OUT ALL INFORMATION , ALL DATA FLOW - you must know everything that happens there!
a good print of what happens inside program UVA 147 dollars (dp)
In this program I only have 3 type of coins - 5c , 10c, 20c ; max amount 30 cents!
http://codepad.org/BypQJeDa
=================================================================
a good print of what happens inside program UVA 147 dollars (dp)
In this program I only have 3 type of coins - 5c , 10c, 20c ; max amount 30 cents!
http://codepad.org/BypQJeDa
=================================================================
EFORE THE FILLING TABLE , all ways to change(cells) are
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0
using coins 5,
cur amount(j): temp: (j- temp): ways[j]: ways[j- temp]: ways[j] + ways[j- temp]:
5 5 0 ways[5] = 0 ways[0] = 1 ways[5] + ways[0]= 1
6 5 1 ways[6] = 0 ways[1] = 0 ways[6] + ways[1]= 0
7 5 2 ways[7] = 0 ways[2] = 0 ways[7] + ways[2]= 0
8 5 3 ways[8] = 0 ways[3] = 0 ways[8] + ways[3]= 0
9 5 4 ways[9] = 0 ways[4] = 0 ways[9] + ways[4]= 0
10 5 5 ways[10] = 0 ways[5] = 1 ways[10] + ways[5]= 1
11 5 6 ways[11] = 0 ways[6] = 0 ways[11] + ways[6]= 0
12 5 7 ways[12] = 0 ways[7] = 0 ways[12] + ways[7]= 0
13 5 8 ways[13] = 0 ways[8] = 0 ways[13] + ways[8]= 0
14 5 9 ways[14] = 0 ways[9] = 0 ways[14] + ways[9]= 0
15 5 10 ways[15] = 0 ways[10] = 1 ways[15] + ways[10]= 1
16 5 11 ways[16] = 0 ways[11] = 0 ways[16] + ways[11]= 0
17 5 12 ways[17] = 0 ways[12] = 0 ways[17] + ways[12]= 0
18 5 13 ways[18] = 0 ways[13] = 0 ways[18] + ways[13]= 0
19 5 14 ways[19] = 0 ways[14] = 0 ways[19] + ways[14]= 0
20 5 15 ways[20] = 0 ways[15] = 1 ways[20] + ways[15]= 1
21 5 16 ways[21] = 0 ways[16] = 0 ways[21] + ways[16]= 0
22 5 17 ways[22] = 0 ways[17] = 0 ways[22] + ways[17]= 0
23 5 18 ways[23] = 0 ways[18] = 0 ways[23] + ways[18]= 0
24 5 19 ways[24] = 0 ways[19] = 0 ways[24] + ways[19]= 0
25 5 20 ways[25] = 0 ways[20] = 1 ways[25] + ways[20]= 1
26 5 21 ways[26] = 0 ways[21] = 0 ways[26] + ways[21]= 0
27 5 22 ways[27] = 0 ways[22] = 0 ways[27] + ways[22]= 0
28 5 23 ways[28] = 0 ways[23] = 0 ways[28] + ways[23]= 0
29 5 24 ways[29] = 0 ways[24] = 0 ways[29] + ways[24]= 0
30 5 25 ways[30] = 0 ways[25] = 1 ways[30] + ways[25]= 1
*****************************************************
using coins 5, 10,
cur amount(j): temp: (j- temp): ways[j]: ways[j- temp]: ways[j] + ways[j- temp]:
10 10 0 ways[10] = 1 ways[0] = 1 ways[10] + ways[0]= 2
11 10 1 ways[11] = 0 ways[1] = 0 ways[11] + ways[1]= 0
12 10 2 ways[12] = 0 ways[2] = 0 ways[12] + ways[2]= 0
13 10 3 ways[13] = 0 ways[3] = 0 ways[13] + ways[3]= 0
14 10 4 ways[14] = 0 ways[4] = 0 ways[14] + ways[4]= 0
15 10 5 ways[15] = 1 ways[5] = 1 ways[15] + ways[5]= 2
16 10 6 ways[16] = 0 ways[6] = 0 ways[16] + ways[6]= 0
17 10 7 ways[17] = 0 ways[7] = 0 ways[17] + ways[7]= 0
18 10 8 ways[18] = 0 ways[8] = 0 ways[18] + ways[8]= 0
19 10 9 ways[19] = 0 ways[9] = 0 ways[19] + ways[9]= 0
20 10 10 ways[20] = 1 ways[10] = 2 ways[20] + ways[10]= 3
21 10 11 ways[21] = 0 ways[11] = 0 ways[21] + ways[11]= 0
22 10 12 ways[22] = 0 ways[12] = 0 ways[22] + ways[12]= 0
23 10 13 ways[23] = 0 ways[13] = 0 ways[23] + ways[13]= 0
24 10 14 ways[24] = 0 ways[14] = 0 ways[24] + ways[14]= 0
25 10 15 ways[25] = 1 ways[15] = 2 ways[25] + ways[15]= 3
26 10 16 ways[26] = 0 ways[16] = 0 ways[26] + ways[16]= 0
27 10 17 ways[27] = 0 ways[17] = 0 ways[27] + ways[17]= 0
28 10 18 ways[28] = 0 ways[18] = 0 ways[28] + ways[18]= 0
29 10 19 ways[29] = 0 ways[19] = 0 ways[29] + ways[19]= 0
30 10 20 ways[30] = 1 ways[20] = 3 ways[30] + ways[20]= 4
*****************************************************
using coins 5, 10, 20,
cur amount(j): temp: (j- temp): ways[j]: ways[j- temp]: ways[j] + ways[j- temp]:
20 20 0 ways[20] = 3 ways[0] = 1 ways[20] + ways[0]= 4
21 20 1 ways[21] = 0 ways[1] = 0 ways[21] + ways[1]= 0
22 20 2 ways[22] = 0 ways[2] = 0 ways[22] + ways[2]= 0
23 20 3 ways[23] = 0 ways[3] = 0 ways[23] + ways[3]= 0
24 20 4 ways[24] = 0 ways[4] = 0 ways[24] + ways[4]= 0
25 20 5 ways[25] = 3 ways[5] = 1 ways[25] + ways[5]= 4
26 20 6 ways[26] = 0 ways[6] = 0 ways[26] + ways[6]= 0
27 20 7 ways[27] = 0 ways[7] = 0 ways[27] + ways[7]= 0
28 20 8 ways[28] = 0 ways[8] = 0 ways[28] + ways[8]= 0
29 20 9 ways[29] = 0 ways[9] = 0 ways[29] + ways[9]= 0
30 20 10 ways[30] = 4 ways[10] = 2 ways[30] + ways[10]= 6
*****************************************************
i:0,w[i]: 1 i:1,w[i]: 0 i:2,w[i]: 0 i:3,w[i]: 0 i:4,w[i]: 0 i:5,w[i]: 1 i:6,w[i]: 0 i:7,w[i]: 0 i:8,w[i]: 0 i:9,w[i]: 0
i:10,w[i]: 2 i:11,w[i]: 0 i:12,w[i]: 0 i:13,w[i]: 0 i:14,w[i]: 0 i:15,w[i]: 2 i:16,w[i]: 0 i:17,w[i]: 0 i:18,w[i]: 0 i:19,w[i]: 0
i:20,w[i]: 4 i:21,w[i]: 0 i:22,w[i]: 0 i:23,w[i]: 0 i:24,w[i]: 0 i:25,w[i]: 4 i:26,w[i]: 0 i:27,w[i]: 0 i:28,w[i]: 0 i:29,w[i]: 0
i:30,w[i]: 6
Posted by
erjan
Subscribe to:
Comments (Atom)
