类似于排列组合,A左边算出来,T右边算出来,相乘累加。
#include<iostream>
#include<string>
#include<map>
using namespace std;
map<int, int>Ma;
int main() {
string s;
cin >> s;
int couP = 0, couT = 0, ans = 0;
for (int i=0; i < s.length(); i++) {
if (s[i] == 'P')couP++;
else if (s[i] == 'A')Ma[i] = couP;
}
for (int i = s.length() - 1; i >= 0; i--) {
if (s[i] == 'T')couT++;
else if (s[i] == 'A') {
ans += (couT*Ma[i]) % 1000000007;
ans %= 1000000007;
}
}
printf("%d", ans);
return 0;
}
1101和1093差不多的思想,但是1101有一个坑爹测试点2,需要多输出回车,不然会格式错误!
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
int N, max = 0, min = 1000000010;
scanf("%d", &N);
vector<int>V1(N), V2(N,0), V3;
for (int i = 0; i < N; i++) {
scanf("%d", &V1[i]);
if (max < V1[i]) {
V2[i] = 1;
max = V1[i];
}
}
for (int i = N - 1; i >= 0; i--) {
if (V1[i] < min) {
if (V2[i] == 1)V3.push_back(V1[i]);
min = V1[i];
}
}
sort(V3.begin(), V3.end());
printf("%d\n", V3.size());
for (int i = 0; i < V3.size(); i++) {
if(i==0)printf("%d", V3[0]);
else printf(" %d", V3[i]);
}
printf("\n");//不写就会导致测试点2格式错误
//但是我分析了很久,我觉的我的程序即使不需要这行也是满足题目要求的!
return 0;
}