Skip to content

Instantly share code, notes, and snippets.

View Krypton3's full-sized avatar
🏠
Working from home

H. M. Mahedi Hasan Krypton3

🏠
Working from home
View GitHub Profile
@Krypton3
Krypton3 / TIMUS1280
Created September 7, 2015 17:05
Topological Sorting.
#include<bits/stdc++.h>
using namespace std;
int graph[1001][1001];
int visited[1001];
int n,m,num,p,q;
int main()
{
memset(visited,0,sizeof(visited));
scanf("%d %d",&n,&m);
for(int i=0;i<m;i++){
@Krypton3
Krypton3 / Palindrom
Created September 7, 2015 13:43
TIMUS1297
#include<bits/stdc++.h>
using namespace std;
char str[1001];
int a,b,tot;
int check(int i,int j)
{
int a1=i;
int b1=j;
while(i<j){
if(str[i]!=str[j]){
@Krypton3
Krypton3 / Backtracking.
Created September 7, 2015 13:42
TIMUS1005
#include<bits/stdc++.h>
using namespace std;
int arr[21];
int minvalue;
int size;
int find(int current,int sum,int sum1)
{
if(current==size){
if((abs(sum-sum1))<minvalue){
minvalue=abs(sum-sum1);
@Krypton3
Krypton3 / Faster Approach
Created September 7, 2015 08:37
Exponent Function
#include<bits/stdc++.h>
using namespace std;
int EXP(int x,unsigned int n)
{
int temp;
if(n==0){
return 1;
}
if(n==1){
return x;
@Krypton3
Krypton3 / 10305 - Ordering Tasks
Created September 6, 2015 12:17
Topological Sort Basic
#include<bits/stdc++.h>
using namespace std;
class Graph
{
int V;
list<int> *adj;
void toposort(int v,bool visited[],stack<int> &stack);
public:
Graph(int V);
void addEdge(int v,int w);
@Krypton3
Krypton3 / nthMagicNumber
Created August 27, 2015 17:43
Basic Implementation.
//A magic number is defined as a number which can be expressed as a power of 5 or sum of unique powers of 5.
#include<bits/stdc++.h>
using namespace std;
int nthMagic(int num)
{
int res=0;
int p=1;
while(num){
p*=5;
if(num&1){
//Author: Krypton3
//Basic but need implementation.
//Help: http://www.geeksforgeeks.org/majority-element/
#include<bits/stdc++.h>
using namespace std;
int main()
{
int s = 0, num = 0, majority = 0, c = 1;
cin>>s>>majority;
@Krypton3
Krypton3 / 10550 - Combination Lock
Created August 25, 2015 07:14
uva online judge
//Author: Krypton3
import java.util.Scanner;
public class uva10550{
public static void main(String[] args){
Scanner key=new Scanner(System.in);
while(true){
int a=key.nextInt(), b=key.nextInt(),c=key.nextInt(),d=key.nextInt();
if(a==0 && b==0 && c==0 && d==0){
break;
}
@Krypton3
Krypton3 / 846 - Steps
Created August 25, 2015 06:45
846 - Steps (uva online judge)
//Author: Krypton3
import java.util.*;
public class uva846{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
int test=in.nextInt();
while(test-->0){
int x=in.nextInt(),y=in.nextInt();
int dist=y-x;
int steps=0;
@Krypton3
Krypton3 / ACM ICPC-2009
Created August 24, 2015 08:05
Probability One
//Author: Krypton3 and Rony_ghost
//Basic Math
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,t=1,ans;
while(scanf("%d",&n)==1){
if(n==0)break;