algoshare.blogspot.com
Algorithm Share: December 2014
http://algoshare.blogspot.com/2014_12_01_archive.html
We learn by sharing. Sunday, December 28, 2014. 591: box of bricks. This problem is pretty straightforward except for one very bad trick. The problem requires outputting a blank line for every set processed. I got caught here and got a wrong answer in my first try. Int n, i, fair, x, moves, k;. For (k = 1; 1; k = 1) {. Sscanf(line, "%d", &n);. Pch = strtok(line, " t n");. H[i] = atoi(pch);. Pch = strtok(NULL, " t n");. Fair = 0;. For (i = 0; i n; i = 1) {. Fair = h[i];. Fair /= n;. Moves = 0;. X = h[i];.
algoshare.blogspot.com
Algorithm Share: 10370: Above average
http://algoshare.blogspot.com/2015/01/10370-above-average.html
We learn by sharing. Friday, January 23, 2015. For this problem, the problem seems to be parsing, because the inputs can have newlines inserted randomly between them. so what i did was to just keep parsing out numbers from the input regardless if the number comes after a space or a newline. just keep parsing numbers. Int num cases, num students;. Int students processed, cases processed;. Int x, i, num above;. Float above percentage;. 1 obtained num cases. 2 obtained num students. 3 all cases processed.
algoshare.blogspot.com
Algorithm Share: 113: power of cryptography
http://algoshare.blogspot.com/2015/01/113-power-of-cryptography.html
We learn by sharing. Saturday, January 24, 2015. 113: power of cryptography. I looked at the discussions in the Internet and discovered that you could actually just use double type, which is kind of smart. double type can handle numbers as large as 10 300. float type however cannot do because float I think can only handle up to 10 38. Using double gives us a whole range of mathematical powers. We can use the cmath library to raise the number p to the fraction (1/n) to get the nth root of p.
algoshare.blogspot.com
Algorithm Share: July 2013
http://algoshare.blogspot.com/2013_07_01_archive.html
We learn by sharing. Saturday, July 27, 2013. A break from the pain of thinking. Cutest chick i'd ever seen! Links to this post. Subscribe to: Posts (Atom). A break from the pain of thinking. Ethereal template. Powered by Blogger.
algoshare.blogspot.com
Algorithm Share: November 2009
http://algoshare.blogspot.com/2009_11_01_archive.html
We learn by sharing. Sunday, November 1, 2009. 11044: Searching for Nessy. 000 #include stdio.h. 002 int main() {. 003 char line[100];. 006 fgets(line, 100, stdin);. 007 sscanf(line, "%d", &t);. 009 for (i = 0; i t; i = 1) {. 010 fgets(line, 100, stdin);. 011 sscanf(line, "%d %d", &n, &m);. 013 n -= 2;. 014 nq = n / 3;. 015 nr = n % 3;. 016 if (nr) {. 017 nq = 1;. 020 m -= 2;. 021 mq = m / 3;. 022 mr = m % 3;. 023 if (mr) {. 024 mq = 1;. 027 s = nq * mq;. 028 printf("%d n", s);. 031 return 0;. 034 return...
algoshare.blogspot.com
Algorithm Share: January 2015
http://algoshare.blogspot.com/2015_01_01_archive.html
We learn by sharing. Saturday, January 31, 2015. 108: Maximum sum (continued). The problem with an O(n 6) algorithm is that you get a time limit error in UVA. Forums claim that you need an O(n 4) algorithm or better to have your code accepted. According to the algorithmist, if you use kadane's algorithm, you can reach an astonishing O(n 3): only 3 for loop implementation which has very fast execution time. Forums recommend using dynamic programming too. Which makes sense in our case, right? Consider the ...
algoshare.blogspot.com
Algorithm Share: 108: Maximum sum (continued)
http://algoshare.blogspot.com/2015/01/108-maximum-sum-continued.html
We learn by sharing. Saturday, January 31, 2015. 108: Maximum sum (continued). The problem with an O(n 6) algorithm is that you get a time limit error in UVA. Forums claim that you need an O(n 4) algorithm or better to have your code accepted. According to the algorithmist, if you use kadane's algorithm, you can reach an astonishing O(n 3): only 3 for loop implementation which has very fast execution time. Forums recommend using dynamic programming too. Which makes sense in our case, right? Consider the ...
algoshare.blogspot.com
Algorithm Share: August 2012
http://algoshare.blogspot.com/2012_08_01_archive.html
We learn by sharing. Tuesday, August 14, 2012. First, I explain the data structures used. Several array variables are utilized. In the real world, one would not do this to implement the algorithm to this problem. In the real world, one would probably use object-oriented programming and classes to implement the algorithm. However, once again, as the emphasis of UVA problems is speed rather than beauty, I resorted to this rather ugly but probably faster code implementation. We have explained the arrays, ar...
algoshare.blogspot.com
Algorithm Share: 10189: Minesweeper
http://algoshare.blogspot.com/2015/01/it-has-been-more-than-5-years-i-guess.html
We learn by sharing. Friday, January 23, 2015. The algorithm I used was first to create an initialized array. For a 3x5 array, it would look something like this:. The u's above represent uninitialized data table. they can be random initially. but notice that after initialization, you have dash characters surrounding the data table. We then read the input into the array:. We then process each element in the data table one element at a time. Again we count the number of bombs for this 3x3 matrix. One thing...
algoshare.blogspot.com
Algorithm Share: 108: Maximum sum
http://algoshare.blogspot.com/2015/01/108-maximum-sum.html
We learn by sharing. Saturday, January 31, 2015. The first time I saw this problem was about in year 2006. The problem was in a programming contest orientation. Back then, I remember I think I was able to solve the problem. So this time, when I saw the same problem in uVA after more than 9 years, I was pretty confident I could resolve the problem. For () { for (.) { for (.) { for (.) {.} } } }. My original algorithm uses a brute force approach and considers all possible rectangles beginning with 1x1 rect...