Tuesday, July 05, 2011

[UVa] 10611 - The Playboy Chimp

All you need is some knowledge of speeding up searching and some tricks to keep things in limits.

First of all, make the heights of the lady monkeys distinct and store them. You can use a map and store in it each height's position in the vector. That helps later.
Now you can make some decisions easily during the querries, if a querry has an index to it in the map then just go there. Check for the index to be boundary or not and print based on that. If however a height is not found, just browse you collection through linear search and make the same decision there. If a height is bigger than the biggest woman height or smaller than the smallest woman height you have a given advantage on it.

I think the vector is slowing it down. Gonna try an array.

#include <cstdio>
#include <map>
#include <iostream>
#include <climits>
#include <vector>


using namespace std;

map<int,int> ver;

vector<int>line;

int main()
{
    int i, j, k, wc, hc, minwh, maxwh, maxk, temp, x, y;

    line.push_back(-1);

    minwh = INT_MAX;
    maxwh = -1;
    scanf("%d",&wc);
    for (i=0, k=1 ; i<wc ; i++)
    {
        scanf("%d",&temp);
        if (ver[temp]==0)
        {
            line.push_back(temp);
            ver[temp]=k;
            k++;

            if (temp>maxwh)
                maxwh = temp;
            if (temp<minwh)
                minwh = temp;
        }
    }


    maxk = k;
    scanf("%d",&hc);

    for (i=0 ; i<hc ; i++)
    {
        scanf("%d",&temp);

        if (temp<minwh)
        {
            printf("X %d\n",line[0]);
            continue;
        } else if (temp>maxwh)
        {
            printf("%d X\n",line[maxk-1]);
            continue;
        }


        if (ver[temp])
        {
            k = ver[temp];
            if (k-1 < 0)
                x = -1;
            else
                x = line[k-1];

            if (k+1>=maxk)
                y = -1;
            else
                y = line[k+1];
        } else {
            for (j=1 ; j<maxk ; j++)
            {
                if (line[j]<temp && line[j+1]>temp)
                {
                    x = line[j];
                    y = line[j+1];
                }
            }
        }
        if (x<0) printf("X ");
        else printf("%d ",x);
        if (y<0) printf("X\n");
        else printf("%d\n",y);

    }

    return 0;
}

[UVa] 11247 - Income Tax Hazard

Simplification of the theorem solves the problem with a few glitches to overlook.
First of all v-(vx)/100 < m-1. Let q = m-1. Play with it for a while and you get => v < q/(100-x)/100 => v < 100q / (100-x) Don't ignore the < sign it will drag you by the nose for a while. So you generate a v from this. But realize if 100q is completely dividable by (100-x) then v must be smaller. So check if that happens. If it does, just decrease v by 1. And some other gotchas are x being m being 1 because you use m-1 and x being 0 or 100.


#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;

int main()
{
long long v, p, q;
long long m, x, orig_m;
while (cin >> m >> x)
{
if (!m && !x)
return 0;

if (m==1 || x==0 || x==100)
{
printf("Not found\n");
continue;
}

v = (100*(m-1)) / (100-x);

if (( (100*(m-1)) % (100-x) ) == 0)
v--;

if (v<m)
{
printf("Not found\n");

} else
{
cout << v << endl;
}
}
return 0;
}

Monday, July 04, 2011

[UVa] 138 - Street Numbers

I encountered this problem at the very beginning of my ACM days and was totally noobish. I played with the ratios a lot that I got from the outputs using doubles but the result never quite reached the points. I googled and found precalculations and theorems in Algorithmist. I just wanted to do it on my own.

Method:
1. Analyze for the first input:
SUM[X-Y] means summation of all the numbers from X to Y.
It's clear that
SUM[1-5] = SUM[1-8] - SUM[1-6]
So, 5*(5+1)/2 = 8*(8+1)/2 - 6*(6+1)/2
Now, think of 6 as Y, 5 as Y-1 and 8 as X.
So, we get
==> (Y-1)*(Y-1+1)/2 = X*(X+1)/2 - Y*(Y+1)/2
==> (Y-1)*Y/2 = X*(X+1)/2 - Y*(Y+1)/2
==> Y(Y-1) = X(X+1) - Y(Y+1)
==> Y(Y-1) + Y(Y+1) = X(X+1)
==> Y(Y-1+Y+1) = X(X+1)
==> Y(2Y) = X(X+1)
==> 2Y^2 = X(X+1)
==> 2Y^2 - X(X+1) = 0

So, we are simply looping from 1->INT_MAX so we have all the Ys. Just find if there is such an X that solves the equation. I coincidentally hit the theory that FLOORING of SQRT(2Y^2)is the only possible number.

#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
using namespace std;

int output[20][2]={0,0};

