A 题
用栈模拟一遍就够了
#include<bits/stdc++.h>
using namespace std;
int a[30];
char c;
stack <int> s;
int main()
{
int n;
cin >> n;
for(int i = 0; i < n; ++i)
{
cin >> c;
if(c == 'T') a[i] = 1;
}
while(cin >> c)
{
if(c>='A'&&c<='Z')
{
if(a[c-'A']) s.push(1);
else s.push(0);
}
else if(c == '*')
{
int x = s.top();s.pop();
int y = s.top();s.pop();
if(x&y) s.push(1);
else s.push(0);
}
else if(c == '+')
{
int x = s.top();s.pop();
int y = s.top();s.pop();
if(x+y) s.push(1);
else s.push(0);
}
else if(c=='-')
{
int x = s.top();s.pop();
x = !x;
s.push(x);
}
}
if(s.top()) cout << "T\n";
else cout << "F\n";
return 0;
}
K题
题意:找一个字符串,长度至少为2,一个字母只出现一次,可以不连续
输出所以满足条件的字符串
暴力
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
int vis[30000] ;
int main()
{
string s;
cin>>s;
int len = s.size() ;
ll ans = 0;
for(int i = 0 ;i < len; i ++)
{
memset(vis,0,sizeof (vis)) ;
for(int j = i + 1 ;j < len;j ++)
{
if(s[j] == s[i]) break;
if(vis[s[j]] == 0)
{
vis[s[j]] = 1;
ans++;
}
}
}
printf("%lld\n" , ans) ;
return 0 ;
}
M
水题一个

延长斜边做个辅助线,晾衣架模型,两个角相等,推出两个三角形相似
最长的长度就是 sqrt((g-r+h-r)*(g-r+h-r) * w * w)
最短就是两个杆的头部相连
#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+50;
double n,m,ans,w,g,h,r;
int main()
{
scanf("%lf",&n);
while(n--)
{
scanf("%lf%lf%lf%lf",&w,&g,&h,&r);
printf("%.8lf ",sqrt(w*w+(g-h)*(g-h)));
ans=sqrt(w*w+(h-r-r+g)*(h-r+g-r));
printf("%.8lf\n",ans);
}
return 0;
}
本文解析了2021年度训练联盟热身训练赛中的三道题目,包括使用栈模拟解决问题的A题,寻找特定字符串的K题,以及利用几何原理解决的M题。
715

被折叠的 条评论
为什么被折叠?



