forked from Cyitao/-BAT-
-
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.
Signed-off-by: Cyitao <[email protected]>
- Loading branch information
Showing
57 changed files
with
748 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,20 @@ | ||
#include<iostream> | ||
#include<vector> | ||
using namespace std; | ||
#define Mod 1000000007 | ||
class Ants { | ||
public: | ||
vector<int> collision(int n) | ||
{ | ||
int down=pow(2.0,n),up=down-2; | ||
int temp=gcd(up,down); | ||
vector<int> res; | ||
res.push_back(up/temp); | ||
res.push_back(down/temp); | ||
return res; | ||
} | ||
int gcd(int x,int y) | ||
{ | ||
return (!y)?x:gcd(y,x%y); | ||
} | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,31 @@ | ||
#include<iostream> | ||
#include<vector> | ||
using namespace std; | ||
#define Mod 1000000007 | ||
class Championship { | ||
public: | ||
vector<int> calc(int k) | ||
{ | ||
vector<int> res; | ||
int up=1,down=1,i=2*k-1; | ||
while(i>0) | ||
{ | ||
down*=i; | ||
i=i-2; | ||
} | ||
i=k+1; | ||
while(i>2) | ||
{ | ||
up*=i; | ||
i--; | ||
} | ||
int Com=gcd(down-up,down); | ||
res.push_back((down-up)/Com); | ||
res.push_back(down/Com); | ||
return res; | ||
} | ||
int gcd(int x, int y) | ||
{ | ||
return (!y)?x:gcd(y,x%y); | ||
} | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,23 @@ | ||
#include<iostream> | ||
#include<vector> | ||
using namespace std; | ||
class RandomP { | ||
public: | ||
static int f(); | ||
}; | ||
|
||
class Random01 { | ||
public: | ||
// ÓÃRandomP::f()ʵÏֵȸÅÂʵÄ01·µ»Ø | ||
int random01() | ||
{ | ||
int a,b; | ||
while(1) | ||
{ | ||
a=RandomP::f(); | ||
b=RandomP::f(); | ||
if(a!=b) | ||
return (a>b)?0:1; | ||
} | ||
} | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,25 @@ | ||
#include<iostream> | ||
#include<vector> | ||
using namespace std; | ||
// 以下内容请不要修改 | ||
class Random5 { | ||
public: | ||
static int randomNumber(); | ||
}; | ||
|
||
class Random7 { | ||
public: | ||
int rand5() { | ||
return Random5::randomNumber(); | ||
} | ||
// 以上内容请不要修改 | ||
|
||
|
||
int randomNumber() | ||
{ | ||
int a=5*(rand5()-1)+rand5()-1; | ||
while(a>20) | ||
a=5*(rand5()-1)+rand5()-1; | ||
return a%7+1; | ||
} | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,20 @@ | ||
#include<iostream> | ||
using namespace std; | ||
class RandomSeg { | ||
public: | ||
// 等概率返回[0,1) | ||
double f() { | ||
return rand() * 1.0 / RAND_MAX; | ||
} | ||
// 通过调用f()来实现 | ||
double random(int k, double x) | ||
{ | ||
double res=-1; | ||
for(int i=0;i<k;i++) | ||
{ | ||
double b=f(); | ||
res=(res>b)?res:b; | ||
} | ||
return res; | ||
} | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,17 @@ | ||
#include<iostream> | ||
#include<vector> | ||
using namespace std; | ||
class RandomPrint { | ||
public: | ||
vector<int> print(vector<int> arr, int N, int M) | ||
{ | ||
vector<int> res; | ||
for(int i=0;i<M;i++) | ||
{ | ||
int pos=rand()%(N-i); | ||
res.push_back(arr[pos]); | ||
swap(arr[pos],arr[N-i-1]); | ||
} | ||
return res; | ||
} | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,36 @@ | ||
#include<iostream> | ||
#include<vector> | ||
using namespace std; | ||
class Backpack { | ||
public: | ||
int maxValue(vector<int> w, vector<int> v, int n, int cap) | ||
{ | ||
int **dp=new int*[n+1]; | ||
for(int i=0;i<n+1;i++) | ||
dp[i]=new int[cap+1]; | ||
for(int i=0;i<n+1;i++) | ||
dp[i][0]=0; | ||
for(int i=0;i<cap+1;i++) | ||
dp[0][i]=0; | ||
for(int i=1;i<n+1;i++) | ||
for(int j=1;j<cap+1;j++) | ||
{ | ||
int temp=dp[i-1][j]; | ||
if(j-w[i-1]>=0) | ||
temp=max(temp,dp[i-1][j-w[i-1]]+v[i-1]); | ||
dp[i][j]=temp; | ||
} | ||
return dp[n][cap]; | ||
} | ||
}; | ||
|
||
int main() | ||
{ | ||
int a[8]={42,25,30,35,42,21,26,28}; | ||
int b[8]={261,247,419,133,391,456,374,591}; | ||
vector<int> arr(a,a+8); | ||
vector<int> brr(b,b+8); | ||
Backpack B; | ||
cout<<B.maxValue(arr,brr,8,297); | ||
return 0; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,41 @@ | ||
#include<iostream> | ||
#include<vector> | ||
using namespace std; | ||
class LCS { | ||
public: | ||
int findLCS(string A, int n, string B, int m) | ||
{ | ||
int **dp=new int*[n]; | ||
for(int i=0;i<n;i++) | ||
dp[i]=new int[m]; | ||
for(int i=0,temp=0;i<n;i++) | ||
{ | ||
if(B[0]==A[i]) | ||
temp=1; | ||
dp[i][0]=temp; | ||
} | ||
for(int i=0,temp=0;i<m;i++) | ||
{ | ||
if(A[0]==B[i]) | ||
temp=1; | ||
dp[0][i]=temp; | ||
} | ||
for(int i=1;i<n;i++) | ||
for(int j=1;j<m;j++) | ||
{ | ||
int m=max(dp[i-1][j],dp[i][j-1]); | ||
if(A[i]==B[j]) | ||
m=max(dp[i-1][j-1]+1,m); | ||
dp[i][j]=m; | ||
} | ||
return dp[n-1][m-1]; | ||
} | ||
}; | ||
|
||
int main() | ||
{ | ||
string A="1A2C3D4B56",B="B1D23CA45B6A"; | ||
LCS f; | ||
cout<<f.findLCS(A,10,B,12); | ||
return 0; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,26 @@ | ||
#include<iostream> | ||
#include<vector> | ||
using namespace std; | ||
class LongestIncreasingSubsequence { | ||
public: | ||
int getLIS(vector<int> A, int n) | ||
{ | ||
int *dp=new int[n],res=0; | ||
dp[0]=1; | ||
for(int i=1;i<A.size();i++) | ||
{ | ||
int max=0,j=0; | ||
while(j<i) | ||
{ | ||
if(A[j]<A[i]&&dp[j]>max) | ||
max=dp[j]; | ||
j++; | ||
} | ||
dp[i]=max+1; | ||
} | ||
for(int i=0;i<A.size();i++) | ||
if(res<dp[i]) | ||
res=dp[i]; | ||
return res; | ||
} | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,16 @@ | ||
#include<iostream> | ||
#include<vector> | ||
using namespace std; | ||
#define Mod 1000000007 | ||
class GoUpstairs { | ||
public: | ||
int countWays(int n) | ||
{ | ||
int *dp=new int[n]; | ||
dp[0]=1; | ||
dp[1]=2; | ||
for(int i=2;i<n;i++) | ||
dp[i]=(dp[i-1]+dp[i-2])%Mod; | ||
return dp[n-1]; | ||
} | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,113 @@ | ||
#include<iostream> | ||
#include<vector> | ||
using namespace std; | ||
//动态规划 | ||
class Exchange { | ||
public: | ||
int countWays(vector<int> penny, int n, int aim) | ||
{ | ||
if(n==0||aim<0) | ||
return 0; | ||
int **map=new int*[n]; | ||
for(int i=0;i<n;i++) | ||
map[i]=new int[aim+1]; | ||
for(int i=0;i<n;i++) | ||
for(int j=0;j<aim+1;j++) | ||
map[i][j]=-1; | ||
for(int i=0;i<n;i++) | ||
map[i][0]=1; | ||
for(int i=0;i<aim+1;i++) | ||
if(i%penny[0]==0) | ||
map[0][i]=1; | ||
else | ||
map[0][i]=0; | ||
for(int i=1;i<n;i++) | ||
for(int j=1;j<aim+1;j++) | ||
if((j-penny[i])>=0) | ||
map[i][j]=map[i][j-penny[i]]+map[i-1][j]; | ||
else | ||
map[i][j]=map[i-1][j]; | ||
return map[n-1][aim]; | ||
} | ||
|
||
}; | ||
|
||
|
||
/*记忆搜索 | ||
class Exchange { | ||
public: | ||
int countWays(vector<int> penny, int n, int aim) | ||
{ | ||
if(n==0||aim<0) | ||
return 0; | ||
int **map=new int*[n]; | ||
for(int i=0;i<n;i++) | ||
map[i]=new int[aim+1]; | ||
for(int i=0;i<n;i++) | ||
for(int j=0;j<aim+1;j++) | ||
map[i][j]=-1; | ||
return process(penny,0,aim,map); | ||
} | ||
int process(vector<int> arr,int index,int aim,int **map) | ||
{ | ||
int res; | ||
if(arr.size()-1==index) | ||
{ | ||
if(map[index][aim]==-1) | ||
map[index][aim]=(aim%arr[index])?0:1; | ||
return map[index][aim]; | ||
} | ||
else | ||
{ | ||
res=0; | ||
int k=aim/arr[index]; | ||
for(int i=0;i<=k;i++) | ||
{ | ||
if(map[index+1][aim-i*arr[index]]==-1) | ||
map[index+1][aim-i*arr[index]]=process(arr,index+1,aim-i*arr[index],map); | ||
res+=map[index+1][aim-i*arr[index]]; | ||
} | ||
} | ||
return res; | ||
} | ||
};*/ | ||
|
||
/*暴力搜索 | ||
class Exchange { | ||
public: | ||
int countWays(vector<int> penny, int n, int aim) | ||
{ | ||
if(n==0||aim<0) | ||
return 0; | ||
return process(penny,0,aim); | ||
} | ||
int process(vector<int> arr,int index,int aim) | ||
{ | ||
int res; | ||
if(arr.size()-1==index) | ||
{ | ||
res=(aim%arr[index])?0:1; | ||
return res; | ||
} | ||
else | ||
{ | ||
res=0; | ||
int k=aim/arr[index]; | ||
for(int i=0;i<=k;i++) | ||
res+=process(arr,index+1,aim-i*arr[index]); | ||
} | ||
return res; | ||
} | ||
};*/ | ||
|
||
int main() | ||
{ | ||
int a[3]={1,2,3}; | ||
vector<int> arr(a,a+3); | ||
Exchange e; | ||
cout<<e.countWays(arr,3,3); | ||
|
||
return 0; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.