首页 > 其他分享 >7/23·morning

7/23·morning

时间:2023-07-23 16:34:55浏览次数:39  
标签:string 23 int morning vis while str cstr

1248:Dungeon Master  http://ybt.ssoier.cn:8088/problem_show.php?pid=1248

#include<bits/stdc++.h>
using namespace std;
char a[103][103][103];
int vis[103][103][103];
int sx,sy,sz,ex,ey,ez;
struct qwert{
    int x,y,z;
};
int xx[6]={1,-1,0,0,0,0};
int yy[6]={0,0,1,-1,0,0};
int zz[6]={0,0,0,0,1,-1};
void bfs(){
    memset(vis,-1,sizeof(vis));
    queue<qwert> q;
    while(!q.empty())q.pop();
    q.push({sx,sy,sz});
    vis[sx][sy][sz]=0;
    while(!q.empty){
        qwert n=q.front();q.pop();
        for(int i=0;i<6;i++){
            int lx,ly,lz
            if(n.x>0&&n.x<=H&&n.y>0&&n.y<=A&&n.z>0&&n.z<=B&&vis[n.x][n.y][n.z]!=-1]){
                q.push()
            }
        }
    }
}
int main(){
    int H,A,B;
    while(H!=0&&A!=0&&B!=0){
        cin>>H>>A>>B;
        for(int i=1;i<=H;i++){
            for(int j=1;j<=A;j++){
                for(int k=1;k<=B;k++){
                    cin>>a[i][j][k];
                    if(a[i][j][k]=='S'){
                        sx=i;sy=j;sz=k;
                    }
                    if(a[i][j][k]=='E'){
                        ex=i;ey=j;ez=k;
                    }
                }
            }
        }
        bfs();
    }
    return 0;
}
//未完成

问题 A: 魔法鲜花  http://www.jzoj.cn/problem.php?cid=5707&pid=0

# include <bits/stdc++.h>
using namespace std;
const int maxN=1e5+1;
struct node{
    int wz,step;
};
string ABC="DABC";
int n,k;
queue<node>Q;
int vis[2*maxN];
int fa[maxN];int cz[maxN];
void findfa(int w){
    if(w==n){
        return;
    }
    else{
        findfa(fa[w]);
        cout<<ABC[cz[w]];
    }
}
void bfs(int start){
    Q.push({start,0});
    vis[start]=1;
    fa[start]=0;cz[start]='D';
    while (!Q.empty()){
        int touwz=Q.front().wz;
        int toustep=Q.front().step;
        Q.pop();
        
        int newwz[4];
        newwz[1]=touwz+1;
        newwz[2]=touwz-10;
        newwz[3]=touwz*2;
        int newstep=toustep+1;
                
        for (int i=1;i<=3;i++){
            
            if (newwz[i]==k) {
                cout<<newstep<<endl;
                fa[newwz[i]]=touwz;
                cz[newwz[i]]=i;
                findfa(newwz[i]);
                return;
            } 
            else if(vis[newwz[i]]==0 && newwz[i]>0 && newwz[i]<=maxN-1) {
                Q.push({newwz[i],newstep});
                fa[newwz[i]]=touwz;
                cz[newwz[i]]=i;
                vis[newwz[i]]=1;
           }
           
         }
    }
}


int main(){
    cin>>n>>k;
    if (n==k) cout<<0<<endl;
    else bfs(n); 
    return 0;
}

问题 B: 抓住那头牛  http://www.jzoj.cn/problem.php?cid=5707&pid=1

