# 2017CCPC杭州题解(持续更新)

2025-12-01 17:02:33

2017CCPC 杭州

比赛

Problem A. Super-palindrome

#include

using namespace std;

int vis[30];

int vis1[30];

int main() {

int T;

cin >> T;

while (T--) {

memset(vis, 0, sizeof(vis));

memset(vis1, 0, sizeof(vis1));

string str;

cin >> str;

for (int i = 0; i < str.length(); i++) {

if (i & 1) {

vis1[str[i] - 'a']++;

} else {

vis[str[i] - 'a']++;

}

}

sort(vis, vis + 26);

sort(vis1, vis1 + 26);

cout << str.length() - vis[25] - vis1[25] << endl;

}

}

Problem B. Master of Phi

待补,我去问问我队友。 我不是很会推这个东西。

Problem C. Hakase and Nano

我出的博弈题! 变形的Nim。 就是每次可选择其中1堆石子取≥1颗石头。 然后一个人作弊,连续操作两次。 给你石子情况和先手安排。

发现必败态是1 1 1的情况,如果轮到H(作弊的人)拿(d==1),就必输,当然轮N也一样是必败态,推广到3的倍数堆都只有1颗石子的石子堆都是必败态。

H先手,除非初始情况就是必败态。 其他情况都是H胜利。

N先手,除非能把H变为必败态,不然还是H胜利。

再打一次居然WA了一次… 少了一次

#include

using namespace std;

int main() {

int T;

cin >> T;

while (T--) {

int n, x;

cin >> n;

int d;

cin >> d;

int cnt1 = 0;

for (int i = 0; i < n; i++) {

cin >> x;

if (x == 1)cnt1++;

}

if (d == 1) {

//H

if (n % 3 == 0 && cnt1 == n)

cout << "No" << endl;

else cout << "Yes" << endl;

} else {

//N

if (n % 3 == 0 && cnt1 == n - 1)

cout << "No" << endl;

else if (n % 3 == 1 && cnt1 == n - 1)

cout << "No" << endl;

else if (n % 3 == 1 && cnt1 == n)

cout << "No" << endl;

else

cout << "Yes" << endl;

}

}

}

Problem D. Master of Random

式子题,我再推一次看看。 题解明天写,绷不住了。

#include

using namespace std;

typedef long long ll;

const ll mod = 998244353;

ll qpow(ll a, int b)

{

ll res = 1;

while (b)

{

if (b & 1)

res = res * a % mod;

a = a * a % mod;

b >>= 1;

}

return res;

}

ll inv[100010];

int main()

{

int t;

for (int i = 1; i <= 100000; i++)

inv[i] = qpow(i, mod - 2);

scanf("%d", &t);

while (t--)

{

int n;

scanf("%d", &n);

ll pre = 0;

ll ans = 0;

for (int i = 1; i <= n; i++)

{

ll x;

scanf("%lld", &x);

ll now = pre * inv[i - 1] % mod + 1;

ans = (ans + now * x % mod * inv[n] % mod) % mod;

pre = (pre+now)%mod;

}

printf("%lld\n", ans);

}

}

/*

2

2

1 1

3

1 2 3

*/

Problem J. Master of GCD

待补

Problem K. Master of Sequence

待补