Initial commit

This commit is contained in:
2025-03-14 22:39:32 +08:00
commit 7b1e0f329e
38 changed files with 1153 additions and 0 deletions

28
14lanqiao/test1.cpp Normal file
View File

@@ -0,0 +1,28 @@
#include<bits/stdc++.h>
using namespace std;
const int N = 1e2 + 10;
int a[N] = { 0,5,6,8,6,9,1,6,1,2,4,9,1,9,8,2,3,6,4,7,7,5,9,5,0,3,8,7,5,8,1,5,8,6,1,8,3,0,3,7,9,2,
7,0,5,8,8,5,7,0,9,9,1,9,4,4,6,8,6,3,3,8,5,1,6,3,4,6,7,0,7,8,2,7,6,8,9,5,6,5,6,1,4,0,1,
0,0,9,4,8,0,9,1,2,8,5,0,2,5,3,3 }; // 示例数组
int day[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main(){
int ans = 0;
for(int i = 1; i <=12; i++){
for(int j = 1; j <= day[i]; j++){
int date[] = {0, 2, 0, 2, 3, i/10, i%10, j/10, j%10 };
int id = 1;
for(int i = 1; i<=100; i++){
if(a[i] == date[id]){
id++;
if(id>8){
ans++;
break;
}
}
}
}
}
cout << ans << endl;
return 0;
}

13
14lanqiao/test2.cpp Normal file
View File

@@ -0,0 +1,13 @@
#include<bits/stdc++.h>
using namespace std;
int main(){
double n = 23333333;
double res = 11625907.5798;
for(int a = 0; a <= n; a++){ // a为0出现的次数
int b = n - a; // b为1出现的次数
if(a>=b) continue;
double ans = (-1)*a*(a/n)*log2(a/n) + (-1)*b*(b/n)*log2(b/n);
if(fabs(ans - res) < 1e-4) cout << a << endl;
}
return 0;
}

49
14lanqiao/test3-1.cpp Normal file
View File

@@ -0,0 +1,49 @@
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e4 + 10;
int a[N], b[N];
//枚举法
signed main(){
int n; cin >> n;
int mxv = LLONG_MIN, miv = LLONG_MAX;
for(int i = 1; i <= n; i++){
cin >> a[i] >> b[i];
if(b[i] != 1) mxv = max(mxv, a[i]/(b[i] - 1));
miv = min(miv, a[i]/(b[i] + 1));
}
for(int v = miv; v <= mxv; v++){
bool flag = true;
for(int i = 1; i <= n; i++){
if(a[i] / v != b[i]){
flag = false;
break;
}
}
if(flag){
cout << v << " ";
break;
}
}
for(int v = mxv; v >= miv; v--){
bool flag = true;
for(int i = 1; i <= n; i++){
if(a[i] / v != b[i]){
flag = false;
break;
}
}
if(flag){
cout << v << endl;
break;
}
}
return 0;
}
/* test samples
3
75 3
53 2
59 2
*/

26
14lanqiao/test3-2.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
int mxv = INT_MIN; int miv = INT_MAX;
for(int i = 1; i <= n; i++){
int a, b; cin >> a >> b;
miv = min(miv, a/b);
mxv = max(mxv, a/(b+1)+1);
}
cout << mxv << " " << miv << endl;
return 0;
}
/*
数学优化
通过floor(A/V) = B可以推出 A/V =B,B+1
进而得到B <= A/V < B+1三个表达式同时被A除
得到关于V的不等式即 A/B >= V > A/(B+1)
*/
/* test samples
3
75 3
53 2
59 2
*/

50
14lanqiao/test4.cpp Normal file
View File

@@ -0,0 +1,50 @@
#include<bits/stdc++.h>
using namespace std;
const int N = 1e2 + 10;
struct node{
int t, d, l; // 分别代表可以降落的时刻,盘旋时间,降落花费时间
}a[N];
bool vis[N];
int t, n;
bool flag = false;
// lasttime: 之前完成降落的所有飞机中的最后一架飞机降落的时间
void dfs(int dep, int lasttime){
if(dep == n + 1){
flag = true;
return;
}
for(int i = 1; i <= n; i++){
if(!vis[i] && a[i].t + a[i].d >= lasttime){
vis[i] = 1;
dfs(dep + 1, max(lasttime, a[i].t) + a[i].l);
// 遍历同级的另一个飞机的下一个深度的飞机前,需要将该飞机设置为未安排状态
vis[i] = 0;
}
}
}
int main(){
cin >> t;
while(t--){
cin >> n;
for(int i = 1; i<=n; i++){
cin >> a[i].t >> a[i].d >> a[i].l;
}
flag = false;
memset(vis, 0, sizeof(vis));
dfs(1, 0);
if(flag) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
/* test samples
2
3
0 100 10
10 10 10
0 2 20
3
0 10 20
10 10 20
20 10 20
*/

33
14lanqiao/test5-1.cpp Normal file
View File

@@ -0,0 +1,33 @@
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int ft[N], bk[N], dp[N];
/*
ft[i]第i个元素的首数字、bki第i个元素尾数字
类LIS问题的DP解法-时间复杂度0(n^2)
状态 dp[i] 以第主个元素作为结尾的最长接龙数列的长度
状态转移方程 dp[i] = max(dp[i], dp[j]+1);
*/
int main(){
int n; cin >> n;
string s;
for(int i = 1; i<=n; i++){
cin >> s;
ft[i] = s.front() - '0', bk[i] = s.back() - '0', dp[i] = 1;
}
int mx = 1;
for(int i = 2; i <= n; i++){
for(int j = 1; j < i; j++){
if(bk[j] == ft[i]){
dp[i] = max(dp[i], dp[j] + 1);
}
mx = max(mx, dp[i]);
}
}
cout << n - mx << endl;
return 0;
}
/* test samples 易超时
5
11 121 22 12 2023
*/

25
14lanqiao/test5-2.cpp Normal file
View File

@@ -0,0 +1,25 @@
#include<bits/stdc++.h>
using namespace std;
int dp[10];
/*
优化dp方案
状态 dp[i] 以数字i结尾的最长接龙序列的长度
状态转移方程 dp[bk]=max(dp[ft]+1, dp[bk])
*/
int main(){
int n; cin >> n;
string s;
int mx = 1;
for(int i = 0; i < n; i++){
cin >> s;
int ft = s.front() - '0', bk = s[s.size() - 1] - '0';
dp[bk] = max(dp[ft] + 1, dp[bk]);
mx = max(mx, dp[bk]);
}
cout << n - mx << endl;
return 0;
}
/* test samples
5
11 121 22 12 2023
*/