int main()
{

    freopen("out.txt","w+",stdout);
    double rupper, rlower;
    long long i, count, upper, lower;

    for (i=1, count=0 ; i<=INT_MAX && count<=10 ; i++)
    {
        upper = 2 * i * i;
        lower = sqrt(upper);

        if ((upper - (lower*lower) - lower)==0)
        {
            cout << "{" << i << "," << lower << "}," << endl;
            count++;
        }
    }

    return 0;

}

The output is generated in a file, named out.txt. Just make a program and initialize the array with the output. And print it.

Sunday, June 19, 2011

World itself is horrific enough, cut the digital crapheads

The era when I had started gaming the arena had all kinds of games that we see these days, no innovations till now. I ain't complaining, lovin' what it's already got. But not just all of it. I recently have found that I have an itch with horror, particularly zombie based games. Why, don't know. I hate to keep on killing stuff that is already so gone. Movies were enough with zombies and dead four legged human bellies/heads that come wanna mate with your head. But why games? I couldn't even start playing the popular zombie title "Resident Evil" 5 years back from now. I hated "The Thing". Not because of how damn thrilling some of its scenes were, but how aimless and pointless it is to kill four legged minis jumping at you. I can take four legged grenades anytime. I love the electro-magnets that come at you in Half-Life 2. They are so fun because of the technicality probably. But armies of the same old boring biological quadropods? Come on!!!. I completed the whole "Ravenholm" part in Half Life 2 that solely features on zombies. Though they were fun because of the blades that I could use with the Gravity gun. I even have finished Doom 3 two times because of the thrills I got from shadows caused by monsters walking overhead or corpses hanging in front of lights. I liked to kill the huge half zombie spiders but not all of them.

I think because of their walking abilities that game developers give them, these (>2)pods or multipods, if I may call them, are overused in every section right after the one they were first uncovered. It's sometimes a huge waste of your favorite Shotgun ammo or Chaingun ammo on these things, while you really wanna kill that howling boss with them. The problem with these overused elements in gaming is amplified when they make some irritating sounds. I remember swarms of spiders attacking in a game while make some ultra high frequency sound everytime they attack you. It was so painful I had to turn off my speakers. Millions of them around you, you need some time to kill them right? And I hated those Scorpion Kings in Serious Sam games. God those sounds. Whenever I heard them calling out, I wanted to just skip everything else and kill them.

Maybe that's what the Game developers want, to make them so irritating that you wanna kill 'em. But it also makes some levels disgusting to play. I always feel tired when I think about finishing them. I know how badly I waited for the Ravenholm episode to end before I could get back some fun. I even checked walkthroughs to find out if the game had any other practical levels later, or else I would have considered Half Life 2 an end right there.

Saturday, June 18, 2011

Just pass it around the table, you ain't drinkin' it anyway

Do we really know who we are?
I mean is it really possible to know what person you are?
I once had a friend who said that he didn't like to use DSP Plugins that come with computer applications like DFX. Why? I asked. And he said it was because the sound gets processed, he didn't like processed sound. I felt that something was wrong with his statement but due to my nature, I couldn't find it in the logic streams. Today, about 1 year later, when I somehow remembered that incident, it dawned to me. How does he know which is the real sound? How do you? How do I? Come to think of it.
If you're considering listening to some unprocessed music on your computer or on your mp3 player, what do you do? Simply use the player without DSP Plugins or any equalizer. Now, we all know that all these multimedia accessories come coded with sound engines of some kind that decode that sound data or the mp3 files that you give it. There is not only a single decoder for this task. Chinese, Japanese, American, Russian. Even if some of us techies come up with the counter argument that "All use LAME Decoder" or "Standard decoder is Fraunhofer IIS dude!" I'd say, even then it's not totally untouched. Some programmers might use extra commands available to them through those decoders. Like command line switches. Which should differ sounds
between players. Now imagine discovering that Sony devices sound crap compared to iPods. Why? Just because of the Headphones? We know Apple doesn't focus on headphones, Sony does. The clarity comes with a price then? Does it mean the real sound came with a price? I mean, think about your artist who availed you with that sound. Did he/she make several copies based on price? No!! Even if some of us use same decoders, the files themselves can sound different even on the same bitrates and all, due to the encoders used by different users when ripping the Sources.
This wasn't and still is not only about sounds. It's about reality itself. How do you know who you are? You've lived all these years, refined yourself through your experiences every second. Your mother tongue, your beliefs, your outlook to people who are not from your country all this was refined through society's interaction with you. Based on some of your instincts you chose what you wanted to be in your personality. Some of it you grabbed, some of it you just spit out, some of it you stood against and some of it you supported and wanted to be in others too. I don't know about you or your friends or your family or your president or our prime minister or my family or my friends. But what I feel like, after all this, that reality or who you are
is not what others tell you, what others want. It's what you want. No matter what, no matter how hard you try or how fast you run. You will ultimately come to the grounds of your own choices selecting what you want. Reality is inside you, how you want things defined around you. Remember those moments when no matter what you can't accept others? Why? And you never knew what you wanted before you were born. You were born to want these things. You were born with these wants, these essentialities, these needs.
How do you erase them? If you are a self defier, you'd try to defeat yourself and do everything opposite to what you want right? But that's you again. You the defier, it's what the defier wants. That reality taking over inside you. Defining you as the defier. So it's again what you want, that's defining reality for you than what anyone else in this world wants. If you are
a society defined person you are just doing what others want because that's what you want. To see that people like you. If you're a rebel then so be it. You fight society. Ultimately, that hard coded want in your self is something that no one can change. It's us that we can't change. It's us to live the way we were born to live, because of our wants.
Doesn't it sound like a control over us? Of course you should have seen it coming, the control of God? God has defined you, before you came here. He has already chosen what is going to happen and everything is happening just the way God has wanted. Through us. We say we change the future, but it's been already changed. The story of the universe has already been written. We are
the pen. Everybody, every single element is the pen. And these pens themeselves are the part of the story. This sounds so confusing to imagine but so clear if just gulped down. Just the way you accept yourself. You don't know why you want certain things but you just want it. You don't know why you can't forget or to stop thinking, it's just there and unchangeable.

