作者:qaz2502919927 | 来源:互联网 | 2023-10-11 22:50
首先,可以用自己的IDE!!!模拟体验满分!!!下午刚打完天梯赛,被模拟折磨了一下午,晚上又被模拟折磨惹。40分钟(好像是)写完ABC,看了看D发现是阅读理解,本来准备交卷开摆,后
首先,可以用自己的IDE!!!模拟体验满分!!!
下午刚打完天梯赛,被模拟折磨了一下午,晚上又被模拟折磨惹。
40分钟(好像是)写完ABC,看了看D发现是阅读理解,本来准备交卷开摆,后来想了想,多交几发枚举一下题意试试,发现和天梯赛的模拟难度差不多。。。
A题:签到,怎么写都能过吧
B题:签到,直接dp即可
C题:他让你怎么写你就怎么写
#include
using namespace std;
#define ll long long
struct func {
string name;
string argdf;
vectors;
vectori;
}fun[1000];
maphtd;
string ITS(int x) {
string res="";
if (!x)return "0";
bool flag = 1;
if (x <0)
flag = 0, x = -x;
while (x) {
res = char((x % 10) + '0') + res;
x /= 10;
}
if (!flag)
res = '-' + res;
return res;
}
int main()
{
for (int i = 0; i <= 9; i++)
htd[char(i + '0')] = i;
htd['A'] = 10;
htd['B'] = 11;
htd['C'] = 12;
htd['D'] = 13;
htd['E'] = 14;
htd['F'] = 15;
int n;
cin >> n;
for (int i = 1; i <= n;i++) {
int x;
cin >> x;
string name, argd;
cin >> name >> argd;
fun[x].name = name;
fun[x].argdf = argd;
}
string rpcs="";
string tmp;
while (cin >> tmp) {
rpcs += tmp;
}
int now = 0;
for (; now int rpcid = 0;
rpcid = htd[rpcs[now]] * 16 + htd[rpcs[now + 1]];
assert(rpcid <256);
now += 2;
string name = fun[rpcid].name;
int tot = 0;
for (auto i:fun[rpcid].argdf) {
if (i == 's')
tot++;
}
queuelen;
for (int i = 1; i <= tot; i++) {
len.push(htd[rpcs[now]] * 16 + htd[rpcs[now + 1]]);
now += 2;
}
for (auto o : fun[rpcid].argdf) {
if (o == 's') {
string tmp = "";
int i = len.front();
len.pop();
for (int j = 1; j <= i * 2; j++) {
tmp += rpcs[now++];
}
fun[rpcid].s.push_back(tmp);
}
else {
int sum = 0;
for (int j = 1; j <= 8; j++) {
sum = sum * 16 + htd[rpcs[now++]];
}
fun[rpcid].i.push_back(sum);
}
}
string ans = name + "(";
int pt1 = 0, pt2 = 0;
for (auto i : fun[rpcid].argdf) {
if (i == 's') {
ans += "\"";
ans += fun[rpcid].s[pt1++];
ans += "\"";
}
else {
ans += ITS(fun[rpcid].i[pt2++]);
}
ans += ",";
}
fun[rpcid].s.clear();
fun[rpcid].i.clear();
ans.pop_back();
ans += ")";
cout < }
return 0;
}
D题:同上,需要一点点技巧。由于输入已经分好词了,所以对于每条question,遍历每个规则,用栈匹配处理括号,同时对于规则里每个词都去这条question里找存不存在,就可以把规则中的单词变成0和1,然后规则就变成只含\(+\)、\(*\)和括号的布尔表达式求值
剩下的就是他怎么说你怎么写了。
#include
using namespace std;
#define ll long long
mapid;
setq[50];
vectorans;
string getNextWord(string& s, int& i) {
if (i >= s.length())return "";
while (s[i] == ' ')
i++;
string res = "";
while (i res = res + s[i++];
return res;
}
int main()
{
int n, m;
cin >> n >> m;
string s;
getline(cin, s);
int cnt = 0;
for (int i = 1; i <= n; i++) {
getline(cin, s);
string tmp = "";
for (int j = 0; j if (s[j] == ' ') {
if (id.find(tmp) == id.end())
id[tmp] = ++cnt;
q[i].insert(id[tmp]);
tmp.clear();
continue;
}
tmp += s[j];
}
if (id.find(tmp) == id.end())
id[tmp] = ++cnt;
q[i].insert(id[tmp]);
}
for (int i = 1; i <= m; i++) {
getline(cin, s);
ans.push_back(s);
}
for (int qi = 1; qi <= n; qi++) {
auto que = q[qi];
bool ok = 0;
int mx = 0;
string res;
for (auto as : ans) {
int i = 0;
stackstk;
int flag = 0;
string now = "";
int tot = 0;//关键词数量
while (1) {
now = getNextWord(as, i);
if (now == "")break;
if (now == "and") {
flag = 1;
}
else if (now == "or") {
flag = 0;
}
else if (now == ")") {
while (1) {
int x = stk.top();
stk.pop();
if (stk.top() == 114 || stk.top() == 514) {
if (stk.top() == 114) {
flag = 0;
stk.pop();
stk.push(x);
}
else {
flag = 1;
stk.pop();
stk.top() &= x;
}
break;
}
stk.top() |= x;
}
}
else if (now == "(") {
if (flag == 0)
stk.push(114);
else
stk.push(514);
flag = 0;
continue;
}
else {
tot++;
int x = 0;
if (id.find(now) == id.end()) {
x = 0;
}
else {
if (que.find(id[now]) != que.end()) {
x = 1;
}
else {
x = 0;
}
}
if (flag == 0) {
stk.push(x);
}
else {
stk.top() &= x;
}
}
}
while (stk.size() > 1) {
int x = stk.top();
stk.pop();
stk.top() |= x;
}
if (stk.top() == 1) {
if (tot > mx) {
mx = tot;
res = as;
}
ok = 1;
}
}
if (!ok)
cout <<"miss" < else
cout < }
return 0;
}