UVA 1203 – Argus

#include <cstdio>
#include <queue>
#include <utility>
#include <cstring>
#include <iostream>
#include <functional>
using namespace std;

int main() {
    char s[20];
    int qnum, p, n;
    priority_queue<pair<int, pair >,
            vector<pair<int, pair > >,
            greater<pair<int, pair > > > pq;

    while (scanf("%s", s), strcmp("#", s)) {
        scanf("%d %d", &qnum, &p);
        pq.push(pair<int, pair >(p, pair(qnum, p)));
    }

    scanf("%d", &n);
    while (n--) {
        pair<int, pair > pr = pq.top();
        pq.pop();

        printf("%d\n", pr.second.first);

        pr.first += pr.second.second;
        pq.push(pr);
    }

    return 0;
}
Advertisements

Multi Threading in Java

While studying Java in my III Sem , i find out that there are many concepts that are lagging in best books about multi threading in java. I found out a good tutorial on multi threading which describes most of the things about multi threading including synchronization and deadlocks. I seriously find this topic to be hardest of java.

Here are the links:

  1. http://www.herongyang.com/Java/Thread-Execution-and-Multi-Threading-Programs.html : Thread Introduction with extremely good example giving output with explanation. Really awesome.
  2. http://www.herongyang.com/Java/Thread-Group-Class-and-system-ThreadGroup-Tree.html: About Thread Groups.
  3. http://www.herongyang.com/Java/Synchronization-Technique-and-Synchronized-Code-Blocks.html : Synchronization : Really Awesome with real world example.
  4. http://www.herongyang.com/Java/Deadlock-Condition-Example-Programs.html : A Good DeadLock Tutorial. Really Important . There are 2 real world examples. A Must look.