空间换时间
题目一:直播获奖 ( P 7072 ) (P7072) (P7072)
/*
coder:sunshine
school:njupt
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n' //交互题删掉
#define x first
#define y second
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9 + 7;
const int N = 610;
int a[N], n, w;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> w;
for (int i = 1; i <= n; i++)
{
int tmp;
cin >> tmp;
a[tmp]++;
int sum = 0;
for (int j = 600; j >= 0; j--)
{
sum += a[j];
if (sum >= max(1, i * w / 100))
{
cout << j << ' ';
break;
}
}
}
return 0;
}
题目二:求和 ( P 2671 ) (P2671) (P2671)
/*
coder:sunshine
school:njupt
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n' //交互题删掉
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 10007;
constexpr int N = 1e5 + 10;
int n, m;
int a[N], b[N];
int s1[N][2], s2[N][2];
int ans;
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
for (int i = 1; i <= n; i++)
{
cin >> b[i];
s1[b[i]][i % 2]++;
s2[b[i]][i % 2] = (s2[b[i]][i % 2] + a[i]) % mod;
}
for (int i = 1; i <= n; i++)
{
int y = b[i];
ans += i * (s2[y][i % 2] + a[i] * (s1[y][i % 2] - 2) % mod) % mod;
ans %= mod;
}
cout << ans << endl;
return 0;
}
题目三:玉蟾宫 ( P 4147 ) (P4147) (P4147)
/*
coder:sunshine
school:njupt
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n' //交互题删掉
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
constexpr int N = 1010;
int n, m, ans = 0;
char a[N][N];
int h[N][N], l[N][N], r[N][N];
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cin >> a[i][j];
h[i][j] = 1;
r[i][j] = l[i][j] = j;
}
for (int j = 2; j <= m; j++)
{
if (a[i][j] == 'F' && a[i][j - 1] == 'F')
{
l[i][j] = l[i][j - 1];
}
}
for (int j = m - 1; j > 0; j--)
{
if (a[i][j] == 'F' && a[i][j + 1] == 'F')
{
r[i][j] = r[i][j + 1];
}
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if (i > 1 && a[i][j] == 'F')
{
if (a[i - 1][j] == 'F')
{
h[i][j] = h[i - 1][j] + 1;
if (l[i - 1][j] > l[i][j])
{
l[i][j] = l[i - 1][j];
}
if (r[i - 1][j] < r[i][j])
{
r[i][j] = r[i - 1][j];
}
if ((r[i][j] - l[i][j] + 1) * h[i][j] > ans)
{
ans = (r[i][j] - l[i][j] + 1) * h[i][j];
}
}
}
}
}
cout << 3 * ans << endl;
return 0;
}