哪位大佬能为本蒟蒻讲一下思路...

P1602 Sramoc问题

用广搜
by 黑客集团_鬼 @ 2018-06-27 19:39:46


你可以优化字符串,普通的可能会爆
by 黑客集团_鬼 @ 2018-06-27 19:41:46


代码: #include<iostream> #include<cstdio> #include<cstring> #include<queue> #include<vector> #include<algorithm> #define LL long long int using namespace std; const int maxn=1005,INF=2000000000,P=1000000007; int K,M; bool vis[maxn]; void bfs(){ queue<LL> q; queue<vector<int> > q2; vector<int> s; for(int i=1;i<K;i++){ q.push(i%M); vis[i%M]=true; s.push_back(i); q2.push(s); s.pop_back(); } LL u,k; while(!q.empty()){ u=q.front(); q.pop(); s=q2.front(); q2.pop(); for(int i=0;i<K;i++){ k=(u*10+i)%M; s.push_back(i); if(!k){ for(unsigned int j=0;j<s.size();j++) printf("%d",s[j]); cout<<endl; return; } else if(!vis[k]){ vis[k]=true; q.push(k); q2.push(s); } s.pop_back(); } } } int main(){ cin>>K>>M; bfs(); return 0; }
by 黑客集团_鬼 @ 2018-06-27 19:43:39


我开了vector
by 黑客集团_鬼 @ 2018-06-27 19:44:06


用同余去做
by 黑客集团_鬼 @ 2018-06-27 19:44:26


###### 谢大佬!
by Z__X @ 2018-06-27 19:51:18


###### 只是,本蒟蒻还没学过C++,准备暑假到网校上去学。
by Z__X @ 2018-06-27 19:52:46


那你用什么语言
by 黑客集团_鬼 @ 2018-06-27 19:55:33


我看看能不能打出来
by 黑客集团_鬼 @ 2018-06-27 19:55:58


@[黑客集团_鬼](/space/show?uid=93051) 用通用格式转出来
by fbhou @ 2018-06-27 20:13:42


|