AtCoder Beginner Contest 189

导读:
简单的题目,只说明题意,或者直接说明结论
下面的难题,会做详细的解释和证明
立个flag,在座的大佬们做个见证:一个月刷60场ABC,现在2021/6/22,第七天,已打卡十一场。

A - Slot

判断三个字符是否相同

void work()
{
  string s; cin >> s;
  if (s[0] == s[1] && s[1] == s[2]) cout << "Won" << endl;
  else cout << "Lost" << endl;
}

B - Alcoholic

模拟题,按照题意模拟就完事了

void work()
{
  int n, x; cin >> n >> x;
  x *= 100;
  for (int i = 1; i <= n; i ++ )
  {
    int a, b; cin >> a >> b;
    x -= a * b;
    // printf("a = %d, b = %d, x = %d\n", a, b, x);
    if (x < 0)
    {
      cout << i << endl;
      return;
    }
  }
  cout << "-1" << endl;
  return;
}

C - Mandarin Orange

单调栈模板题,(我居然还写不出来) ,找到高度小于当前位置高度的最近的位置,如L[x]表示位置x处,左边第一个小于h[x]的高度。r[x]表示位于x处,右边第一个小于h[x]的高度。

#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int n;
int h[N];
int q[N], tot;
int l[N], r[N];
int main()
{
  cin >> n;
  for (int i = 1; i <= n; i ++ ) cin >> h[i];
  h[0] = h[n + 1] = -1;
  q[0] = 0; tot = 0;
  for (int i = 1; i <= n; i ++ )
  {
    while (tot >= 1 && h[i] <= h[q[tot]]) tot --;
    l[i] = q[tot];
    q[++ tot] = i;
  }
  q[0] = n + 1, tot = 0;
  for (int i = n; i >= 1; i -- )
  {
    while (tot >= 1 && h[i] <= h[q[tot]]) tot --;
    r[i] = q[tot];
    q[++ tot] = i;
  }
  // for (int i = 1; i <= n; i ++ )
  //   cout << l[i] << " ";
  // cout << endl;
  // for (int i = 1; i <= n; i ++ )
  //   cout << r[i] << " ";
  // cout << endl;
  int s = 0;
  for (int i = 1; i <= n; i ++ )
    s = max(s, h[i] * (r[i] - l[i] - 1));
  cout << s << endl;
}

D - Logical Expression

题意:给你一个S串,s[i]表示在i这个位置,y[i-1]要与x[i]进行的操作是什么,如果s[i]为^要进行与操作,如果是v,要进行或操作。而且x[0] = y[0],问我们有多少种x方案让y[n]为True。

做法:所以,我们要做的就是求x的方法,当s[i]^的时候,x[i]必须为True,那么这个位置的x[i]就被确定了,对方案没有什么贡献,如果s[i]为v时,如果x[i]为true,前面的i个有2^i次方种枚举方案。递推一下,就可以得到方案数了。

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const int N = 60;
int main()
{
  ll n; cin >> n;
  ll ans = 1;
  for (int i = 1; i <= n; i ++ )
  {
    string s; cin >> s;
    if (s[0] == 'O') ans += 1ll << i;
  }
  cout << ans << endl;
  return 0;
}
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const int N = 110;
ll dp[N][2];//走到位置i,y的值为0/1的方案数为多少,是方案数,而不是为True的方案数
int main()
{
  int n; cin >> n;
  dp[0][0] = 1; dp[0][1] = 1;
  for (int i = 1; i <= n; i ++ )
  {
    string s; cin >> s;
    if (s == "AND")
    {
      //y为false,x为false,y(i-1)随意,或者x为true,y(i-1)为false
      dp[i][0] = dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][0];
      //y为true,只能是x为true,y(i-1)也为true
      dp[i][1] = dp[i - 1][1];
    }
    else
    {
      //y为false,x为false同时y(i-1)也为false
      dp[i][0] = dp[i - 1][0];
      //y为true,x为true,y(i-1)随意,x为false,y为true
      dp[i][1] = dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][1];
    }
  }
  cout << dp[n][1] << endl;
  return 0;
}

E - Rotate and Flip

题意:给定n个坐标,给m个操作,有Q个询问。

m个操作分为四种,1,绕原点顺时针旋转90度,2,绕原点逆时针旋转90度,3,沿着x=p变为对称点,4,沿着y=p变为对称点。

Q个询问,询问第a次操作的第b个点会出现到哪里。

解决:旋转度数参考计算几何中的三角函数与坐标关系。可以想到用矩阵来做坐标转移:这里用到了三维坐标变换,可以学习一波。

[外链图片转存中...(img-oX7vXAel-1624350861770)]
第二,我们令矩阵相乘,这样就可以静态查询每个点在任意时刻的变化了。这一需要注意一点,我们设变换为A,坐标为T,矩阵乘法为AT

但是,在我们进行再次矩阵变换的时候,我们是先与矩阵A相乘,再与T相乘,若是接下来的变换为B、C、D,我们运算的顺序应该为DCBAT

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值