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

7/23·afternoon

时间:2023-07-23 17:12:15浏览次数:41  
标签:string 23 int vis while afternoon front kk

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

#include<bits/stdc++.h>
using namespace std;
int s,t;
int vis[100007];
struct node{
    int num;
    string path;
};
string ABC="ABC";
int main(){
    memset(vis,-1,sizeof(vis));
    cin>>s>>t;
    if(s==t){
        cout<<0;
        return 0;
    }
    queue<node> q;
    while(!q.empty())q.pop();
    q.push({s,""});
    vis[s]=0;
    while(!q.empty()){
        int frontn=q.front().num;
        string frontp=q.front().path;
        q.pop();
        for(int i=0;i<3;i++){
            int x=frontn;
            if(i==0)x+=1;
            if(i==1&&x>10)x-=10;
            if(i==2)x*=2;
            if(x>0&&x<=100000&&vis[x]==-1){
                q.push({x,frontp+ABC[i]});
                vis[x]=vis[frontn]+1;
                if(x==t){
                    cout<<vis[x]<<endl;
                    cout<<frontp+ABC[i];
                    return 0;
                }
            }
        }
    }
    return 0;
}
/*换了一种路径记录方式*/

问题 E: 最少点路径  http://www.jzoj.cn/problem.php?cid=5707&pid=4

#include<bits/stdc++.h>
using namespace std;
int N,s,t;
int a[13][13];
bool vis[13];
struct node{
    int w;
    string path;
};
queue<node> q;
int main(){
    cin>>N;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            cin>>a[i][j];
        }
    }
    cin>>s>>t;
    
    while(!q.empty())q.pop();
    string st="";st+=char(s+48);
    q.push({s,st});
    vis[s]=1;
    while(!q.empty()){
        int x=q.front().w;
        string pa=q.front().path;
        q.pop();
        //cout<<x<<endl;
        for(int i=1;i<=N;i++){
            string p=pa+'-'+char(i+48);
            if(a[x][i]==1&&!vis[i]){
                q.push({i,p});
                vis[i]=1;
                if(i==t){
                    cout<<p<<endl;
                    return 0;
                }
            }
            
        }
    }
    return 0;
}
 

问题 F: 八数码问题  http://www.jzoj.cn/problem.php?cid=5707&pid=5

#include<bits/stdc++.h>
using namespace std;
/*
0 1 2
3 4 5
6 7 8
*/
string start,finish;
struct node{
    string a;
    int b,k;
};
int mov[4]={-3,3,1,-1};
set<string> vis;
string change(string str,int cz,int kk){
    int ch=kk+mov[cz];
    if(ch<0||ch>8||cz==3&&kk==3||cz==3&&kk==6||cz==2&&kk==2||cz==2&&kk==5)return "NO";
    else{
        string strr=str;
        swap(strr[kk],strr[ch]);
        return strr;
    }
}
int main(){
    cin>>start;
    cin>>finish;
    if(start==finish){//特判!!!
        cout<<0;
        return 0;
    }
    queue<node> q;
    while(!q.empty())q.pop();
    int z=0;while(start[z]!='0')z++;
    q.push({start,0,z});
    vis.insert(start);
    while(!q.empty()){
        string fronta=q.front().a;
        int frontb=q.front().b;
        int frontk=q.front().k;
        q.pop();
        for(int i=0;i<4;i++){
            string str=change(fronta,i,frontk);
            if(str!="NO"&&vis.count(str)==0){
                q.push({str,frontb+1,frontk+mov[i]});
                vis.insert(str);
                if(str==finish){
                    cout<<frontb+1;
                    return 0;
                } 
            }
        }
    }
    cout<<"impossible";
    return 0;
}

 

 

标签:string,23,int,vis,while,afternoon,front,kk
From: https://www.cnblogs.com/zangqy/p/17575126.html

相关文章

  • 2023/7/23
    今天了解了包装类中的Boolean类和Character类,包装类有一个共同的父类Number类,Number类中所有的方法都包含在子类中。个人感觉包装类更多用于方法的形参中,可以实时记录过程的值并在反馈在主函数中。package包装类;publicclassCharacter类{publicstaticvoidmain(St......
  • 7.23做题记录
    线段树没学会 ......
  • 7/23·morning
    1248:DungeonMaster  http://ybt.ssoier.cn:8088/problem_show.php?pid=1248#include<bits/stdc++.h>usingnamespacestd;chara[103][103][103];intvis[103][103][103];intsx,sy,sz,ex,ey,ez;structqwert{intx,y,z;};intxx[6]={1,-1,0,0,0,0};in......
  • 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我们考虑到所有人都知道其他人的喜好度,也就是说,假设当前要选......