#include <bits/stdc++.h>
#define N 100001
using namespace std;
bool vis[N];
int dir[2]={-1,1};
struct node
{
    int x;
    int step;
}q[N];
void bfs(int n,int k)
{
    int head=1,tail=1;
    vis[n]=1;
    q[tail].x=n;
    q[tail].step=0;
    tail++;
    while(head<tail)
    {
        int x=q[head].x;
        int step=q[head].step;
        if(x==k)
        {
            cout<<step<<endl;
            break;
        }
        for(int i=0;i<2;i++)
        {
            int nx=x+dir[i];
            if(1<=nx and nx<=N and vis[nx]==0)
            {
                vis[nx]=1;
                q[tail].x=nx;
                q[tail].step=step+1;
                tail++;
            }
        }
        int nx=2*x;
        if(1<=nx and nx<=N and vis[nx]==0)
        {
            vis[nx]=1;
            q[tail].x=nx;
            q[tail].step=step+1;
            tail++;
        }
        head++;
    }
}
int main()
{
    int n,k;
    cin>>n>>k;
    if(k<n)
    {
        cout<<n-k<<endl;
    } 
    else
    {
        bfs(n,k);
    }
    return 0;
}

问题 C: 【提高】魔板  http://www.jzoj.cn/problem.php?cid=5707&pid=2

#include<bits/stdc++.h>
using namespace std;
string start;
struct node{
    string zt,cz;
};
set<string> vis;
string ABC="DABC";
string change(string str,char abc){
    string cstr="";
    /*
    0 1 2 3
    4 5 6 7
    A
    4 5 6 7
    0 1 2 3
    B
    3 0 1 2
    7 4 5 6
    C
    0 5 1 3
    4 6 2 7
    */
    if(abc=='A'){
        cstr+=str[4];cstr+=str[5];
        cstr+=str[6];cstr+=str[7];
        cstr+=str[0];cstr+=str[1];
        cstr+=str[2];cstr+=str[3];
    }
    else if(abc=='B'){
        cstr+=str[3];cstr+=str[0];
        cstr+=str[1];cstr+=str[2];
        cstr+=str[7];cstr+=str[4];
        cstr+=str[5];cstr+=str[6];
    }
    else if(abc=='C'){
        cstr+=str[0];cstr+=str[5];
        cstr+=str[1];cstr+=str[3];
        cstr+=str[4];cstr+=str[6];
        cstr+=str[2];cstr+=str[7];
    }
    return cstr;
} 
void bfs(){
    queue<node> q;
    while(!q.empty())q.pop();
    q.push({start,""});
    vis.insert(start);
    while(!q.empty()){
        string nowzt=q.front().zt,nowcz=q.front().cz;q.pop();
        //cout<<nowzt<<endl;
        for(int i=1;i<=3;i++){
            string newstr=change(nowzt,ABC[i]);
            string newcz=nowcz+ABC[i];
            if(newstr=="12345678"){
                cout<<newcz;
                exit(0);
            }
            if(vis.count(newstr)==0){
                q.push({newstr,newcz});
                vis.insert(newstr);
            }
        }
    }
}
int main(){
    int xx;start="";
    for(int i=1;i<=8;i++){
        cin>>xx;
        start+=char(xx+48);
    }
    bfs(); 
    cout<<"wujie"<<endl; 
    return 0;
}

问题 D: 连通块  http://www.jzoj.cn/problem.php?cid=5707&pid=3

#include<bits/stdc++.h>
using namespace std;
struct pos{
    int x,y;
};
int n,m;
int a[203][203];
bool vis[203][203];
int tx[4]={1,0,-1,0};
int ty[4]={0,1,0,-1};
void bfs(int bx,int by){
    queue<pos> q;
    while(!q.empty())q.pop();
    vis[bx][by]=1;
    q.push({bx,by});
    while(!q.empty()){
        pos c=q.front();q.pop();
        for(int i=0;i<4;i++){
            int nx=c.x+tx[i];
            int ny=c.y+ty[i];
            if(nx>0&&nx<=n&&ny>0&&ny<=m&&!vis[nx][ny]&&a[nx][ny]!=0){
                vis[nx][ny]=1;
                q.push({nx,ny});
            }
        }
    }
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }
    int sum=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(!vis[i][j]&&a[i][j]!=0){
                bfs(i,j);
                sum++;
            }
        }
    }
    cout<<sum;
    return 0;
}

 

标签:string,23,int,morning,vis,while,str,cstr
From: https://www.cnblogs.com/zangqy/p/17574776.html

