蓝桥杯最终冲刺(冲刺Day4)

38 篇文章 1 订阅
14 篇文章 2 订阅

1.ASC

#include <iostream>
using namespace std;
int main()
{
  // 请在此输入您的代码
  // 已知大写字母 A 的 ASCII 码为 65,请问大写字母 L 的 ASCII 码是多少?
  cout<<65+('L'-'A');
  return 0;
}

2.修改数组(21年省赛——3月28日)

 

 

#include <iostream>
using namespace std;
int main()
{
    int n;
    int a[100005]={0}, b[1000005] = { 0 };
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        while (b[a[i]] != 0)
        {
            b[a[i]]++;
      a[i]+=(b[a[i]]-1);
        }
        b[a[i]]++;
        cout << a[i] << ' ';
    }
    return 0;
}

3.大胖子走迷宫(19年国赛——3月25日) 

 

 

 

 

#include <bits/stdc++.h>
#include <queue>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
int t,n,k,vis[1005][1005];//体重、行数、变瘦时间标记数组
char mp[400][400];//存图
//上下左右
const int dr[]= {0,0,-1,1};
const int dc[]= {-1,1,0,0};

struct node {
    int x,y,dis;
    node(int x=0,int y=0,int dis=0):x(x),y(y),dis(dis) {}
};
//在迷宫里饿死啦(T_T)
bool inside(int xx, int yy) {
    if(xx+t/2<n && xx-t/2>=0 && yy+t/2<n && yy-t/2>=0) return true;//记得加上大胖子的身材哦!
    else return false;
}
//大胖子吃太多好胖~卡住啦,动不了,只能在迷宫里饿一饿变瘦子
bool check(int xx,int yy) {
    for(int i=xx-t/2; i<=xx+t/2; i++)
        for(int j=yy-t/2; j<=yy+t/2; j++)
            if(mp[i][j]=='*') return false;
    return true;
}
//博主最爱的bfs 
void bfs() {
    queue<node> q;
    node u(2,2,0);//大胖子出发啦
    vis[2][2]=1;
    q.push(u);
    while(!q.empty()) {
        node u=q.front();
        q.pop();
        if(u.x==n-3 && u.y==n-3) {
            cout<<u.dis;
            return;
        }
                
        if(u.dis<k) t=5;//大胖子
        else if(u.dis>=k && u.dis<2*k) t=3;//胖子
        else if(u.dis>=2*k) t=1;//瘦子
        
        if(t!=1) q.push(node(u.x,u.y,u.dis+1));//胖子太胖啦,出不去,只能呆在原地 
        
        for(int i=0; i<4; i++) {
            int nx=u.x+dr[i];
            int ny=u.y+dc[i];
            if(inside(nx,ny) && !vis[nx][ny] && check(nx,ny)) {
                vis[nx][ny]=1;
                int diss=u.dis+1;
                node v(nx,ny,diss);
                q.push(v);
            }
        }
    }
}


int main() {
    cin>>n>>k;
    for(int i=0; i<n; i++)
        cin>>mp[i];
    bfs();
    return 0;
}

4.数字三角形(20年省赛——3月19日)  

 

 

#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 110;

int n;
int maxnum;
int note[maxn] = { 0 }, left1 = 0, right1 = 0, pos = 1;
int a[maxn][maxn];

void dfs(int x, int left, int right) {

    if (x == n) { // 递归边界
        if (abs(left - right) > 1) return;

        note[x] = a[x][1 + right]; //
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += note[i];
        }
        if (sum > maxnum) maxnum = sum; // 刷新最大值
        return;
    }

    note[x] = a[x][1 + right]; // 记录第x层的数字
    dfs(x + 1, left + 1, right);
    dfs(x + 1, left, right + 1);
}


int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            cin >> a[i][j];
        }
    }

    dfs(1,0,0); //

    cout << maxnum << endl;

    getchar();
    getchar();
    return 0;
}

5. 36进制(17年省赛)

 

思路:相减乘起来 

#include <iostream>
using namespace std;
int main()
{
  long long int sum=0;
  int y=34;
  int n=23*36;
  int a=10*36*36;
  int m=22*36*36*36;
  sum=m+a+n+y;
  cout<<sum; 
  return 0;
}

6. 交换瓶子(16年省赛)

 

 

 思路:遇到编号和数字不同的就交换位置 记录次数

#include <iostream>
using namespace std;

//处理输入
//遍历i:1-n
//如果a[i]=i,已经到位
//否则先找到i在a中的位置pos[i]和i为交换-swap(a,pos[i],i)
int ans=0;
int a[10000];
int n;
int pos(int x)
{
  for(int i=1;i<=n;i++)
  {
    if (a[i]==x)
    return i;
  }
  return -1;
}
void swap(int i,int j)
{
  int t=a[i];
  a[i]=a[j];
  a[j]=t;
}
int main()
{

 
  
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    cin>>a[i];
  }
  for(int i=1;i<=n;i++)
  {
    if(a[i]==i)
    continue;
    else
    {
      swap(pos(i),i);
      ans++;
    }
  }
  cout<<ans;
  return 0;
}

7. 路径之谜(16年国赛)

 

 

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=25;
int arr[maxn][maxn];//n*n矩阵
int a[maxn];//西->东
int b[maxn];//北->南
int n;
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
bool vis[maxn][maxn];
struct Point{
int x,y;
//记录到达每个点的路径
string road;
Point(){}
Point(int xx,int yy){
x=xx;
y=yy;
}
};

bool check(){
for(int i=0;i<n;i++)
      if(a[i]!=0||b[i]!=0)
    return false;

  return true;
}

void dfs(Point p){
    if(p.x==n-1&&p.y==n-1){
        if(check())
        cout<<p.road<<endl;

    return;
    }

    for(int i=0;i<4;i++){
        int dx=p.x+dir[i][0];
        int dy=p.y+dir[i][1];
        if(dx>=0&&dx<n&&dy>=0&&dy<n&&!vis[dx][dy]&&a[dy]!=0&&b[dx]!=0){
            Point next;
            next.x=dx;
            next.y=dy;
            string nextroad=to_string(arr[dx][dy]);
            next.road=p.road+" "+nextroad;
            vis[dx][dy]=true;
            a[dy]--;
            b[dx]--;


          dfs(next);
            //状态回溯
           vis[dx][dy]=false;
            a[dy]++;
            b[dx]++;


        }
    }





}



int main(){

cin>>n;
int temp=0;
for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
    arr[i][j]=temp++;
}
}

for(int j=0;j<n;j++){
    cin>>a[j];
}
for(int i=0;i<n;i++){
    cin>>b[i];
}


//初始化第一个点
Point pp;
pp.x=pp.y=0;
pp.road="0";
vis[0][0]=true;
a[0]--;
b[0]--;
dfs(pp);

return 0;
}

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小灰QAQ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值