360病毒
(只会打暴力的人)
2025 年2 月 22 日 02:49
1
rt,请大佬帮忙看看,码风有没有什么可以优化的地方,让我调试调轻松点,本人有点强迫症)
以下是我P1032的die码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
pair<string,string> x[15],y[15];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
string a,b;
cin>>a>>b;
string s1,s2;
int cnt=0;
while(cin>>s1>>s2){
x[++cnt]={s1,s2};
y[cnt]={s2,s1};
}
queue<pair<string,int> > qa,qb;
map<string,int> ma,mb;
int s=10;
qa.push({a,0});
qb.push({b,0});
ma[a]=1,mb[b]=1;
while(s--){
if(qa.size()<=qb.size()){
int len=qa.size();
while(len--){
string q=qa.front().first;
int step=qa.front().second;
qa.pop();
for(int i=1;i<=cnt;i++){
int l1=q.size(),l2=x[i].first.size();
for(int j=0;j+l2-1<l1;j++){
if(q.substr(j,l2)==x[i].first){
string t=q.substr(0,j)+x[i].second+q.substr(j+l2);
if(ma[t]!=0)
continue;
else if(mb[t]!=0){
cout<<10-s;
return 0;
}
else
qa.push({t,step+1});
ma[t]=1;
}
}
}
}
}
else{
int len=qb.size();
while(len--){
string q=qb.front().first;
int step=qb.front().second;
qb.pop();
for(int i=1;i<=cnt;i++){
int l1=q.size(),l2=y[i].first.size();
for(int j=0;j+l2-1<l1;j++){
if(q.substr(j,l2)==y[i].first){
string t=q.substr(0,j)+y[i].second+q.substr(j+l2);
if(mb[t]!=0)
continue;
else if(ma[t]!=0){
cout<<10-s;
return 0;
}
else
qb.push({t,step+1});
mb[t]=1;
}
}
}
}
}
}
cout<<"NO ANSWER!";
}
还有救吗?
2 个赞
黄飞栋
(一堆果冻)
2025 年2 月 22 日 02:52
6
那肯定有救
这是我的码风:
#include<bits/stdc++.h>
#define int long long
using namespace std;
pair<string,string> x[15],y[15];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
string a,b;
cin>>a>>b;
string s1,s2;
int cnt=0;
while(cin>>s1>>s2){
x[++cnt]={s1,s2};
y[cnt]={s2,s1};
}queue<pair<string,int> > qa,qb;
map<string,int> ma,mb;
int s=10;
qa.push({a,0});
qb.push({b,0});
ma[a]=1,mb[b]=1;
while(s--){
if(qa.size()<=qb.size()){
int len=qa.size();
while(len--){
string q=qa.front().first;
int step=qa.front().second;
qa.pop();
for(int i=1;i<=cnt;i++){
int l1=q.size(),l2=x[i].first.size();
for(int j=0;j+l2-1<l1;j++){
if(q.substr(j,l2)==x[i].first){
string t=q.substr(0,j)+x[i].second+q.substr(j+l2);
if(ma[t]!=0)continue;
else if(mb[t]!=0){
cout<<10-s;
return 0;
}else qa.push({t,step+1});
ma[t]=1;
}
}
}
}
}else{
int len=qb.size();
while(len--){
string q=qb.front().first;
int step=qb.front().second;
qb.pop();
for(int i=1;i<=cnt;i++){
int l1=q.size(),l2=y[i].first.size();
for(int j=0;j+l2-1<l1;j++){
if(q.substr(j,l2)==y[i].first){
string t=q.substr(0,j)+y[i].second+q.substr(j+l2);
if(mb[t]!=0)continue;
else if(ma[t]!=0){
cout<<10-s;
return 0;
}else qb.push({t,step+1});
mb[t]=1;
}
}
}
}
}
}cout<<"NO ANSWER!";
return 0;
}
貌似更没救了
2 个赞
linan04103
(Clea_bulc_miracle)
2025 年2 月 22 日 02:53
7
我的呢:
#include <bits/stdc++.h>
#define LL long long
#define for_(i, a, b) for (int i = (a); i <= (b); i++)
#define _for(i, a, b) for (int i = (a); i >= (b); i--)
#define read() freopen("a.in", "r", stdin)
#define out() freopen("a.out", "w", stdout)
#define N 100005
#define M 1000005
#define Mod int(1e9 + 7)
typedef pair<int, int> PII;
using namespace std;
int head[N];
int to[M];
int Next[M];
int W[M];
struct Edge
{
int to;
int next;
};
int cnt_edge;
void add_edge(int u,int v,int w)
{
to[++cnt_edge] = u;
W[cnt_edge] = w;
Next[cnt_edge] = head[v];
head[u] = cnt_edge;
}
int main()
{
read();
out();
return 0;
}
很抽象
2 个赞
360病毒
(只会打暴力的人)
2025 年2 月 22 日 02:54
9
主要是最后那一长串的},看的很不舒服,有什么好办法吗?
2 个赞
俞天行
(ytxqωq)
2025 年2 月 22 日 02:57
15
像AI吗(?
#include <bits/stdc++.h>
#define int long long
using namespace std;
pair<string, string> x[15], y[15];
signed main()
{
//快读
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
//输入要求的字符串
string a, b;
cin >> a >> b;
string s1, s2;
int cnt = 0;
while (cin >> s1 >> s2) {
x[++cnt] = {s1, s2};
y[cnt] = {s2, s1};
}
queue<pair<string, int> > queA, queB; //两个队列操作
map<string, int> mazeFirst, mazeSecond; //map记录
int T = 10;
queA.push({a, 0});
queB.push({b, 0});
mazeFirst[a] = 1, mazeSecond[b] = 1;
while (T--) {
if (queA.size() <= queB.size()) {
int len = queA.size();
while (len--) {
string q = queA.front().first;
int step = queA.front().second;
queA.pop();
for (int i = 1; i <= cnt; i++) {
int lengh1 = q.size(), lengh2 = x[i].first.size();
for (int j = 0; j + lengh2 - 1 < lengh1; j++) {
if (q.substr(j, lengh2) == x[i].first) {
string t = q.substr(0, j) + x[i].second + q.substr(j + lengh2);
if (mazeFirst[t] != 0)
continue;
else if (mazeSecond[t] != 0) {
cout << 10 - T;
return 0;
} else
queA.push({t, step + 1});
mazeFirst[t] = 1;
}
}
}
}
} else {
int len = queB.size();
while (len--) {
string q = queB.front().first;
int step = queB.front().second;
queB.pop();
for (int i = 1; i <= cnt; i++) {
int lengh1 = q.size(), lengh2 = y[i].first.size();
for (int j = 0; j + lengh2 - 1 < lengh1; j++) {
if (q.substr(j, lengh2) == y[i].first) {
string answer = q.substr(0, j) + y[i].second + q.substr(j + lengh2);
if (mazeSecond[answer] != 0)
continue;
else if (mazeFirst[answer] != 0) {
cout << 10 - T;
return 0;
} else
queB.push({answer, step + 1});
mazeSecond[answer] = 1;
}
}
}
}
}
}
cout << "NO ANSWER!"; //没有答案
return 0;
}
2 个赞
360病毒
(只会打暴力的人)
2025 年2 月 22 日 02:57
17
这个样子?
#include<bits/stdc++.h>
#define int long long
using namespace std;
pair<string,string> x[15],y[15];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
string a,b;
cin>>a>>b;
string s1,s2;
int cnt=0;
while(cin>>s1>>s2){
x[++cnt]={s1,s2};
y[cnt]={s2,s1};
}
queue<pair<string,int> > qa,qb;
map<string,int> ma,mb;
int s=10;
qa.push({a,0});
qb.push({b,0});
ma[a]=1,mb[b]=1;
while(s--){
if(qa.size()<=qb.size()){
int len=qa.size();
while(len--){
string q=qa.front().first;
int step=qa.front().second;
qa.pop();
for(int i=1;i<=cnt;i++){
int l1=q.size(),l2=x[i].first.size();
for(int j=0;j+l2-1<l1;j++){
if(q.substr(j,l2)==x[i].first){
string t=q.substr(0,j)+x[i].second+q.substr(j+l2);
if(ma[t]!=0)
continue;
else if(mb[t]!=0){
cout<<10-s;
return 0;
}
else
qa.push({t,step+1});
ma[t]=1;
}
}
}
}
}
else{
int len=qb.size();
while(len--){
string q=qb.front().first;
int step=qb.front().second;
qb.pop();
for(int i=1;i<=cnt;i++){
int l1=q.size(),l2=y[i].first.size();
for(int j=0;j+l2-1<l1;j++){
if(q.substr(j,l2)==y[i].first){
string t=q.substr(0,j)+y[i].second+q.substr(j+l2);
if(mb[t]!=0)
continue;
else if(ma[t]!=0){
cout<<10-s;
return 0;
}
else
qb.push({t,step+1});
mb[t]=1;}}}}}
cout<<"NO ANSWER!";
}
2 个赞