AtCoder Beginner Contest 197(Sponsored by Panasonic)

AtCoder Beginner Contest 197(Sponsored by Panasonic)

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

A - Rotate

将串复制一遍,然后从第二个字符输出三个字符

void work()
{
  string s; cin >> s;
  s += s;
  for (int i = 1; i < 4; i ++ ) cout << s[i];
  cout << endl;
}

B - Visibility

题意:从(x,y)扩展,如果是.就可以走,如果是#就停,问有多少个.,那我们就直接向四个方向扩展

void work()
{
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  char g[110][110];
  for (int i = 0; i < n; i ++ ) scanf("%s", g[i]);
  x --, y --;
  if (g[x][y] == '#')
  {
    cout << "0" << "\n";
    return;
  }
  int ans = 1;
  //向上
  int a = x - 1;
  while (a >= 0 && g[a][y] == '.') a --, ans ++ ;
  //向下
  a = x + 1;
  while (a < n && g[a][y] == '.') a ++, ans ++ ;
  //向左
  int b = y - 1;
  while (b >= 0 && g[x][b] == '.') b --, ans ++ ;
  //向右
  b = y + 1;
  while (b < m && g[x][b] == '.') b ++, ans ++;
  cout << ans << "\n";
  return;
}

C - ORXOR

题意:给一个长度为n的序列,在n-1个空格中添加^或者|,求一个最小值

我们知道,|越多越大,但是^却可能大,也可能小。我第一次做的时候,使用DFS做的,结果是对的,但是花了我一小时的时间debug,当时太拉跨了,现在看到官方题解,确实哦,能用DFS做的,用二进制枚举同样不超时的,这里就是二进制枚举的做法了。

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i ++ )
const int N = 21;
int n;
int a[N];
int main()
{
  cin >> n;
  rep(i, n) cin >> a[i];
  int ans = INT_MAX;
  rep(i, 1 << (n - 1)) //枚举取xor的方法
  {
    int xor_val = 0;
    int or_val = 0;
    rep(j, n + 1)
    {
      if (j < n) or_val |= a [j];
      if (j == n || i >> j & 1) xor_val ^= or_val, or_val = 0;
    }
    ans = min(ans, xor_val);
  }
  cout << ans << "\n";
  return 0;
}

D - Opposite

计算几何:这是我整理的这个题的公式推导
在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n; cin >> n;
  double x, x2, y, y2; cin >> x >> y >> x2 >> y2;
  double a = (x + x2) / 2, b = (y + y2) / 2;
  double angle = acos(-1) * 2 / n;
  printf("%.5lf %.5lf\n", a + (x - a) * cos(angle) - (y - b) * sin(angle), b + (x - a) * sin(angle) + (y - b) * cos(angle));
  return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值