社区讨论

神奇!!!

P1213[IOI 1994 / USACO1.4] 时钟 The Clocks参与者 7已保存回复 6

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
6 条
当前快照
1 份
快照标识符
@loc0tqrh
此快照首次捕获于
2023/10/30 06:06
2 年前
此快照最后确认于
2023/11/04 11:39
2 年前
查看原帖
我的代码提交上去55分(T了4个),开了O2竟然AC了 ?!
有没有大佬帮忙解释一下这是为什么
CPP
#include <iostream>
#include <cstdio>
#include <queue>
#include <map>
using namespace std;
struct node
{
    string s,ans;
}now,nex;
const int d[10][5] = {0,0,0,0,0,1,2,4,5,0,1,2,3,0,0,2,3,5,6,0,1,4,7,0,0,2,4,5,6,8,3,6,9,0,0,4,5,7,8,0,7,8,9,0,0,5,6,8,9,0};
map<string,bool> vis;
node bfs(string s)
{
    queue<node> q;
    now.s = s;
    q.push(now);
    vis[s] = 1;
    while(!q.empty())
    {
        now = q.front();
        q.pop();
        bool b = 1;
        for(int i = 1;i <= 9;i++)
            if(now.s[i]!='4'){b = 0;break;}
        if(b)return now;
        for(int i = 1;i <= 9;i++)
        {
            nex.s = now.s;
            for(int j = 0;j < 5;j++)
                nex.s[d[i][j]] = (nex.s[d[i][j]]-'0')%4+'1';
            if(vis[nex.s])continue;
            nex.ans = now.ans+(char)(i+'0')+' ';
            q.push(nex);
//            cout << nex.ans << endl;
            vis[nex.s] = 1;
        }
    }
    return now;
}
int main()
{
    string a = " ";
    for(int i = 1;i <= 9;i++)
    {
        int x;
        cin >> x;
        a+=(char)(x/3+'0');
    }
    cout << bfs(a).ans;
    return 0;
}

回复

6 条回复,欢迎继续交流。

正在加载回复...