AtCoder Beginner Contest 190
导读:
简单的题目,只说明题意,或者直接说明结论
下面的难题,会做详细的解释和证明
立个flag,在座的大佬们做个见证:一个月刷60场ABC,现在2021/6/21,第六天,已打卡十场。
A - Very Very Primitive Game
谁先吃完谁就输了
void work()
{
int a,b,c; cin >> a >> b >> c;
string A = "Takahashi", B = "Aoki";
if (!c) cout << (a > b ? A : B) << endl;
else cout << (b > a ? B : A) << endl;
}
B - Magic 3
小于s,大于t的才合法
void work()
{
int n, s, t; cin >> n >> s >> t;
bool flag = false;
while (n -- )
{
int x, y; cin >> x >> y;
if (x < s && y > t) flag = true;
}
if (flag) cout << "Yes" << '\n';
else cout << "No" << "\n";
return;
}
C - Bowls and Dishes
二进制枚举所有蛋糕的方法,然后更新最大值
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m; cin >> n >> m;
int a[110], b[110];
for (int i = 0; i < m; i ++ ) cin >> a[i] >> b[i];
pair<int, int> c[110];
int k; cin >> k;
for (int i = 0; i < k; i ++ )
cin >> c[i].first >> c[i].second;
int ans = 0;
for (int i = 0; i < 1 << k; i ++ )
{
vector<int> cnt(n + 1, 0);
for (int j = 0; j < k; j ++ )
cnt[i >> j & 1 ? c[j].first : c[j].second] ++;
int ct = 0;
for (int i = 0; i < m; i ++ )
if (cnt[a[i]] && cnt[b[i]]) ct ++;
ans = max(ans, ct);
}
cout << ans << endl;
return 0;
}
D - Staircase Sequences
设区间左端点为A,区间右端点为B,那么,此区间的和为(A+B)(B-A+1)/2 == n,令A+B = x,B-A+1=y,则xy结果为2n、
我们可以枚举2n的公约数,因为2B+1==x+y,所以,若x+y为奇数则合法
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main()
{
ll n; cin >> n;
ll ans = 0;
n = n << 1;
for (int i = 1; i <= n / i; i ++ )
if (n % i == 0)
{
ll y = i;
ll x = n / i;
if (x + y & 1)
ans += 2;
}
cout << ans << endl;
return 0;
}
涉及知识点:
矩阵的坐标变换
矩阵乘法
题意:给定n个坐标,给m个操作,有Q个询问。
m个操作分为四种,1,绕原点顺时针旋转90度,2,绕原点逆时针旋转90度,3,沿着x=p变为对称点,4,沿着y=p变为对称点。
Q个询问,询问第a次操作的第b个点会出现到哪里。
解决:旋转度数参考计算几何中的三角函数与坐标关系。可以想到用矩阵来做坐标转移:这里用到了三维坐标变换,可以学习一波。> 第二,我们令矩阵相乘,这样就可以静态查询每个点在任意时刻的变化了。这一需要注意一点,我们设变换为A,坐标为T,矩阵乘法为AT
但是,在我们进行再次矩阵变换的时候,我们是先与矩阵A相乘,再与T相乘,若是接下来的变换为B、C、D,我们运算的顺序应该为DCBAT
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
#define int long long
int n, m, q;
int x[N], y[N];
int g[N][4][4], t[4][4][4];
void get(int b[4][4], int a[4][4], int u)
{
for (int i = 1; i <= 3; i ++ )
for (int j = 1; j <= 3; j ++ )
for (int k = 1; k <= 3; k ++ )
g[u][i][j] += a[i][k] * b[k][j];
// printf("i = %d\n", u);
// printf("a[][] : \n");
// for (int i = 1; i <= 3; i ++ )
// {
// for (int j = 1; j <= 3; j ++ )
// printf("%3d ", a[i][j]);
// cout << endl;
// }
// printf("b[][] : \n");
// for (int i = 1; i <= 3; i ++ )
// {
// for (int j = 1; j <= 3; j ++ )
// printf("%3d ", b[i][j]);
// cout << endl;
// }
// printf("g[u][][] : \n", u);
// for (int i = 1; i <= 3; i ++ )
// {
// for (int j = 1; j <= 3; j ++ )
// printf("%3d ", g[u][i][j]);
// cout << endl;
// }
}
pair<int, int> get_id(int a[4][4], int b[4])
{
int c[4] = {0};
for (int i = 1; i <= 3; i ++ )
for (int j = 1; j <= 3; j ++ )
c[i] += a[i][j] * b[j];
return {c[1], c[2]};
}
signed main()
{
cin >> n;
for (int i = 1; i <= n; i ++ )
scanf("%lld%lld", &x[i], &y[i]);
cin >> m;
g[0][1][1] = g[0][2][2] = g[0][3][3] = 1;
t[0][1][2] = 1; t[0][2][1] = -1; t[0][3][3] = 1;
t[1][1][2] = -1; t[1][2][1] = 1; t[1][3][3] = 1;
t[2][1][1] = -1; t[2][2][2] = t[2][3][3] = 1;
t[3][1][1] = 1; t[3][2][2] = -1; t[3][3][3] = 1;
for (int i = 1; i <= m; i ++ )
{
int d; scanf("%lld", &d);
if (d == 1)
{
get(g[i - 1], t[0], i);
}
else if (d == 2)
{
get(g[i - 1], t[1], i);
}
else if (d == 3)
{
int p; scanf("%lld", &p);
t[2][1][3] = 2 * p;
get(g[i - 1], t[2], i);
}
else
{
int p; scanf("%lld", &p);
t[3][2][3] = 2 * p;
get(g[i - 1], t[3], i);
}
// for (int j = 1; j <= 3; j ++ )
// {
// for (int k = 1; k <= 3; k ++ )
// cout << g[i][j][k] << " " ;
// cout << endl;
// }
}
scanf("%lld", &q);
while (q -- )
{
int a, b; scanf("%lld%lld", &a, &b);
int s[4] = {0, x[b], y[b], 1};
pair<int, int> c = get_id(g[a], s);
cout << c.first << " " << c.second << endl;
}
return 0;
}