ABC 258 上分记录
作者:互联网
A
模拟,注意特判前导零。
signed main()
{
int x; cin >> x;
int h = x / 60;
x %= 60;
printf("%d:", h + 21);
if(x <= 10) printf("0");
printf("%d",x);
return 0;
}
B
我们发现他能够将这个矩形给复制成 \(9\) 份。
然后在复制后的矩形里去找最大值就行了。
const int dx[] = {0, -1, -1, -1, 0, 0, 1, 1, 1};
const int dy[] = {0, -1, 0, 1, -1, 1, -1, 0, 1};
bitset <1000> vis[1000];
ll Ans = -0x3f3f3f3f;
void dfs(int x, int y, int fx, ll ans, int step) {
if(step == n + 1) return Ans = max(Ans, ans), void();
int xx = x + dx[fx], yy = y + dy[fx];
if(xx >= 1 && xx <= 3 * n && yy >= 1 && yy <= 3 * n) {
// vis[xx][yy] = 1;
dfs(xx, yy, fx, ans * 10 + mp[xx][yy], step + 1);
// vis[xx][yy] = 0;
}
}
signed main()
{
n = read();
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
scanf("%1d", &mp[i][j]);
}
}
for(int i = 1; i <= n; i++) {
for(int j = n + 1; j <= 2 * n; j++) {
mp[i][j] = mp[i][j - n];
}
}
for(int i = 1; i <= n; i++) {
for(int j = 2 * n + 1; j <= 3 * n; j++) {
mp[i][j] = mp[i][j - 2 * n];
}
}
for(int i = n + 1; i <= 2 * n; i++) {
for(int j = 1; j <= n; j++) {
mp[i][j] = mp[i - n][j];
}
}
for(int i = n + 1; i <= 2 * n; i++) {
for(int j = n + 1; j <= 2 * n; j++) {
mp[i][j] = mp[i][j - n];
}
}
for(int i = n + 1; i <= 2 * n; i++) {
for(int j = 2 * n + 1; j <= 3 * n; j++) {
mp[i][j] = mp[i][j - 2 * n];
}
}
for(int i = 2 * n + 1; i <= 3 * n; i++) {
for(int j = 1; j <= n; j++) {
mp[i][j] = mp[i - 2 * n][j];
}
}
for(int i = 2 * n + 1; i <= 3 * n; i++) {
for(int j = n + 1; j <= 2 * n; j++) {
mp[i][j] = mp[i][j - n];
}
}
for(int i = 2 * n + 1; i <= 3 * n; i++) {
for(int j = 2 * n + 1; j <= 3 * n; j++) {
mp[i][j] = mp[i][j - 2 * n];
}
}
for(int k = 1; k <= 8; k++) {
for(int i = 1; i <= 3 * n; i++) {
for(int j = 1; j <= 3 * n; j++) {
dfs(i, j, k, 0, 1);
}
}
}
// printf("\n");
cout << Ans;
return 0;
}
C
sb 题,把字符串复制一遍,用一个指针来维护当前状态下的字符串。
其实可以对这个字符串建个主席树
signed main() {
int n, Q;
cin >> n >> Q;
cin >> s;
s += s;
int l = 0;
for (int i = 1; i <= Q; i++) {
int opt = read(), x = read();
if(opt & 1) l = (l + n - x) % n;
}
else cout << s[l + x - 1] << "\n";
}
return 0;
}
D
还是sb题,直接贪心就行了。
用一个前缀和还有前缀最小值来搞。
老套路了。
ll a[N], b[N];
ll ans = 2e18, qzh[N], c[N];
signed main()
{
int n = read(), x = read();
c[0] = 1e18;
for(int i = 1; i <= n; i++) {
a[i] = read(), b[i] = read();
qzh[i] = qzh[i - 1] + a[i] + b[i], c[i] = min(b[i] * 1ll, c[i - 1]);
}
for(int i = 1; i <= n; i++) {
ll m = qzh[i];
ans = min(ans, m + c[i] * (x - i));
}
cout << ans;
return 0;
}
G
计数题。
暴力做法是 \(\mathcal(O)(n^3)\)
我们发现用一个 bitset 就做到了 \(\mathcal(O)(\frac{n^3}{w})\)
bitset <4000> vis[4000];
signed main()
{
int n = read();
for(int i = 1; i <= n; i++) {
for(int j = n - 1; j >= 0; j--) {
int x;
scanf("%1d", &x);
vis[i].set(j, x);
}
}
ll ans = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(vis[i][n - j]) ans += (vis[i] & vis[j]).count();
}
}
cout << ans / 6;
return 0;
}
标签:ABC,int,ll,signed,vis,258,ans,上分,main 来源: https://www.cnblogs.com/tttttttle/p/16438673.html