Algorithm Name: Kruskal
Algorithm Category: Graph search algorithm
Source Code:
Programming in UVa
Tuesday, August 26, 2014
Shortest path by Dijkstra
Algorithm Name: Dijkstra
Algorithm Category: Graph search algorithm
Source Code:
//////////////////////////////////////////////
// Bismillahir Rahmanir Rahim //
// Author : Shohan Ahmed Sijan //
// Country : Bangladesh //
// University : East West University //
/////////////////////////////////////////
#pragma warning(disable:4786)
#include
#include
#include
#include
using namespace std;
#define Max 999999999
#define Size 1009
int node,edge,cost[Size],path[Size],start,dest,sc,i,j,c,source,destination;
bool visit[Size];
pair p,pp;
queue< pair >q[Size];
void Dijkstra(int s,int d)
{
cost[s]=0;
priority_queue < pair >pq;
pq.push(pair(-cost[s],s));
while(pq.empty()==false)
{
p=pq.top();
pq.pop();
sc=p.second;
if(sc==d)break;
visit[sc]=true;
while(q[sc].empty()==false)
{
pp=q[sc].front();
q[sc].pop();
i=pp.first;
if(visit[i]==false && cost[sc]+pp.second(-cost[i],i));
}
}
}
}
void getpath(int d)
{
if(path[d]!=-1)
{
getpath(path[d]);
printf(" %d",d);
}
}
int main()
{
scanf("%d %d %d %d",&node,&edge,&source,&destination);
for(i=0;i<=node;i++)
{
cost[i]=Max;
visit[i]=false;
path[i]=-1;
while(q[i].empty()==false)
q[i].pop();
}
for(i=0;i(dest,c));
q[dest].push(pair(start,c));
}
Dijkstra(source,destination);
if(cost[destination]!=Max)
{
printf("Minimum cost is %d\n",cost[destination]);
printf("Path is:%d",source);
getpath(destination);
printf("\n");
}
else printf("Unreachable\n");
return 0;
}
Input:
5
5 7 1 5
1 2 3
2 3 2
1 5 7
5 4 2
3 4 5
1 4 4
3 5 4
Output:
Minimum cost is 6
Path is:1 4 5
Algorithm Category: Graph search algorithm
Source Code:
Input:
Output:
Monday, August 25, 2014
UVa Problem No:100 - The 3n + 1 problem
Source code of UVa Online Judge problem number: 100 - The 3n + 1 problem
Problem description: http://uva.onlinejudge.org/external/1/100.html
//////////////////////////////////////////////
// Bismillahir Rahmanir Rahim //
// Author : Shohan Ahmed Sijan //
// Country : Bangladesh //
// University : East West University //
/////////////////////////////////////////
#include
int main()
{
long long i,j,max,temp,count,ii;
while(scanf("%ld %ld",&ii,&j)!=EOF)
{
printf("%ld %ld",ii,j);
if(ii>j)
{
temp = ii;
ii = j;
j = temp;
}
max = 0;
for(i=ii;i<=j;i++)
{
temp = i;
count = 1;
if(temp>1)
{
do
{
if(temp%2==0)
temp=temp/2;
else
temp=temp*3+1;
count++;
}while(temp!=1);
}
if(count>max)
max = count;
}
printf(" %ld\n",max);
}
return 0;
}
Problem description: http://uva.onlinejudge.org/external/1/100.html
Saturday, January 8, 2011
Facebook Programing Contest
Facebook Hacker Cup have arranged a programing contest. If you want to participate it, just login your facebook than go to Facebook Hacker Cup.
Give a like & than click http://www.facebook.com/hackercup/problems.php?round=4
Best of lack...........:)
Give a like & than click http://www.facebook.com/hackercup/problems.php?round=4
Best of lack...........:)
Thursday, January 6, 2011
UVa Online Judge Membership
Its very easy.
Just go UVa Online Judge
and click Register
Then submit your Name , email address & password. Click "Results email:" for notification via e-mail.
Beginning knowledge for programming
You must Need a clear concept about this function, Variable & Statement for the programming. Click on the function and other to know about details on it.
Variable, Data type
printf
scanf
gets
if....else statement
looping(for,while,do-while)
strlen
NULL
Array
break statement
go to statement
pointer
Practise more & more for the clear concept.
Variable, Data type
printf
scanf
gets
if....else statement
looping(for,while,do-while)
strlen
NULL
Array
break statement
go to statement
pointer
Practise more & more for the clear concept.
Browse Problems
Problem Set Volume (problem 100 to 999)
Volume I ( problem 100 to 199)
................................................
Volume IX (problem 900 to 999)
Contest Volumes(problem 1000 to 11898)
Volume C (problem 10000 to 10099)
.........................................................
Volume CXVIII(problem 11800 to 11898)
Volume I ( problem 100 to 199)
................................................
Volume IX (problem 900 to 999)
Contest Volumes(problem 1000 to 11898)
Volume C (problem 10000 to 10099)
.........................................................
Volume CXVIII(problem 11800 to 11898)
Subscribe to:
Posts (Atom)
