社区讨论
求帮我看看为什么错误
UVA124Following Orders参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mhjl0h7h
- 此快照首次捕获于
- 2025/11/04 04:17 4 个月前
- 此快照最后确认于
- 2025/11/04 04:17 4 个月前
code:
CPP#include<bits/stdc++.h>
using namespace std;
vector<char>nowp;
vector<char>ops;
vector<pair<char,char>>can;
vector<char>tmpvct;
int n;
void output()
{
for (auto chr : nowp)
cout << chr;
cout << '\n';
}
void dfs()
{
if (nowp.size() == n)
{
output();
return;
}
for (char c : ops)
{
bool can_choose = true;
if (find(nowp.begin(), nowp.end(), c) != nowp.end())
continue;
for (auto &p : can)
if (p.second == c)
if (find(nowp.begin(), nowp.end(), p.first) == nowp.end())
{
can_choose = false;
break;
}
if (can_choose)
{
nowp.push_back(c);
dfs();
nowp.pop_back();
}
}
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
string tmp;
while (getline(cin, tmp))
{
ops.clear();
tmpvct.clear();
nowp.clear();
can.clear();
stringstream ss;
ss << tmp;
char cr;
while (ss >> cr)
ops.emplace_back(cr);
getline(cin, tmp);
ss.clear();
ss << tmp;
while (ss >> cr)
tmpvct.emplace_back(cr);
for (int i = 0; i < tmpvct.size(); i += 2)
can.emplace_back(tmpvct[i], tmpvct[i + 1]);
sort(ops.begin(),ops.end());
n = ops.size();
dfs();
cout << '\n';
}
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...