C题
c题自己以为是搜索,自己还是考虑少了,但是实则暴力就可以,通过这个题自己也学到了一个新的遍历的方式。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int INF = 0x3f3f3f3f;
string a;
string b;
int main(){
cin >> a >> b;
int len1 = a.length();
int len2 = b.length();
int ans = INF;
int len = len2;
if(len1<len2){
swap(a,b);
swap(len1,len2);
}
for(int i = 1; i < len2; i++){
int num = 0;
for(int k = i, j = 0; k < len2 && j < len1; k++, j++){
if(b[k] == a[j])
num++;
}
ans = min(ans, len-num);
}
for(int i = 0; i < len1; i++){
int num = 0;
for(int k = i, j = 0; j < len2 && k < len1; j++, k++)
if(a[k] == b[j])
num++;
ans = min(ans, len-num);
}
printf("%d\n", ans);
return 0;
}
D题
D题思考起来太绕了,尤其是题干,刚开始说只有一个罪犯,下面又说至少一个罪犯,在补题之前我甚至也一直以为罪犯不止一个。
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
const int N = 1e5 + 300;
int a[N];
int issuspect[N], nosuspect[N];
int iscrimer[N], crimer[N];
int main(){
int n, m;
while(scanf("%d%d",&n,&m)!=EOF){
int nosupn = 0;
for(int i = 1; i <= n; i++){
scanf("%d",&a[i]);
if(a[i] > 0){
issuspect[a[i]]++;
}else{
nosuspect[-a[i]]++;
nosupn++;
}
}
int saytrue = 0;
int cn = 0;
for(int i = 1; i <= n; i++){
saytrue = issuspect[i] + nosupn - nosuspect[i];
if(saytrue == m){
crimer[cn] = i; cn++;
iscrimer[i] = 1;
}
}
if(cn == 1){
for(int i = 1; i <= n; i++){
if(a[i] > 0){
if(iscrimer[a[i]]){
puts("Truth");
}else{
puts("Lie");
}
}else{
if(iscrimer[-a[i]]){
puts("Lie");
}else{
puts("Truth");
}
}
}
}else{
for(int i = 1; i <= n; i++){
if(a[i] > 0){
if(iscrimer[a[i]]){
puts("Not defined");
}else{
puts("Lie");
}
}else{
if(iscrimer[-a[i]]){
puts("Not defined");
}else{
puts("Truth");
}
}
}
}
}
return 0;
}