This commit is contained in:
Zengtudor 2024-08-11 11:45:06 +08:00
parent d7036e2248
commit d5d842515b
7 changed files with 118 additions and 4 deletions

View File

@ -1,4 +1,8 @@
# bdfz_2024_summer
# 竞赛的一些方法
1. 真正难的地方是通过题目给的信息和性质推出要用的算法
# 题目经验总结
## Day2
### [U111091 区间2段覆盖](./day2/U111091/U111091.md)
@ -9,9 +13,7 @@
>隔着老远swap一般不稳定
>稳定:插入,归并,冒泡
# 竞赛的一些方法
1. 真正难的地方是通过题目给的信息和性质推出要用的算法
## Day3
### [U86432 捞鱼(fish)](./day3/U86432/U86432.md)
@ -104,4 +106,5 @@ ll ksm(ll a,ll b,ll M){
>扫描线
>矩阵乘法
## Day9
### 字典树与异或极值

85
day9/P2580/P2580.cpp Normal file
View File

@ -0,0 +1,85 @@
//AC Code
#include<bits/stdc++.h>
using namespace std;
struct Node{
bool v=false;
bool is_word=false;
int next=0;
};
const int MAXN=1e6;
int n,tn=0,m;
Node t[MAXN][26];
int main(int argc,char *argv[]){
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef OITEST
#define AS(c){if(!(c)){cerr<<"assert faild :"<<#c<<endl;return -1;}}
AS(argc==3)
cout<<argv[0]<<" "<<argv[1]<<" "<<argv[2]<<endl;
ifstream ifile(argv[1]);
ifstream afile(argv[2]);
AS(ifile.is_open()==true)
AS(afile.is_open()==true)
stringstream ss;
#define cin ifile
#define cout ss
#endif
cin>>n;
for(int i=1;i<=n;i++){
string s;
cin>>s;
int now=0;
for(int j=0;j<s.size()-1;j++){
if (t[now][s[j]-'a'].next==0) {
t[now][s[j]-'a'].next=++tn;
}
now=t[now][s[j]-'a'].next;
}
t[now][s[s.size()-1]-'a'].is_word=true;
}
cin>>m;
for(int i=1;i<=m;i++){
string s;
cin>>s;
int now=0;
#ifdef OIPRINT
// cout<<s<<endl;
#define PRINTV(v)
#endif
for(int j=0;j<s.size()-1;j++){
#ifdef OIPRINT
PRINTV(j)
PRINTV(now)
PRINTV(t[now][s[j]-'a'].next)
#endif
if (t[now][s[j]-'a'].next==0) {
cout<<"WRONG"<<endl;
goto out;
}
now=t[now][s[j]-'a'].next;
}
if (!t[now][s[s.size()-1]-'a'].is_word) {
cout<<"WRONG"<<endl;
goto out;
}
if(t[now][s[s.size()-1]-'a'].v){
cout<<"REPEAT"<<endl;
}else{
t[now][s[s.size()-1]-'a'].v=true;
cout<<"OK"<<endl;
}
out:;
#ifdef OITEST
string cans;
afile>>cans;
string myans;
ss>>myans;
AS(myans==cans)
#endif
}
}

4
day9/P2580/P2580_1.in Normal file
View File

@ -0,0 +1,4 @@
1
ad
1
a

1
day9/P2580/P2580_1.out Normal file
View File

@ -0,0 +1 @@
WRONG

10
day9/P2580/P2580_2.in Normal file
View File

@ -0,0 +1,10 @@
5
a
b
c
ad
acd
3
a
a
e

3
day9/P2580/P2580_2.out Normal file
View File

@ -0,0 +1,3 @@
OK
REPEAT
WRONG

View File

@ -87,4 +87,12 @@ target("U279656")
for v=1,3 do
local s=tostring(v)
add_tests(s,{files="./day8/U279656/*.cpp",runargs={"seg"..s..".in","seg"..s..".ans"},defines="OITEST",run_timeout=1000})
end
end
target("P2580")
set_rundir("./day9/P2580")
add_files("./day9/P2580/*.cpp")
for v=1,2 do
local s=tostring(v)
add_tests(s,{files="./day9/P2580/*.cpp",runargs={"P2580_"..s..".in","P2580_"..s..".out"},defines="OITEST",run_timeout=1000})
end