AtCoder Beginner Contest 183

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

A - ReLU

void work()
{
  int x; cin >> x;
  if (x > 0) cout << x << endl;
  else cout << 0 << endl;
}

B - Billiards

在x轴反射,找对称点,就变成了y等于0,求方程的x值了

#include <bits/stdc++.h>
using namespace std;
double ax, ay, bx, by;

int main()
{
  cin >> ax >> ay >> bx >> by;
  if (ax == bx)
  {
    printf("%.8lf\n", ax);
    return 0;
  }
  else
  {
    ay = - ay;
    printf("%.8lf\n", ax - ay * (ax - bx) / (ay - by));
  }

  return 0;
}

C - Travel

8很小,可以直接暴力枚举所有方案

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[10] = {2, 3, 4, 5, 6, 7, 8, 9};
int n;
ll k;
int g[10][10];
int main()
{
  cin >> n >> k;
  for (int i = 1; i <= n; i ++ )
    for (int j = 1; j <= n; j ++ )
      cin >> g[i][j];
  int ans = 0;
  do{
    ll sum = 0;
    sum += g[1][a[0]];
    for (int i = 0; i < n - 1; i ++ ) sum += g[a[i]][a[i + 1]];
    sum += g[a[n - 2]][1];
    if (sum == k) ans ++;
  }while(next_permutation(a, a + n - 1));
  cout << ans << endl;
  return 0;
}

D - Water Heater

考察前缀和

#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
typedef long long ll;
int n, m;
ll a[N], b[N];
void insert(int l, int r, int x)
{
  b[l] += x;
  b[r + 1] -= x;
}
int main()
{
  cin >> n >> m;
  int mx = 0;
  for (int i = 1; i <= n; i ++ )
  {
    int l, r, x; scanf("%d%d%d", &l, &r, &x);
    mx = max(mx, r);
    insert(l, r - 1, x);
  }
  for (int i = 0; i <= mx; i ++ )
  {
    a[i] = a[i - 1] + b[i];
    if (a[i] > m)
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

E - Queen on Grid

将三个方向的方案数分别计算出来,然后在加起来

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2010, mod = 1e9 + 7;
int n, m;
char s[N][N];
ll dp[N][N][4];
int main()
{
  cin >> n >> m;
  for (int i = 1; i <= n; i ++ ) cin >> s[i] + 1;
  for (int i = 1; i <= n; i ++ )
    for (int j = 1; j <= m; j ++ )
      if (s[i][j] == '.')
      {
        if (i == 1 && j == 1) {dp[i][j][3] = 1; continue;}
        if (s[i - 1][j] == '.') dp[i][j][1] = (dp[i - 1][j][1] + dp[i - 1][j][3]) % mod;
        if (s[i][j - 1] == '.') dp[i][j][2] = (dp[i][j - 1][2] + dp[i][j - 1][3]) % mod;
        if (s[i-1][j-1] == '.') dp[i][j][0] = (dp[i-1][j-1][0] + dp[i-1][j-1][3]) % mod;
        dp[i][j][3] = (dp[i][j][0] + dp[i][j][1] + dp[i][j][2]) % mod;
      }
  cout << dp[n][m][3] << endl;
  return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值