题目链接:https://ac.nowcoder.com/acm/contest/3036/
题解链接:https://www.nowcoder.com/discuss/352755
文章目录
A - 原初的信纸
#include <iostream>
using namespace std;
int main(void)
{
int t, n, minv, val;
cin >> t;
while (t--){
minv = 0;
cin >> n;
while (n--){
cin >> val;
minv = max(minv, val);
}
cout << minv << endl;
}
return 0;
}
B - 骑士的对决
#include <iostream>
#include <string>
using namespace std;
//S J B
int main(void)
{
char a, b, c;
cin >> a >> b >> c;
if (c == 'S'){
if (a == 'B' || b == 'B')
cout << "pmznb" << endl;
else
cout << "lyrnb" << endl;
}
else if (c == 'J'){
if (a == 'S' || b == 'S')
cout << "pmznb" << endl;
else
cout << "lyrnb" << endl;
}
else if (c == 'B'){
if (a == 'J' || b == 'J')
cout << "pmznb" << endl;
else
cout << "lyrnb" << endl;
}
return 0;
}
C - 秘密的议会
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
int t, y, n;
string s;
cin >> t;
while (t--){
y = n = 0;
cin >> s;
for (int i = 0; i < s.size(); i++){
if (s[i] == 'y' || s[i] == 'Y')
y++;
else if (s[i] == 'n' || s[i] == 'N')
n++;
}
if (y >= s.size() / 2)
cout << "pmznb" << endl;
else if (n >= s.size() / 2)
cout << "lyrnb" << endl;
else
cout << "wsdd" << endl;
}
return 0;
}
D - 城市的税金
在进行区间询问的时候,因为数的范围为1e9,不能用数组来记录每个数出现的次数
但是可以将区间中的数字放到另一个数组中,进行排序,找出最多有几个数连续即可。
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a[105], b[105];
void change(int idx)
{
a[idx] = a[idx] * 251 % 996 * 404 * 123;
}
int main(void)
{
int n, m, t, l, r;
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i];
while (m--){
cin >> t;
if (t == 1){
cin >> l >> r;
for (int i = l; i <= r; i++)
change(i);
}
else{
cin >> l >> r;
for (int i = l; i <= r; i++){
b[i] = a[i];
}
sort(b + l, b + r + 1);
int maxv = 1, cnt = 1;
for (int i = l + 1; i <= r; i++){
if (b[i] == b[i - 1])
cnt++;
else
cnt = 1;
maxv = max(maxv, cnt);
}
cout << maxv << endl;
}
}
return 0;
}
K - 消亡的质数
因式分解步骤:
x3−y3
=(x3−x2y)+x2y−(y3−xy2)−xy2
=x2(x−y)−y2(y−x)+xy(x−y)
=(x−y)(x2+xy+y2)
每次做数论题都感觉好神奇,数论只会gcd QAQ
M - 破碎的愿望
注意特判能被2n整除的情况
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
char str[100];
int main(void)
{
ll n, k;
cin >> n >> k;
cin >> str + 1;
for (int i = 1; i <= n; i++)
str[2 * n - i + 1] = str[i];
if (k % (2 * n) == 0)
cout << str[1] << endl;
else
cout << str[k % (2 * n)] << endl;
return 0;
}
默_silence
发布了184 篇原创文章 · 获赞 21 · 访问量 2万+
私信
关注