Thursday, November 5, 2015

ACM problem set 10300 - Ecological Premium

Hello there.

Ecological premium is a very easy problem. Just you have to look at datatype. Consider following test case -


99999 99999 99999
99999 99999 99999
99999 99999 99999
99999 99999 99999
99999 99999 99999
99999 99999 99999
99999 99999 99999
99999 99999 99999
99999 99999 99999
99999 99999 99999


And following table is showing all fundamental integer types of variables in C:

Keyword Size Range Format Specifier
int 2 -32768 --> +32767 %d
long 4 -2,147,483,648 --> 2,147,438,647 %ld
long long 8 −9223372036854775807 --> +9223372036854775807 %lld
unsigned int 2 0 --> 65535 %u
unsigned long 4 0 --> 4,294,967,295 %lu
unsigned long long 8 0 --> 18446744073709551614 %llu

So carefully choice datatype.

Happy coding.

Friday, July 31, 2015

ACM problem set - 100 - The 3n+1 Problem

2 months ago when I have started solving ACM ad-hoc problems, I started with The 3n+1 problem. And I have failed to solve as usual. Then next few days I was thinking some complex solutions for that problem but my misfortune. I have failed again and again I have failed. 

Then I have focused on other ad-hoc problems. Solved some and learned that, "Sticky with Story!". The story of some ad-hoc problems have written in such way that readers started to think like they are going to solve a dynamic greedy np-hard problem. :D :D :D. One of my academic fellow who already competed regional math olympierd in Indonesia 2 times, he also gave-up ACM for this The 3n+1 problem!!

Here I am giving some clue for them who have tried this problem already and becoming frasted :)

clue 1: look at data type: declare all of your variables long (%ld)

clue 2: input would not always be given in sorted order. check whether first number < second number

clue 3: Show output in given order: If you swap first number and second number at the beginning of your program then be careful when showing output.

clue 4: If you got Time Limit Exit then check - does your program terminates correctly?
To terminate your program write program like this - 
while( scanf("%ld %ld", &firstNumber, &secondNumber) != EOF )
     // ... rest of your code ...

clue 5: The program algorithm is given in story. so you do not need to think about new algorithm.

clue 6: after each output there will be a new line. so,
printf("%ld %ld %ld\n", printNumberOne, printNumberTwo, output);

clue 7: debug, debug and debug if you get wrong output.

This problem is a Brute Force problem. so think straight.

Happy coding.

Thursday, July 16, 2015

ACM problem set - 10055 - Hashmat the Brave Warrior

Hello all. Today is my last fasting day of this Arabic fiscal year. I am preparing myself to celebrate EID-day tomorrow. But I am missing my family a lot. Without them nothing could be fulfilled.

Today I was looking into an acm problem 10055 - Hashmat the brave warrior. At first I was disappointed by the problem setter by thinking that, what a easy problem!  - Simple subtraction. And wrote code in 2 minutes and got 3 times penalty from online judge.  

What the hell!! simple subtraction :(
Then I read the problem again and again and found the tricks hidden in story. :)

You can try once. just find the tricks. you do not need to solve.

Happy coding.

Thursday, June 4, 2015

Do you know which windows port is used by Microsoft SQL Server?

The default TCP port of Microsoft SQL Server default instance is 1433. But if the named instance is different than default instance then SQL server could use different port. Here I found a useful script to find out which TCP port is currently used by SQL server.




    SET @RegLoc='Software\Microsoft\MSSQLServer\MSSQLServer\SuperSocketNetLib\Tcp\' 
    SET @RegLoc='Software\Microsoft\Microsoft SQL Server\' + @InstName + '\MSSQLServer\SuperSocketNetLib\Tcp\' 

EXEC [master].[dbo].[xp_regread] 'HKEY_LOCAL_MACHINE', @RegLoc, 'tcpPort'

Now, why it is important to know this TCP port number?
If you are planning to access database from remote computer and/or
if the firewall of your computer is opened then you have to allow that TCP port number as exception.

Thats it.

Happy Coding.

Sunday, April 19, 2015

Subversion cleanup issue.

I have been using subversion for last two years. TortoiseSVN is a great free subversion client for freelancer like me. Although I am using AnkhSVN subversion client to manage subversion from Visual Studio IDE. Today during work, I have deleted a folder manually from my project working directory. After that my nightmare has just began. Whenever I was trying to commit/update/revert/unlock my project, it was showing a nice error "Previous operation has not finished: run 'cleanup' if it was interrupted". Sometimes the error text was different but was containing at-least "cleanup" word. Like, "Please execute the 'Cleanup' command". Well, there is a cleanup button in both TortoiseSVN and AnkhSVN subversion client. But same error was showing after clicking cleanup button too.

It was clear to me that, I was ended up in such issue, which was not possible to resolve by my subversion client. After a long time I have found a solution in stackoverflow. Subversion repository is using a internal SQLite database (wc.db in .svn folder) which contains a table named work_queue. Whenever we are trying to do an event, subversion repository searches previous pending task in that table and compare current task with that pending task and forward.

The solution was to delete all entries of work_queue table. There is an executable file of SQLite in SQLite official website. Download and unzip in project working directory. Then run the following command from windows command prompt(cmd.exe) to see the pending tasks -

sqlite3.exe .svn/wc.db "select * from work_queue"

To delete all old pending task, run the following command

sqlite3.exe .svn/wc.db "delete from work_queue"

Then try again "Cleanup" from subversion client. 
Hope this will help to get rid of this cleanup issue. 

Happy coding.