AtCoder Beginner Contest 129
A
水题
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int a, b, c;
cin >> a>> b >> c;
int ans = a+ b;
ans = min(ans ,a + c);
ans = min(ans, b + c);
cout << ans << endl;
return 0;
}
B
前缀和
const int MAXN = 105;
int a[MAXN];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int ans = 1e9+5;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) a[i] += a[i-1];
for(int i = 1; i <= n; i++)
{
ans = min(ans, int(abs(a[i] - a[n] + a[i])));
}
cout << ans << endl;
return 0;
}
C
变种fibonacci
const int MAXN = 1e5+5;
int vis[MAXN];
ll f[MAXN];
const int mod = 1e9+7;
int main()
{
//FIN;
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int m;
cin >> m;
for(int i = 0; i < m; i++)
{
int num;
cin >> num;
vis[num] = 1;
}
if(!vis[1]) f[1] = 1;
f[0] = 1;
for(int i = 2; i <= n; i++)
{
if(!vis[i-1]) f[i] += f[i-1];
if(!vis[i-2]) f[i] += f[i-2];
f[i] %= mod;
}
cout << f[n] << endl;
return 0;
}
D
比赛的时候抽风
先预处理即可
string s[2010];
int a[2010][2010], b[2010][2010];
int numa[2010 * 2010], numb[2010 * 2010];
int main()
{
int i, j, k, n, m, x, y, h = 0;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++)
{
cin >> s[i];
}
for (i = 0; i < n; i++)
{
x = 0;
for (j = 0; j < m; j++)
{
if (s[i][j] == '#')
{
if (x > 0)
{
numa[h] = x;
x = 0;
h++;
}
}
else
{
a[i][j] = h;
x++;
}
}
if (x > 0)
{
numa[h] = x;
h++;
}
}
h = 0;
for (i = 0; i < m; i++)
{
x = 0;
for (j = 0; j < n; j++)
{
if (s[j][i] == '#')
{
if (x > 0)
{
numb[h] = x;
x = 0;
h++;
}
}
else
{
b[j][i] = h;
x++;
}
}
if (x > 0)
{
numb[h] = x;
h++;
}
}
int ma = 0;
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
ma = max(ma, numa[a[i][j]] + numb[b[i][j]] - 1);
}
}
printf("%d", ma);
return 0;
}