feat: 添加三个算法题目解决方案

添加了三个算法题目的解决方案文件:
1. P3951.cpp - 实现简单的数学计算
2. P14362.cpp - 基础IO优化设置
3. P3952.cpp - 实现复杂度分析器,判断代码块的时间复杂度
This commit is contained in:
Zengtudor 2025-11-05 10:44:23 +08:00
parent e75cbc7b1b
commit 8aeb58ec32
3 changed files with 119 additions and 0 deletions

13
src/11/4/P14362.cpp Normal file
View File

@ -0,0 +1,13 @@
#include <cstdint>
#include <iostream>
#include <istream>
using ll = int64_t;
int main(){
std::iostream::sync_with_stdio(false);
std::cin.tie(nullptr);
}

6
src/11/4/P3951.cpp Normal file
View File

@ -0,0 +1,6 @@
#include <iostream>
int main(){
int a,b;
std::cin>>a>>b;
std::cout<<(a*b)-a-b<<"\n";
}

100
src/11/4/P3952.cpp Normal file
View File

@ -0,0 +1,100 @@
#include <algorithm>
#include <cctype>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <istream>
#include <set>
#include <string>
using ll = int64_t;
#define sl static inline
ll n,op,res,now,nres;
char tmp;
std::string st;
std::set<char> used;
bool iserror;
struct S{
char c;
ll res;
bool isok;
};
std::deque<S> stk;
#define printf
sl void solve(){
op=0,res=0;
iserror=false;
used.clear();
stk.clear();
std::cin>>tmp>>tmp>>tmp;
if(tmp=='1'){
op=0;
std::cin>>tmp;
}else{
std::cin>>tmp;
std::cin>>op;
std::cin>>tmp;
}
printf("STARTING %lld Get O(n^%lld)\n",++now,op);
while(std::cin>>st){
printf("while st=%s\n",st.data());
ll add=0;
if(st=="F"){
char i;
bool isok=(stk.size()?stk.back().isok:true);
std::string x,y;
std::cin>>i>>x>>y;
if(y=="n"&&x!="n"){
add++;
}else if(x=="n"&&isdigit(y[0])){
isok=false;
}else if(isdigit(x[0])&&isdigit(y[0])){
ll nx=atoi(x.data()),ny=atoi(y.data());
if(nx>ny){
isok=false;
}
}
if(used.find(i)!=used.end()){
iserror=true;
}else{
used.emplace(i);
}
stk.push_back({i,stk.empty()?add:stk.back().res+add,isok});
}else if(st=="E"){
if(stk.empty()){
iserror=true;
}else{
printf("pop stk c=%c, res=%lld\n",stk.back().c,stk.back().res);
if(stk.back().isok){
res=std::max(res,stk.back().res);
}
used.erase(stk.back().c);
stk.pop_back();
}
}else{
n=atoi(st.data());
break;
}
}
if(stk.size())iserror=true;
if(iserror){
std::cout<<"ERR\n";
}else{
std::cout<<(res==op?"Yes":"No")<<"\n";
}
}
int main(){
std::iostream::sync_with_stdio(false);
std::cin.tie(nullptr);
ll t;
std::cin>>t;
std::cin>>n;
while(t--){
solve();
}
}