(补题 水题 汇总)四川大学第二届SCUACM新生赛
B-丁姐姐喜欢LCS
输入
abc
bca
wad
ad
as
asd
wa
aw
wa
wwa
输出
bc
ad
as
a
解题思路
暴力呀!暴力呀!暴力呀!!!(我真是白学了ORZ)
代码样例
#include <bits/stdc++.h>
using namespace std;
int main(){
string a,b;
while(cin >> a >> b){
bool judge = false;
int cnt=0;
for(int i=0; i < a.length(); i++){
if(judge){
if (a[i] != b[cnt])
judge = false;
}
if(a[i] == b[cnt]){
judge = true;
cnt++;
}
}
if(judge)
for(int i=0;i < cnt; i++)
cout << b[i];
else
cout << "\"NULL!\"";
cout << endl;
}
return 0;
}
J-n=abc
输入
2
10
12
输出
No solution
12=2*2*3
解题思路
暴力呀!!!暴力呀!!!暴力呀!!!(我真是白学了ORZ ORZ)
代码样例
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
int a,b,c;
for(int i = 2; i < n; i++)
if(n % i == 0)
{
int m = n / i;
for(int j = i; j <= m / j + 1; j++)
if(m % j == 0 && j <= m / j)
if(m/j - i < cmp)
a = i, b = j, c = m/j, cmp = m/j - i;
}
if (judge == n)
cout << "No solution" << endl;
else
cout << n << "=" << a << "*" << b << "*" << c << endl;
}
return 0;
}
L-双流机场
输入
2
3 3
010
010
3 3
011
011
输出
Sad
Happy
解题思路
水题,只需要判断四个角是否能够有出路和入路即可
代码样例
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
int n,m;
cin >> n >> m;
string a,b;
cin >> a >> b;
bool judge=false;
if(a[0] == '0'&&b[m-1] == '0')
judge = true;
if(a[0] == '1'&&b[0] == '0')
judge = true;
if(a[n-1] == '0'&&b[m-1] == '1')
judge = true;
if(a[n-1] == '1'&&b[0] == '1')
judge = true;
if(judge)
cout << "Sad" << endl;
else
cout << "Happy" << endl;
}
return 0;
}
我知道了,我收拾收拾马上滚ORZ