相关文章

  • 23暑期集训 题目印象
    7.16[USACO20DEC]SleepingCowsP确定dp顺序P8863「KDOI-03」构造数组转化模型易于理解CF1363F转化概念区间右移变为右端点左移,便于转移CF1188Cdp不一定要直接求出答案;使得答案为min(i,j),排序取i,j两边的;......
  • The 2023 Guangdong Provincial Collegiate Programming Contest(2023广东省赛)
    链接:https://codeforces.com/gym/104369A.ProgrammingContestC++Code#include"bits/stdc++.h"usingnamespacestd;usingi64=longlong;voidsolve(){inty1,y2;cin>>y1;intn;cin>>n;vector<int>......
  • Toyota Programming Contest 2023#4(AtCoder Beginner Contest 311)——D
    https://atcoder.jp/contests/abc311/tasks/abc311_d思路题目说如果当前方向的下一个点能走,那么就一直走,否则才能转向。根据题意模拟即可,这道题的难点在于,碰到已经走过的点到底要不要走。如果当前方向走到底,其中的点之前全部都走过那么就不能再走了。我们用bfs模拟,对于能一直走......
  • 2023.7.23 接雨水
    一个能接雨水的区域,肯定是两边高,中间低,基于这个前提出发就能得到两种做法。动态规划预处理出每个柱子左边最高的柱子,同时也处理出每个柱子右边的最高的柱子。两者取一个min,记做h。那么如果h比当前柱子更高,那么起码当前这个柱子就可以在垂直领域上可以存下h-当前柱子高个单位......
  • 我的2023暑假青岛3天2晚旅游计划
    我的原暑假出游计划:https://ntopic.cn/p/2023072301/看海玩水优选青岛小朋友们最开心的暑假来了,今年我的2位小朋友最希望去玩的是看海和玩水。这样今年暑假我的出游目标就比较明确了,该计划实施路径了。出游目的地的比较和选择(维度:温度适宜、有海有沙滩):上海本地游:有海有沙滩的......
  • 2023.29 人工智能的发展特征
    今年以来,人工智能又热了起来,发展有以下几个特征:涌现出很多大模型,它们使用大量数据集进行训练,所以称它们为大型语言模型(LLM)。这些模型是生成式的。这意味着他们可以创建新内容,无论是文本、图像、声音、视频、3D对象,甚至是计算机代码。这是相较于旧人工智能模型的一个进步,旧的......
  • 2023牛客暑期多校训练营2 补题
    D.TheGameofEating题意:有n个人和m道菜,每个人对每个菜的都有一个喜好度a[i][j],所有人都知道其他人的喜好度,现在需要上k道菜,从1,2...,n,1,2.....的顺序来选,如果每个人都只考虑自己的喜好,问最后哪些菜会被端上来Solution我们考虑到所有人都知道其他人的喜好度,也就是说,假设当前要选......
  • 「赛后总结」20230722 CSP 模拟赛
    「赛后总结」20230722CSP模拟赛点击查看目录目录「赛后总结」20230722CSP模拟赛反思题解T1回文思路代码T2快速排序思路代码T3混乱邪恶思路代码T4校门外歪脖树上的鸽子思路吓死我了我还以为K8He不更博了。为啥前天模拟赛不写啊?打过,没参加。为啥昨天模拟赛不......
  • NOI2023游记
    7.21坐飞机提前来成都,飞机晚点了一个小时,但只晚到了15分钟。酒店房间太小了,愤怒。晚上点外卖,吃了一大堆水果。水了一晚上qq。7.22早上起来pvz。报到,因为到太早会有人拿着摄像机拍一路所以9点多到的,结果是AH第一个到的被采访了,不会说话/ll。去宿舍的时候有小姐姐帮忙拎箱子......
  • 2023年7月23日 天气:晴
       今天早上起来看了一个小时的英语阅读,接着背了一小时的英语单词,然后写了一个小时的Java,然后看了一小时的阅读,接着看了两个小时的作业。  明天打算背会单词,然后看几个小时的构建之法,接着出去玩一个小时。......