Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
unclezhou486 committed Aug 6, 2024
1 parent c15111a commit b35db6e
Show file tree
Hide file tree
Showing 110 changed files with 1,858 additions and 4,555 deletions.
41 changes: 41 additions & 0 deletions assets/0_to_latex.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm> // 包含算法库
#include <filesystem>

namespace fs = std::filesystem;

int main() {
const std::string output_filename = "0output_latex_sections.tex";
std::ofstream outfile(output_filename);

if (!outfile.is_open()) {
std::cerr << "Failed to open output file." << std::endl;
return 1;
}

for (const auto& entry : fs::directory_iterator(".")) {
if (entry.is_regular_file() && entry.path().extension() == ".cpp") {
std::string filename = entry.path().filename().string();
std::string basename = filename.substr(0, filename.size() - 4);
if(filename=="0_to_latex.cpp") continue;
// 转换为大写
std::transform(basename.begin(), basename.end(), basename.begin(),
[](unsigned char c){ return std::toupper(c); });

std::string subsection_title = basename;
// 将文件名中的短横线替换为空白
std::replace(subsection_title.begin(), subsection_title.end(), '-', ' ');

outfile << "\\subsection{" << subsection_title << "}\n";
outfile << "\\raggedbottom\\lstinputlisting[style=cpp]{assets/" << basename << ".cpp}\n";
outfile << "\\hrulefill\n\n";
}
}

outfile.close();
std::cout << "LaTeX sections generated in " << output_filename << std::endl;
return 0;
}
54 changes: 54 additions & 0 deletions assets/2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <bits/stdc++.h>

using namespace std;

void solve(){
int n;
cin>>n;
vector<int> a(n+1);
long long ans=0;
for(int i=1;i<=n;i++){
cin>>a[i];
ans+=a[i];
}
map<int,int> maa;
int mxx=0;
int lenn=0;
for(int i=1;i<=n;i++){
maa[a[i]]++;
if(maa[a[i]]>=2&&a[i]>mxx){
mxx=a[i];
}
a[i]=mxx;
ans+=a[i];
}
map<int,int> ma;
int mx=0;
int len=0;
for(int i=1;i<=n;i++){
ma[a[i]]++;
if(ma[a[i]]==2&&a[i]>mx){
ans+=1ll*(2*n-2*i+len+3)*(len)/2*mx;
mx=a[i];
len=1;
}
else if(ma[mx]>=2){
len+=1;
}
}
ans+=1ll*(len+1)*(len)/2*mx;
cout<<ans<<'\n';
}

