-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f3158ed
Showing
57 changed files
with
5,242 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/** | ||
* Author: Ashraful Islam Rafi | ||
* University: Leading University,Sylhet | ||
* url: http://www.lightoj.com/volume_showproblem.php?problem=1002 | ||
* problem id: 1002 - Country Roads | ||
* complexity: 2nd level(mst) | ||
* site: Lightoj.com | ||
**/ | ||
#include"map" | ||
#include"set" | ||
#include"queue" | ||
#include"cmath" | ||
#include"stack" | ||
#include"ctype.h" | ||
#include"cstdio" | ||
#include"vector" | ||
#include"cstdio" | ||
#include"cstring" | ||
#include"cstdlib" | ||
#include"string.h" | ||
#include"iostream" | ||
#include"algorithm" | ||
using namespace std; | ||
#define cs "Case "<<++casee<<": " | ||
#define csE "Case "<<++casee<<":\n" | ||
#define sf(t) scanf("%d",&t) | ||
#define sNE(n,e) scanf("%d %d",&N,&E) | ||
#define Inf 1000000000 | ||
#define S_N 5000010 | ||
#define MST(a, tf) memset(a, tf, sizeof (a)) | ||
int N,E; | ||
int edge[505][16010]; | ||
int arr[20010]; | ||
struct node | ||
{ | ||
int cost,vertex,mxcost; | ||
}; | ||
bool operator<(node a,node b) | ||
{ | ||
return a.cost>b.cost; | ||
} | ||
void mst(int st) | ||
{ | ||
bool visited[505]; | ||
MST(visited,false); | ||
node temp; | ||
temp.cost=0; temp.vertex=st; temp.mxcost=0; | ||
priority_queue<node>pq; | ||
pq.push(temp); | ||
int ans=0; | ||
while(!pq.empty()) | ||
{ | ||
node cur=pq.top(); pq.pop(); | ||
if(visited[cur.vertex]) continue; | ||
visited[cur.vertex]=true; | ||
///ans+=cur.mxcost; | ||
arr[cur.vertex]=cur.mxcost; | ||
for(int i=0;i<N;i++) | ||
{ | ||
if(edge[cur.vertex][i]>=0 && edge[cur.vertex][i]<20005 ) | ||
{ | ||
/**node t; | ||
t.cost=edge[cur.vertex][i]; | ||
t.vertex=i; | ||
if(visited[i]==false) pq.push(t);*/ | ||
node t; | ||
t.cost=edge[cur.vertex][i]; | ||
t.mxcost=max(cur.mxcost,edge[cur.vertex][i]); | ||
t.vertex=i; | ||
if(visited[i]==false) pq.push(t); | ||
} | ||
} | ||
} | ||
// cout<<csE; | ||
for(int i=0;i<N;i++) | ||
{ | ||
if(arr[i]!=-1) printf("%d\n",arr[i]); | ||
else printf("Impossible\n"); | ||
} | ||
} | ||
int main() | ||
{ | ||
int t; sf(t);int casee=0; | ||
while(t--) | ||
{ | ||
sNE(N,E); MST(arr,-1); MST(edge,20010); | ||
for(int j=0;j<E;j++) | ||
{ | ||
int u,v,c; sf(u);sf(v);sf(c); | ||
c=min(edge[u][v],c); | ||
edge[u][v]=edge[v][u]=c; | ||
} | ||
int start;sf(start); cout<<csE; | ||
mst(start); | ||
} | ||
} | ||
|
||
|
||
|
||
///---test case--/// | ||
/** | ||
2 | ||
5 6 | ||
0 1 5 | ||
0 1 4 | ||
2 1 3 | ||
3 0 7 | ||
3 4 6 | ||
3 1 8 | ||
1 | ||
5 4 | ||
0 1 5 | ||
0 1 4 | ||
2 1 3 | ||
3 4 7 | ||
1 | ||
Case 1: | ||
4 | ||
0 | ||
3 | ||
7 | ||
7 | ||
Case 2: | ||
4 | ||
0 | ||
3 | ||
Impossible | ||
Impossible | ||
**/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/** | ||
* Author: Ashraful Islam Rafi | ||
* University: Leading University,Sylhet | ||
* url: http://www.lightoj.com/volume_showproblem.php?problem=1005 | ||
* problem id: 1005 - Rooks | ||
* complexity: 2nd level(DP) | ||
* site: Lightoj.com | ||
**/ | ||
|
||
#include"map" | ||
#include"set" | ||
#include"queue" | ||
#include"cmath" | ||
#include"stack" | ||
#include"ctype.h" | ||
#include"cstdio" | ||
#include"vector" | ||
#include"cstdio" | ||
#include"cstring" | ||
#include"cstdlib" | ||
#include"string.h" | ||
#include"iostream" | ||
#include"algorithm" | ||
using namespace std; | ||
#define cs "Case "<<++casee<<": " | ||
#define csE "Case "<<++casee<<":\n" | ||
#define cs "Case "<<++casee<<": " | ||
#define csE "Case "<<++casee<<":\n" | ||
#define sf(t) scanf("%d",&t) | ||
#define sNE(n,e) scanf("%d %d",&N,&E) | ||
#define Inf 1000000000 | ||
#define S_N 5000010 | ||
#define size_N 10000000 | ||
#define size_P 1000000 | ||
#define MST(a, tf) memset(a, tf, sizeof (a)) | ||
typedef unsigned long long ULL; | ||
|
||
ULL ncr[31][31]; | ||
ULL fact[31]; | ||
|
||
void Binomial() | ||
{ | ||
ncr[0][0]=0; | ||
for(int i=1; i <=30 ;i++) | ||
{ | ||
ncr[0][i]=0; ncr[i][0] = 1; | ||
} | ||
ncr[1][1]=1; fact[0]=1; fact[1]=1; | ||
|
||
for(int i= 2;i<=30 ;i++) | ||
{ | ||
fact[i] = i * fact[i-1]; | ||
for(int k=1;k<=i;k++) | ||
ncr[i][k] = ncr[i-1][k-1] + ncr[i-1][k]; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
Binomial(); ULL n, k; | ||
|
||
/**for(int i=0; i <=30 ;i++) | ||
for(int j=0;j<=30;j++) | ||
clog<<ncr[i][j]<<" "; | ||
clog<<endl;*/ | ||
/**for(int i=0;i<30;i++) clog<<fact[i]<<" "; clog<<endl;*/ | ||
|
||
int t;sf(t); int casee=0; | ||
while(t--) | ||
{ | ||
cin>>n>>k; | ||
if(k>n) | ||
{ | ||
cout<<cs<< "0\n"; continue; | ||
} | ||
clog<<ncr[n][k]<<" "<<fact[k]<<endl; | ||
cout <<cs<<(ncr[n][k] * ncr[n][k] )* fact[k] <<endl; | ||
} | ||
return 0; | ||
} | ||
/** | ||
15 | ||
1 1 | ||
2 1 | ||
3 1 | ||
4 1 | ||
4 2 | ||
4 3 | ||
4 4 | ||
4 5 | ||
1 0 | ||
30 1 | ||
30 20 | ||
30 2 | ||
1 0 | ||
Case 1: 1 | ||
Case 2: 4 | ||
Case 3: 9 | ||
Case 4: 16 | ||
Case 5: 72 | ||
Case 6: 96 | ||
Case 7: 24 | ||
Case 8: 0 | ||
Case 9: 1 | ||
Case 10: 900 | ||
Case 11: 353469769534668800 | ||
Case 12: 378450 | ||
Case 13: 1 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
* Author: Ashraful Islam Rafi | ||
* University: Leading University,Sylhet | ||
* url: http://www.lightoj.com/volume_showproblem.php?problem=1007 | ||
* problem id: 1007 - Mathematically Hard | ||
* complexity: 2nd level(DP) | ||
* site: Lightoj.com | ||
**/ | ||
|
||
#include"map" | ||
#include"set" | ||
#include"queue" | ||
#include"cmath" | ||
#include"stack" | ||
#include"ctype.h" | ||
#include"cstdio" | ||
#include"vector" | ||
#include"cstdio" | ||
#include"cstring" | ||
#include"cstdlib" | ||
#include"string.h" | ||
#include"iostream" | ||
#include"algorithm" | ||
using namespace std; | ||
#define cs "Case "<<++casee<<": " | ||
#define csE "Case "<<++casee<<":\n" | ||
#define INF 1000000000 | ||
#define N 5000010 | ||
#define MST(a, tf) memset(a, tf, sizeof (a)) | ||
|
||
using namespace std; | ||
|
||
bool visited [N]; | ||
unsigned long long RelativPrm[N],sum; | ||
|
||
void sieve () | ||
{ | ||
MST(visited,true); | ||
visited[0]= visited[1]=false; | ||
for(int i=4; i<N; i+=2 ) visited[i]= false; | ||
///for(int i=0;i<100;i++) cout<<i<<" : "<<visited[i]<<"\n"; | ||
for(int i=0; i<N; i++) RelativPrm[i] =i; | ||
///for(int i=0;i<100;i++) cout<<i<<" : "<<RelativPrm[i]<<"\n"; | ||
|
||
for(int i=2; i<=N; i++) | ||
{ | ||
if(visited[i]) | ||
{ | ||
for(int j=i; j<N; j += i) | ||
{ | ||
visited[j]=false; | ||
RelativPrm[j] = (RelativPrm[j] / i) * (i-1); | ||
} | ||
} | ||
} | ||
///---to see the relative primes open dis--// | ||
/** | ||
for(int i=0;i<100;i++) cout<<i<<" : "<<RelativPrm[i]<<"\n"; | ||
*/ | ||
} | ||
|
||
void Squire_Sum() | ||
{ | ||
for(int i=1; i<N; i++ ) | ||
{ | ||
sum = RelativPrm[i] * RelativPrm[i]; | ||
RelativPrm[i] = sum + RelativPrm[i-1]; | ||
} | ||
///---to see the squire sum of relative primes open dis--// | ||
/** | ||
for(int i=1;i<100;i++) cout<<i<<" : "<<RelativPrm[i]<<endl; | ||
*/ | ||
} | ||
int main() | ||
{ | ||
sieve(); | ||
Squire_Sum(); | ||
int t; scanf ("%d", &t); | ||
int casee=0; | ||
while(t--) | ||
{ | ||
int a,b; scanf ("%d %d",&a,&b); | ||
cout<<cs<<RelativPrm[b] - RelativPrm[a-1]<<endl; | ||
} | ||
return 0; | ||
} | ||
///--test casee--/// | ||
/** | ||
5 | ||
2 5000000 | ||
5000000 5000000 | ||
4000000 5000000 | ||
4999999 5000000 | ||
4999999 4999999 | ||
Case 1: 17843739680429560645 | ||
Case 2: 4000000000000 | ||
Case 3: 8707753927266037000 | ||
Case 4: 28999980000004 | ||
Case 5: 24999980000004 | ||
*/ |
Oops, something went wrong.