Monday, January 18, 2016

New RUET Gate, RUET, Rajshahi







Solved UVA problem (code for bad horse using c/C++ programming)


using namespace std;

class Node{
public:
    string name;
    vector adj;
    bool visited;
    int groupId;

    Node(string str):name(str), visited(false), groupId(-1){}
    int getNeighborCount(){
        return adj.size();
    }
};

class graph{
public:
    unordered_map hashNode;
    vector nodes;

    void createNode(string str){
        Node* n = new Node(str);
        nodes.push_back(n);
        hashNode[str] = n;
    }
};

int main()
{
    freopen("A-small-practice-1.in", "r", stdin);
    freopen("A-small-practice-1.out", "w", stdout);
    int input_count;
    cin>>input_count;
    int counter = 1;
    while(input_count)
    {
        int M;
        cin>>M;
        graph G;
        for(int i=0;i        {
            string str1, str2;
            cin>>str1>>str2;
            g.AddEdge(str1,str2);
        }
        cout<<"Case #"<        input_count--;
    }
    return 0;
}


Solved uva programming problem Jolly Jumper C/C++ code Solution


#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define pi acos(-1.0)
#define N 1000000
#define long long LL
using namespace std;
int num[3010],n;
int diff[3005];
int k;
main()
{
    while(scanf("%d", &n)){
        for(int i=0;i         scanf("%d", &num[i]);
        k=1;
        for(int i =1; i           diff[k++]=abs(num[i]-num[i-1]);

    sort(diff+1,diff+k);
    bool yap=true;
    for(int i=1;i        if(diff[i]!=i){
            yap = false;
            break;
            }
    }
    if(yap) cout<<"Jolly"<    else cout<<"Not jolly"<    }
}

UVA 102 Ecological bin solved problem c/c++

// @BEGIN_OF_SOURCE_CODE

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define pi acos(-1.0)
#define N 1000000
#define long long LL
using namespace std;

int bottles [9 + 3];

int count_movement (int a, int b, int c)
{
    int m = 0;
    for ( int i = 0; i < 9; i++ ) {
        if ( i != a && i != b && i != c )
            m += bottles [i];
    }

    return m;
}

int main ()
{
    while ( scanf ("%d", &bottles [0]) != EOF ) {

        for ( int i = 1; i < 9; i++ )
            scanf ("%d", &bottles [i]);

        char output_str [3 + 3];
        int movements [6];
        int min_movement = INT_MAX;
        char combinations [6] [3 + 2] = {"BCG", "BGC", "CBG", "CGB", "GBC", "GCB"};

        // Brown index : 0 3 6
        // Green index : 1 4 7
        // Clear index : 2 5 8

        movements [0] = count_movement (0, 5, 7); // BCG
        movements [1] = count_movement (0, 4, 8); // BGC
        movements [2] = count_movement (2, 3, 7); // CBG
        movements [3] = count_movement (2, 4, 6); // CGB
        movements [4] = count_movement (1, 3, 8); // GBC
        movements [5] = count_movement (1, 5, 6); // GCB

        for ( int i = 0; i < 6; i++ ) {
            if ( movements [i] < min_movement ) {
                min_movement = movements [i];
                strcpy (output_str, combinations [i]);
            }
        }

        printf ("%s %d\n", output_str, min_movement);

    }

    return 0;
}

// @END_OF_SOURCE_CODE

Friday, January 31, 2014

Interrupts

Hardware interrupts were introduced as a way to reduce wasting the processor's valuable time in polling loops, waiting for external events. They may be implemented in hardware as a distinct system with control lines, or they may be integrated into the memory subsystem.
If implemented in hardware, an interrupt controller circuit such as the IBM PC's Programmable Interrupt Controller (PIC) may be connected between the interrupting device and the processor's interrupt pin to multiplex several sources of interrupt onto the one or two CPU lines typically available. If implemented as part of the memory controller, interrupts are mapped into the system's memory address space.
Interrupts can be categorized into these different types:
  • Maskable interrupt (IRQ): a hardware interrupt that may be ignored by setting a bit in an interrupt mask register's (IMR) bit-mask.
  • Non-maskable interrupt (NMI): a hardware interrupt that lacks an associated bit-mask, so that it can never be ignored. NMIs are used for the highest priority tasks such as timers, especially watchdog timers.
  • Inter-processor interrupt (IPI): a special case of interrupt that is generated by one processor to interrupt another processor in a multiprocessor system.
  • Software interrupt: an interrupt generated within a processor by executing an instruction. Software interrupts are often used to implement system calls because they result in a subroutine call with a CPU ring level change.
  • Spurious interrupt: a hardware interrupt that is unwanted. They are typically generated by system conditions such as electrical interference on an interrupt line or through incorrectly designed hardware.
Processors typically have an internal interrupt mask which allows software to ignore all external hardware interrupts while it is set. Setting or clearing this mask may be faster than accessing an interrupt mask register (IMR) in a PIC or disabling interrupts in the device itself. In some cases, such as the x86 architecture, disabling and enabling interrupts on the processor itself act as a memory barrier; however, it may actually be slower.
An interrupt that leaves the machine in a well-defined state is called a precise interrupt. Such an interrupt has four properties:
  • The Program Counter (PC) is saved in a known place.
  • All instructions before the one pointed to by the PC have fully executed.
  • No instruction beyond the one pointed to by the PC has been executed (that is no prohibition on instruction beyond that in PC, it is just that any changes they make to registers or memory must be undone before the interrupt happens).
  • The execution state of the instruction pointed to by the PC is known.
An interrupt that does not meet these requirements is called an imprecise interrupt.
The phenomenon where the overall system performance is severely hindered by excessive amounts of processing time spent handling interrupts is called an interrupt storm.

Microprocessor

micr

Assembly Language Program: Display a character and read two decimal digits and summation of some integer number

.model small
.stack 100h
.data
s1 db 'ENTER TWO NUMBER WHOSE SUM IS LESS THAN 10: $'
S2 DB 0AH,'THE SUM OF $'
S3 DB ' AND $'
S4 DB ' IS $'
A DB ?
B DB ?
C DB ?

.CODE

MAIN PROC

MOV AX,@DATA
MOV DS,AX

MOV AH,9
LEA DX,S1
INT 21H


MOV AH,2
MOV DL,0AH
INT 21H



MOV AH,2
MOV DL,'?'
INT 21H


MOV AH,1
INT 21H
MOV A,AL




MOV AH,1
INT 21H
MOV B,AL


MOV AH,9
LEA DX,S2
INT 21H

MOV AH,2
MOV DL,A
INT 21H

MOV AH,9
LEA DX,S3
INT 21H

MOV AH,2
MOV DL,B

INT 21H


MOV AH,9
LEA DX,S4
INT 21H

SUB A,48D
SUB B,48D
MOV AL,A
ADD AL,B
MOV C,AL

ADD C,48D



MOV AH,2
MOV DL,C

INT 21H

MOV AH,1
INT 21H

MOV AH,4CH
INT 21H

MAIN ENDP
END MAIN