Monday, May 23, 2011

IIUC Stubborns Standings

IIUC Tech Fest Intra University Programming Contest 2010:
Members:
  1. Shayhan Ameen
  2. Tafhim Ul Islam
  3. Alamgir Mikrani
Position:
  • 2nd


BUBT IUPC 2010:
Members:
  1. Shayhan Ameen
  2. Tafhim Ul Islam
  3. Alamgir Mikrani
Position:
  • 32nd

Daffodil IUPC 2010:
Members:
  1. Shayhan Ameen
  2. Tafhim Ul Islam
  3. Munaour Mehtab
Position:
  • 38th

IIUC IT Fest Inter University Programming Contest 2011:
Members:
  1. Shayhan Ameen
  2. Tafhim Ul Islam
  3. Rakibul Hassan
Position:
  • 2nd

CUET IUPC 2011:
Members:
  1. Shayhan Ameen
  2. Tafhim Ul Islam
  3. Rakibul Hassan
Position:
  • 7th
 


IIUC IT Fest 2011 IUPC

Team: IIUC Stubbornz (Replace the 'z' with 's', cuz it's changed now :))
Members: Me (Tafhim Ul Islam), Shayhan Ameen, Rakibul Hassan.

Was thinking a lot before posting something like this. Because we lost this position on the immediate contest that followed this in CUET. Anyways, it was our first success in a real time Inter University Contest. Arranged by my own varsity at our main Campus in the city outskirts, Kumira. I always had dreamed of winning a place like this in our home ground, never thought the hot summer day was gonna break it's sweat like this :).
The problem set mostly consisted of Ad-Hoc problems. As far as my skill is concerned, I have solved about 200 of this type at UVa. So it was an easy set for me. Wish we could solve some more, that would include the algorithmic ones, solving which sounds really cool.

At the initial phase we had gained the first position by solving two problems. The CUET team restlessly followed our trail to find the easy ones. By the time they were solving 2 problems we had already 3 ACs on our side. We were hungry for more, ravaging through the problem set trying to find something that was waiting for the bash. We were trying some tough ones and I totally forgot about a problem that I initially guessed was in my Expertise range, Strings. My team was trying out 2 other problems and with 3 hours gone and still stuck with 5th position, my heart was hammering for a 4th one, and it was definitely there, I just couldn't see it. Right then I saw a 2 page problem, name inspired by the Dan Brown novel "The lost symbol". I almost jumped, a sure AC now. I immediately dominated the workstation and read the problem statement and prepared string template at the same time. I didn't even read the intro parts, just what to do. I coded and it came up with correct answers. Submitted, "Wrong Answer". Changed some values and again "WA". I almost broke down, right before deciding to read the problem again. And there it was, right at the first paragraph, "distinct", in clear bold letters. I shouted and modified the code, some small debugging and Submit. "Yes", and we shouted like mad guys, I almost skipped a beat. We were in the second position. We tried some more problems, and reached one in the end but the time ran out.
In the end, we came 2nd. It was our first big success and we celebrated a lot. This one contest has changed our outlook towards our team a lot and has increased our performance dramatically. InshAllah, IIUC contest arena is gonna change again. And this time the crown will be for Stubborns.

Just 3 days after that we performed in CUET IUPC 2011 and got 7th position. Though it was not as expected, we definitely can say that our performance has increased dramatically.

Let's hope Allah (SWT) keeps his graceful eyes over us.

Connect Rapoo MT750S with Linux (Tested on Manjaro)

 I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...