# A. There Are Two Types Of Burgers

## Description

$1\leq t,b,p,f,h,c\leq 100$

## Code

#include <bits/stdc++.h>
using namespace std;

int t, b, p, f, h, c, ans;

int main() {
scanf("%d", &t);
while (t--) {
ans = 0;
scanf("%d%d%d%d%d", &b, &p, &f, &h, &c);
for (int i = 0; i <= p; i++)
for (int j = 0; j <= f; j++)
if (i+j <= b/2)
ans = max(ans, i*h+c*j);
printf("%d\n", ans);
}
return 0;
}

# B. Square Filling

## Description

$1\leq n,m\leq 50$

## Code

#include <bits/stdc++.h>
using namespace std;

int n, m, a[55][55], tmp;
int ans[55][55], tot;

void noans() {
puts("-1"); exit(0);
}
bool color(int x, int y) {
if (x == n || y == m || x == 0 || y == 0) return false;
if (!a[x][y] || !a[x+1][y] || !a[x][y+1] || !a[x+1][y+1]) return false;
ans[x][y] = 1;
return true;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
scanf("%d", &a[i][j]);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (a[i][j])
if (color(i-1, j-1) || color(i, j-1) || color(i-1, j) || color(i, j));
else noans();
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
tot += ans[i][j];
printf("%d\n", tot);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (ans[i][j])
printf("%d %d\n", i, j);
return 0;
}

# C. Gas Pipeline

## Description

$2\leq n\leq 2\cdot 10^5,1\leq a,b\leq 10^8$

## Solution

$f_{i,0/1}$ 表示修管道 $1\sim i$，且 $i$ 处管道高度为 $1/2$ 的最小花费。

## Code

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5+5;
const ll inf = 2e15;

int t, n, a, b;
char ch[N];
ll f[N][2];

int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d%d", &n, &a, &b);
scanf("%s", ch+1);
f[1][0] = a+2ll*b;
f[1][1] = 2ll*a+2ll*b;
for (int i = 2; i <= n; i++) {
f[i][0] = min(f[i-1][0]+a+b, f[i-1][1]+2ll*a+2ll*b);
f[i][1] = min(f[i-1][1]+a+2ll*b, f[i-1][0]+2ll*a+2ll*b);
if (ch[i] == '1') f[i][0] = inf;
}
printf("%I64d\n", f[n][0]);
}
return 0;
}

# D. Number Of Permutations

## Description

$1\leq n\leq 3\cdot 10^5$

## Code

#include <bits/stdc++.h>
using namespace std;
const int yzh = 998244353, N = 3e5+5;

int n, fac[N], ca[N], cb[N], ans, tmp, cnt = 1;
struct node {
int a, b;
bool operator < (const node &t) const {
return a == t.a ? b < t.b : a < t.a;
}
} x[N];

int main() {
scanf("%d", &n); fac[0] = 1;
for (int i = 1; i <= n; i++) {
scanf("%d%d", &x[i].a, &x[i].b);
fac[i] = 1ll*i*fac[i-1]%yzh;
ca[x[i].a]++, cb[x[i].b]++;
}
ans = fac[n], tmp = 1;
for (int i = 1; i <= n; i++)
tmp = 1ll*tmp*fac[ca[i]]%yzh;
(ans -= tmp) %= yzh;
tmp = 1;
for (int i = 1; i <= n; i++)
tmp = 1ll*tmp*fac[cb[i]]%yzh;
(ans -= tmp) %= yzh;
sort(x+1, x+n+1);
for (int i = 1; i <= n; i++)
if (x[i].b < x[i-1].b) {printf("%d\n", (ans+yzh)%yzh); return 0; }
tmp = 1;
for (int i = 1; i <= n+1; i++)
if (x[i].a == x[i-1].a && x[i].b == x[i-1].b) ++tmp;
else {
cnt = 1ll*cnt*fac[tmp]%yzh;
tmp = 1;
}
(ans += cnt) %= yzh;
printf("%d\n", (ans+yzh)%yzh);
return 0;
}

# E. XOR Guessing

## Description

$x\in[0,2^{14}-1]$

## Code

#include <bits/stdc++.h>
using namespace std;

int main() {
int a = (1<<7)-1, tmp, ans = 0;
int b = (1<<14)-1-a;
printf("? ");
for (int i = 1; i <= 100; i++)
printf("%d%c", (i<<7), " \n"[i == 100]);
fflush(stdout);
scanf("%d", &tmp);
ans += (tmp&a);
printf("? ");
for (int i = 1; i <= 100; i++)
printf("%d%c", i, " \n"[i == 100]);
fflush(stdout);
scanf("%d", &tmp);
ans += (tmp&b);
printf("! %d\n", ans);
fflush(stdout);
return 0;
}

# F. Remainder Problem

## Description

• 单点加；
• 询问：$500000$ 个位置模 $x$$y$ 的位置的值的和。

$1\leq q\leq 500000$

## Code

#include <bits/stdc++.h>
using namespace std;
const int N = 500000+5;

int cal[710][710], a[N], q, t, x, y;

int main() {
scanf("%d", &q);
while (q--) {
scanf("%d%d%d", &t, &x, &y);
if (t == 1) {
a[x] += y;
for (int i = 1; i <= 709; i++)
cal[i][x%i] += y;
} else {
if (x <= 709) printf("%d\n", cal[x][y]);
else {
int ans = 0;
for (int i = 0; i*x+y <= 500000; i++)
ans += a[i*x+y];
printf("%d\n", ans);
}
}
}
return 0;
}

# G. Indie Album

• 新取一个字符；
• 将前面某个字符串复制后，在末尾新添一个字符。

$1\leq n,q,\sum|t|\leq 4\cdot 10^5$

## Code

posted @ 2019-08-23 14:11  NaVi_Awson  阅读(127)  评论(0编辑  收藏