A
懂题意就没什么问题了、
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define mst(a, b) memset(a, b, sizeof a)
#define REP(i, x, n) for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
int main(){
LL n, t1, t2, v1, v2;
scanf("%lld%lld%lld%lld%lld", &n, &v1, &v2, &t1, &t2);
LL a = t1 + v1 * n + t1;
LL b = t2 + v2 * n + t2;
if(a == b) {
puts("Friendship");
} else if(a < b) {
puts("First");
} else {
puts("Second");
}
return 0;
}
B
题意:原本有一个数x,它的数位之和最小是k,然后给出一个数n给你,n和x长度一样,问n和x最少有多少个对应位置的数不相同、
思路:可以这么想,如何n这个数的数位之和sum大于等于k,很显然他们两个可以相等也就是说n == x,此时它们的贡献是0,如果sum < k,此时需要贪心一下
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define mst(a, b) memset(a, b, sizeof a)
#define REP(i, x, n) for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
char st[qq];
int main(){
int k; scanf("%d", &k);
scanf("%s", st);
int len = strlen(st);
int sum = 0;
for(int i = 0; i < len; ++i) {
sum += st[i] - '0';
}
if(k <= sum) {
puts("0");
return 0;
}
sort(st, st + len);
int cnt = sum;
for(int i = 0; i < len; ++i) {
cnt = cnt + (9 - (st[i] - '0'));
if(cnt >= k) {
printf("%d\n", i + 1);
return 0;
}
}
return 0;
}
C
题意:n个点,给出坐标和初始亮度,最开始是0时刻,现在问你t时刻矩阵x1 y1 x2 y2 中亮度和是多少,每过一秒每个点的亮度加1,如果超过c则变成0
思路:dp[i][j][k]代表矩阵0 0 i j 亮度为k的点有多少个,计算一下即可
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define mst(a, b) memset(a, b, sizeof a)
#define REP(i, x, n) for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
int n, q, c;
LL dp[105][105][12];
LL num[105][105][12];
int main(){
scanf("%d%d%d", &n, &q, &c);
int maxnX = 100, maxnY = 100;
for(int i = 0; i < n; ++i) {
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
num[x][y][z]++;
dp[x][y][z]++;
}
for(int i = 1; i <= maxnX; ++i) {
for(int j = 1; j <= maxnY; ++j) {
for(int k = 0; k <= c; ++k) {
dp[i][j][k] += dp[i - 1][j][k];
}
}
}
for(int i = 1; i <= maxnX; ++i) {
for(int j = 1; j <= maxnY; ++j) {
// printf("%d %d QQQ ", i, j);
for(int k = 0; k <= c; ++k) {
dp[i][j][k] += dp[i][j - 1][k];
// printf("%d ", dp[i][j][k]);
}
// puts("");
}
}
while(q--) {
int t, x1, x2, y1, y2;
scanf("%d%d%d%d%d", &t, &x1, &y1, &x2, &y2);
t = t % (c + 1);
LL sum = 0;
for(int k = 0; k <= c; ++k) {
LL see = (k + t) % (c + 1);
// printf("%d %d %d %d\n", dp[x2][y2][k], dp[x2][y1 - 1][k], dp[x1 - 1][y2][k], dp[x1 - 1][y1 - 1][k]);
LL tmp = (dp[x2][y2][k] - dp[x2][y1 - 1][k] - dp[x1 - 1][y2][k] + dp[x1 - 1][y1 - 1][k]);
sum += (see * tmp);
}
printf("%lld\n", sum);
}
return 0;
}
D
题意:求出回文度为1 ,2,3,..., len的个数
思路:参考:传送门
dp[i][j]代表区间[i, j]的回文度,用类似于区间dp的方法更新结果
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define mst(a, b) memset(a, b, sizeof a)
#define REP(i, x, n) for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 5000 + 10;
int dp[qq][qq];
int num[qq];
char st[qq];
int main(){
scanf("%s", st + 1);
int len = strlen(st + 1);
for(int l = 1; l <= len; ++l) {
for(int i = 1; i + l - 1 <= len; ++i) {
int j = i + l - 1;
if(l == 1) {
dp[i][j] = 1;
continue;
} else if(l == 2) {
if(st[i] == st[j]) dp[i][j] = 2;
else dp[i][j] = 0;
continue;
}
if(st[i] != st[j] || !dp[i + 1][j - 1]) continue;
dp[i][j] = 1;
int mid = l / 2;
if(dp[i][i + mid - 1] && dp[j - mid + 1][j]) {
dp[i][j] = dp[i][i + mid - 1] + 1;
}
}
}
for(int i = 1; i <= len; ++i) {
for(int j = i; j <= len; ++j) {
num[dp[i][j]]++;
}
}
for(int i = len - 1; i >= 1; --i) {
num[i] += num[i + 1];
}
for(int i = 1; i <= len; ++i) {
printf("%d ", num[i]);
}
puts("");
return 0;
}