int main(){
freopen("1.in","r",stdin);
freopen("2.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
55 changes: 55 additions & 0 deletions assets/3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <bits/stdc++.h>

using namespace std;

void solve(){
int n;
cin>>n;
vector<int> a(n+1);
long long ans=0;
bool flag=1;
for(int i=1;i<=n;i++){
cin>>a[i];
ans+=a[i];
}
map<int,int> maa;
int mxx=0;
int lenn=0;
for(int i=1;i<=n;i++){
maa[a[i]]++;
if(maa[a[i]]>=2&&a[i]>mxx){
mxx=a[i];
}
a[i]=mxx;
ans+=a[i];
}
map<int,int> ma;
int mx=0;
int len=0;
for(int i=1;i<=n;i++){
ma[a[i]]++;
if(ma[a[i]]==2&&a[i]>mx){
ans+=1ll*(2*n-2*i+len+3)*(len)/2*mx;
mx=a[i];
len=1;
}
else if(ma[mx]>=2){
len+=1;
}
}
ans+=1ll*(len+1)*(len)/2*mx;
cout<<ans<<'\n';
}

int main(){
freopen("1.in","r",stdin);
freopen("2.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
69 changes: 69 additions & 0 deletions assets/A_Access_Denied.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <bits/stdc++.h>

using namespace std;

string s;

//string res;

bool fl1;//len
char ans[30];

char c[70];

int main(){
for(int i=0;i<26;i++){
c[i]='A'+i;
}
for(int i=26;i<52;i++){
c[i]='a'+i-26;
}
for(int i=52;i<62;i++){
c[i]='0'+i-52;
}
ans[1]='A';
cout<<ans[1]<<endl;
int idx=1,d;
char cc;
for(int i=1;i<=20;i++){
cin>>s>>s;
if(s[0]=='G'){
return 0;
}
cin>>cc>>d>>s;
if(d==5){
idx++;
ans[idx]='A';
for(int i=1;i<=idx;i++){
cout<<ans[i];
}
cout<<endl;
}
else{
break;
}
}
int len=idx;idx=1;
for(int i=1;i<=len;i++){
int maxn=0;
char ansc;
for(int j=0;j<62;j++){
ans[i]=c[j];
for(int k=1;k<=len;k++){
cout<<ans[k];
}
cout<<endl;
cin>>s>>s;
if(s[0]=='G'){
return 0;
}
cin>>cc>>d>>s;
if(d>maxn){
maxn=d;
ansc=c[j];
}
}
ans[i]=ansc;
}

}
22 changes: 22 additions & 0 deletions assets/A_Simple_Task.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <bits/stdc++.h>

using namespace std;

int n,m;

vector<int> ne[20];

int dp[(1<<19)][19];

int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>m;
while(m--){
int u,v;
cin>>u>>v;
ve[u].push_back(v);
ve[v].push_back(u);
}

}
30 changes: 30 additions & 0 deletions assets/B.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <bits/stdc++.h>

using namespace std;

void solve(){
long long n;
cin>>n;
long long bmax=0,bmin=0;
for(int i=0;i<=77;i++){
if((n-79*i)%77==0){
bmax=(n-79*i)/77;
break;
}
}
for(int i=0;i<=79;i++){
if((n-77*i)%79==0){
bmin=i;
}
}
long long ans=(bmax-bmin)/79;
if(bmax||bmin) ans+=1;
cout<<ans<<'\n';
}

int main(){
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
84 changes: 84 additions & 0 deletions assets/B_The_Human_Equation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n;

void solve(){
cin>>n;
int x=0;
int y;
vector<int> vec;
for(int i=1;i<=n;i++){
cin>>y;
if(!y) continue;
if(x*y>=0){
x+=y;
}
else{
vec.push_back(x);
x=y;
}
}
if(x) vec.push_back(x);
//for(auto v:vec){
// cout<<v<<' ';
//}
//cout<<'\n';
int m=vec.size();
if(m==0){
cout<<0<<'\n';
}
else if(m==1){
cout<<abs(vec[0])<<'\n';
}
else if(m==2){
cout<<max(abs(vec[0]),abs(vec[1]))<<'\n';
//cout<<abs(abs(vec[0])-abs(vec[1]))<<'\n';
}
else{
priority_queue<pair<int,int>,vector<pair<int,int> > ,greater<pair<int,int> > > q;
vector<int> l(m+10),r(m+10),val(m+10),vis(m+10);
for(int i=1;i<=m;i++){
l[i]=i-1;
r[i]=i+1;
val[i]=abs(vec[i-1]);
}
l[m+1]=m;r[0]=1;
for(int i=1;i<=m;i++){
q.push({abs(vec[i-1],i)});
}
int ans=0;
while(q.size()){
pair<int,int> pos=q.top();
q.pop();
int v=val[id],id=pos.second;
if(vis[id]) continue;
vis[id]=1;
if(v<=ans){
int ll=l[id],rr=r[id];
r[ll]=rr;
l[rr]=ll;
continue;
}
int res=v-ans;
int ll=l[id],rr=r[id];
if(ll){
vis[rr]=1;

}

}
}
}

signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
24 changes: 24 additions & 0 deletions assets/D.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <bits/stdc++.h>

using namespace std;

const int N=5e3+10;

int n,w[N],p[N],a[N];

vector<vector<int> > ne(N);

int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>w[i];
}
for(int i=1;i<=n;i++) cin>>p[i];
for(int i=1;i<=n;i++){
cin>>a[i];
ne[a[i]].push_back(i);
}

}
Loading

0 comments on commit b35db6e

Please sign in to comment.