2024cspj前三题

· · 个人记录

第一题

#include<bits/stdc++.h>
using namespace std;
 int a[105][105];
 int n,ans;
 string s;
int main()
{   cin>>n;
    while(n--)
    {
       cin>>s;
       if(a[s[0]][s[1]]==1) continue;
       ans++;
       a[s[0]][s[1]]=1;
    }
    cout<<52-ans;
   return 0;
}

第二题

#include<bits/stdc++.h>
using namespace std;
int xx[]={0,1,0,-1},yy[]={1,0,-1,0};
char g[1005][1005];
bool zhan[1005][1005];
int n,m,k,x,y,d,ans;
int check(int a,int b)
{  
   if(a<1||a>n||b<1||b>m) return 0;

   if(g[a][b]=='x') return 0;
   return 1;
}
int main()
{  int t;
    cin>>t;
   while(t--)
   {  ans=1;
      cin>>n>>m>>k;
      cin>>x>>y>>d;
      for(int i=1;i<=n;++i)
      for(int j=1;j<=m;++j)
      cin>>g[i][j];
      memset(zhan,0,sizeof zhan);
      zhan[x][y]=1;


       while(k--)
      { int xxx=x+xx[d],yyy=y+yy[d];
        if(check(xxx,yyy))
        {
        x=xxx, y=yyy;

        if(zhan[x][y]==0)ans++, zhan[x][y]=1;
        }
        else  d=(d+1)%4;


      }
      cout<<ans<<endl;


   }



   return 0;
}

第三题

#include<bits/stdc++.h>
using namespace std;
int g[]={6,2,5,5,4,5,6,3,7,6};
int  e[1000],n;
int get(int x)
 {
        if(x==0) return 6;
        int res=0;
        while(x)
        { res+=g[x%10];
          x/=10;        
        }
            return res;
 }


int main()
{ //打表 
  for(int i=1;i<=1000000;++i)
  {   int temp=get(i);
      if(e[temp]==0)
      e[temp]=i;
      else e[temp]=min(e[temp],i);
  }
 // for(int i=2;i<=60;++i)cout<<e[i]<<" "<<i<<endl;
  int t;
  cin>>t;
  while(t--)
  {   scanf("%d",&n);
      if(n==1) {printf("-1\n");continue;}
      if(n<=28) printf("%d\n",e[n]);
      else
      { int len=floor(1.0*(n-21)/7);
        printf("%d",e[21+(n-21)%7]);
        for(int i=1;i<=len;++i)
        printf("8");
        putchar('\n');


  }


  }

   return 0;
}