A——暴力枚举计数就好了,可以参考这段代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 100003
#define MAN 1000100
char str[10];
int ans;
void ok(){
ans = 0;
int len = 0;
for(int i = 0; str[i] != '\0'; i++)
len++;
if(len == 1){
ans = 0;
for(char i = 'a'; i <= 'z'; i++){
ans++;
if(i == str[0])
return;
}
}
if(len == 2){
ans = 26;
for(char i = 'a'; i <= 'z'; i++){
for(char j = i + 1; j <= 'z'; j++){
ans++;
if(str[0] == i && str[1] == j)
return;
}
}
}
if(len == 3){
ans = 351;
for(char i = 'a'; i <= 'z'; i++){
for(char j = i + 1; j <= 'z'; j++){
for(char k = j + 1; k <= 'z'; k++){
ans++;
if(str[0] == i && str[1] == j && str[2] == k)
return;
}
}
}
}
if(len == 4){
ans = 2951;
for(char i = 'a'; i <= 'z'; i++){
for(char j = i + 1; j <= 'z'; j++){
for(char k = j + 1; k <= 'z'; k++){
for(char l = k + 1; l <= 'z'; l++){
ans++;
if(str[0] == i && str[1] == j && str[2] == k && str[3] == l)
return;
}
}
}
}
}
if(len == 5){
ans = 17901;
for(char i = 'a'; i <= 'z'; i++){
for(char j = i + 1; j <= 'z'; j++){
for(char k = j + 1; k <= 'z'; k++){
for(char l = k + 1; l <= 'z'; l++){
for(char p = l + 1; p <= 'z'; p++){
ans++;
if(str[0] == i && str[1] == j && str[2] == k && str[3] == l && str[4] == p)
return;
}
}
}
}
}
}
}
int main(){
while(scanf("%s", str) != EOF){
int x = 1;
for(int i = 0; str[i + 1] != '\0'; i++){
if(str[i + 1] <= str[i]){
x = 0;
printf("0\n");
}
}
if(x){
ok();
cout<<ans<<endl;
}
}
return 0;
}
E—— 统计子矩阵
#include <bits/stdc++.h>
using namespace std;
const int N = 510;
typedef long long LL;
int n, m, k;
int s[N][N];
int main() {
cin >> n >> m >> k;
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++) {
cin >> s[i][j];
s[i][j] += s[i - 1][j]; // 每列上的一维前缀和
}
LL ans = 0;
for (int i = 1; i <= n; i ++) // i j 上下边界
for (int j = i; j <= n; j ++)
for (int l = 1, r = 1, sum = 0; r <= m; r ++) { // l r 左右边界
sum += s[j][r] - s[i - 1][r];
while (sum > k) {
sum -= s[j][l] - s[i - 1][l];
l ++;
}
ans += r - l + 1;
}
cout << ans << endl;
return 0;
}
H—— Prefix Sum Addicts
#include <bits/stdc++.h>
using namespace std;
void solve()
{
int n, k;
cin >> n >> k;
vector<long long> s(n + 1);
for (int i = n - k + 1; i <= n; ++i)
cin >> s[i];
if (k == 1)
{
cout << "Yes" << endl;
return;
}
vector<long long> a(n + 1);
for (int i = n - k + 2; i <= n; ++i)
a[i] = s[i] - s[i - 1];
for(int i=n-k+3;i<=n;++i){
if (a[i-1]>a[i]){
cout << "No" << endl;
return;
}
}
if (s[n - k + 1] > a[n - k + 2] * (n - k + 1))
{
cout << "No" << endl;
return;
}
cout << "Yes" << endl;
}
int main()
{
int tests;
cin >> tests;
while (tests--) solve();
return 0;
}
I——龟兔赛跑预测
#include <iostream>
using namespace std;
int v1, v2, t, s, l;
int main()
{
scanf("%d %d %d %d %d", &v1, &v2, &s, &t, &l);
int s1 = 0, s2 = 0,i=0;
int t2 = l / v2;
while(s1<l && s2<l)
{
if (s1 - s2 >= s)
{
s2 += (t * v2);
i += t;
if (i >= t2) break;
}
else
{
s1 += v1;
s2 += v2;
i++;
}
}
if (s1 == s2 ) printf("D\n%d", t2);
else if (s1 > s2 ) printf("R\n%d", i);
else if (s1 < s2 ) printf("T\n%d", t2);
return 0;
}
标签:cout,int,题解,s1,ans,v2,测试,s2,第二次
From: https://www.cnblogs.com/expect-999/p/18327388