CSP2024 反思

封面

放的代码是赛时代码。

CSP-J:

总分:280。

T1:AC,map。

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define itn int
// unordered
// priority
// operator
int n;
unordered_map<string,int>mp;
string xy[]={
"DA","CA","HA","SA",
"D2","C2","H2","S2",
"D3","C3","H3","S3",
"D4","C4","H4","S4",
"D5","C5","H5","S5",
"D6","C6","H6","S6",
"D7","C7","H7","S7",
"D8","C8","H8","S8",
"D9","C9","H9","S9",
"DT","CT","HT","ST",
"DJ","CJ","HJ","SJ",
"DQ","CQ","HQ","SQ",
"DK","CK","HK","SK"
};
int main(){
freopen("poker.in","r",stdin);
freopen("poker.out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++){
string s;cin>>s;
mp[s]=1;
}
itn ans=52;
for(int i=0;i<52;i++){
if(mp.count(xy[i]))ans--;
}
cout<<ans;
return 0;
}

T2:边界条件写错了,用了 bfs,边界条件只考虑了 x,yx,y,没有考虑 tx,tytx,ty,80 分。(出考场后马上用手机打了遍代码,赛后打的是对的…)。

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define itn int
// unordered
// priority
// operator
int read(){// read -> int -> long long
int x=0;bool fuh=0;
char ch=getchar();
while(ch>'9'||ch<'0')ch=getchar(),fuh=!fuh;
while(ch<='9'&&ch>='0')x=x*10+ch-'0',ch=getchar();
return fuh?-x:x;
}
int T,n,m,k;
int start_x,start_y,start_d;
char jz[1005][1005];
bool bj[1005][1005];
struct node{
int x;
int y;
int d;
int step;
};
queue<node>dl;
int main(){
freopen("explore.in","r",stdin);
freopen("explore.out","w",stdout);
cin>>T;
while(T--){
memset(bj,0,sizeof(bj));
cin>>n>>m>>k>>start_x>>start_y>>start_d;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>jz[i][j];
}
}
while(!dl.empty())dl.pop();
node temp;
temp.x=start_x;
temp.y=start_y;
temp.d=start_d;
temp.step=0;
dl.push(temp);
while(!dl.empty()){
temp=dl.front();dl.pop();
int x=temp.x,y=temp.y,d=temp.d,step=temp.step;
bj[x][y]=1;
if(step==k)break;
if(temp.d==0){
if(x>=1&&y>=1&&x<=n&&y<=m&&jz[x][y+1]=='.'){
dl.push(node{x,y+1,d,step+1});
}
else{
dl.push(node{x,y,((d+1)%4),step+1});
}
}
else if(temp.d==1){
if(x>=1&&y>=1&&x<=n&&y<=m&&jz[x+1][y]=='.'){
dl.push({x+1,y,d,step+1});
}
else{
dl.push({x,y,((d+1)%4),step+1});
}
}
else if(temp.d==2){
if(x>=1&&y>=1&&x<=n&&y<=m&&jz[x][y-1]=='.'){
dl.push({x,y-1,d,step+1});
}
else{
dl.push({x,y,((d+1)%4),step+1});
}
}
else if(temp.d==3){
if(x>=1&&y>=1&&x<=n&&y<=m&&jz[x-1][y]=='.'){
dl.push({x-1,y,d,step+1});
}
else{
dl.push({x,y,((d+1)%4),step+1});
}
}
}
LL ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(bj[i][j])ans++;
}
}
cout<<ans<<'\n';
}
return 0;
}

T3:AC,数学规律。

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define itn int
// unordered
// priority
// operator
int read(){// read -> int -> long long
int x=0;bool fuh=0;
char ch=getchar();
while(ch>'9'||ch<'0')ch=getchar(),fuh=!fuh;
while(ch<='9'&&ch>='0')x=x*10+ch-'0',ch=getchar();
return fuh?-x:x;
}
int T,n;
int xb[]={6,2,5,5,4,5,6,3,7,6};// z k l 0 1 2 4 7 8
LL dfs(int nn,LL a){
if(nn==0)return a;
else if(nn<0)return 1000000000;
else{
LL a1=1000000000,a2,a3,a4,a5,a6;
if(nn!=n)a1=dfs(nn-xb[0],a*10+0);
else a1=dfs(nn-xb[6],a*10+6);
a2=dfs(nn-xb[1],a*10+1);
a3=dfs(nn-xb[2],a*10+2);
a4=dfs(nn-xb[4],a*10+4);
a5=dfs(nn-xb[7],a*10+7);
a6=dfs(nn-xb[8],a*10+8);
return min(a1,min(a2,min(a3,min(a4,min(a5,a6)))));
}
}
int main(){
freopen("sticks.in","r",stdin);
freopen("sticks.out","w",stdout);
cin>>T;
while(T--){
cin>>n;
if(n<=20){
LL ans=dfs(n,0);
if(ans==1000000000)cout<<-1<<"\n";
else cout<<ans<<"\n";
}
else{
if(n%7==0){
for(int i=1;i<=n/7;i++)cout<<"8";
cout<<"\n";
}
else if(n%7==1){
cout<<10;
for(int i=2;i<=n/7;i++)cout<<8;
cout<<"\n";
}
else if(n%7==2){
cout<<1;
for(int i=1;i<=n/7;i++)cout<<"8";
cout<<"\n";
}
else if(n%7==3){
cout<<200;
for(int i=3;i<=n/7;i++)cout<<8;
cout<<"\n";
}
else if(n%7==4){
cout<<20;
for(int i=2;i<=n/7;i++)cout<<8;
cout<<"\n";
}
else if(n%7==5){
cout<<2;
for(int i=1;i<=n/7;i++)cout<<8;
cout<<"\n";
}
else if(n%7==6){
cout<<6;
for(int i=1;i<=n/7;i++)cout<<8;
cout<<"\n";
}
}
}
return 0;
}

T4:不会,试了模拟写错了qaq。

CSP-S:

总分:140

T1:AC,贪心。

T2:写了个暴力(我一普及组来写CSP-S?),20 分。

T3:暴力 20 分。

T4:没写。

总结:不会+边界条件。