rt, T2 部分分,solve3 和 solve4 没定义,本地 Dev-cpp 跑的话如果 c 不等于 5,6,7,8 就不会报编译错误,但是洛谷和小图灵上都是全挂 CE 的
问问是一旦有 CE 就全部挂掉还是按每个数据点跑只要不使用就不会 CE
#include <bits/stdc++.h>
using namespace std;
int n, m, a[100005], b[100005], ans;
char op[100005][5], arr[15];
bool check(){
char arr1[15];
for (int i = 1; i <= n; i++)
arr1[i] = arr[i];
for (int i = 1; i <= m; i++){
if (op[i][0] == 'T' || op[i][0] == 'U' || op[i][0] == 'F')
arr1[a[i]] = op[i][0];
if (op[i][0] == '+')
arr1[a[i]] = arr1[b[i]];
if (op[i][0] == '-')
arr1[a[i]] = arr1[b[i]] == 'T' ? 'F' : (arr1[b[i]] == 'U' ? 'U' : 'T');
}
for (int i = 1; i <= n; i++)
if (arr1[i] != arr[i])
return 0;
return 1;
}
void dfs1(int step, int cnt){
if (cnt >= ans)
return ;
if (step > n){
if (check())
ans = min(ans, cnt);
return ;
}
arr[step] = 'T';
dfs1(step + 1, cnt);
arr[step] = 'F';
dfs1(step + 1, cnt);
arr[step] = 'U';
dfs1(step + 1, cnt + 1);
}
void solve1(){
ans = 20;
dfs1(1, 0);
printf("%d\n", ans);
}
void solve2(){
ans = 0;
int arr2[100005];
for (int i = 1; i <= n; i++)
arr2[i] = 0;
for (int i = 1; i <= m; i++){
if (op[i][0] == 'T')
arr2[a[i]] = 1;
if (op[i][0] == 'F')
arr2[a[i]] = 2;
if (op[i][0] == 'U')
arr2[a[i]] = 3;
}
for (int i = 1; i <= n; i++)
if (arr2[i] == 3)
ans++;
printf("%d\n", ans);
}
int main(){
//freopen("tribool.in", "r", stdin);
//freopen("tribool.out", "w", stdout);
int c, T;
scanf("%d%d", &c, &T);
while (T--){
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++){
scanf("%s", op[i]);
if (op[i][0] == 'T' || op[i][0] == 'U' || op[i][0] == 'F')
scanf("%d", &a[i]);
if (op[i][0] == '+' || op[i][0] == '-')
scanf("%d%d", &a[i], &b[i]);
}
if (c <= 2)
solve1();
if (c == 3 || c == 4)
solve2();
if (c == 5 || c == 6)
solve3();
if (c == 7 || c == 8)
solve4();
}
return 0;
}
这 40 分真的对我很重要……坐标 ZJ,本来一直追求的都是压线过一等,唯一一个停了一周课的,本年段唯一一个有望一等(我们年段过弱了),本来高二考完就 AFO,全挂真的很难过……