2019 acm-icpc 北美选拔赛

2021年度训练联盟热身训练赛第三场

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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值