L1-1 PTA使我精神焕发
解题思路:无
参考代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e2 + 5;
int main() {
cout << "PTA shi3 wo3 jing1 shen2 huan4 fa1 !";
return 0;
}
L1-2 6翻了
解题思路:模拟即可
参考代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e2 + 5;
vector<string>v;
string s;
int main() {
getline(cin, s);
string x;
int l = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '6') {
l++;
} else {
if (l) {
if (l > 9) {
cout << "27";
} else if (l > 3) {
cout << "9";
} else {
for (int j = 1; j <= l; j++) cout << "6";
}
l = 0;
}
cout << s[i];
}
}
if (l) {
if (l > 9) {
cout << "27";
} else if (l > 3) {
cout << "9";
} else {
for (int j = 1; j <= l; j++) cout << "6";
}
l = 0;
}
cout << endl;
return 0;
}
L1-3 敲笨钟
解题思路:模拟
参考代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e2 + 5;
int n;
string s;
int main() {
cin >> n;
getchar();
while (n--) {
getline(cin, s);
if (s.find("ong,") != -1 && s.find("ong.") != -1) {
int position = 0;
int icount = 1;
while ((position = s.find(" ", position)) != -1) {
position++;
icount++;
}
icount -= 3;
for (int i = 0; i < s.length(); i++) {
if (s[i] == ' ') {
icount--;
}
if (icount) {
cout << s[i];
} else {
cout << " qiao ben zhong." << endl;
break;
}
}
} else {
cout << "Skipped" << endl;
}
}
return 0;
}
L1-4 心理阴影面积
解题思路:小学算术
参考代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e2 + 5;
int main() {
int x, y;
cin >> x >> y;
cout << 100 * 100 / 2 - (100 - x)*(100 - y) / 2 - x*y / 2 - (100 - x)*y;
return 0;
}
L1-5 新胖子公式
解题思路:小学算术
参考代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e2 + 5;
int main() {
double k, m;
cin >> k >> m;
double x = k / (m * m);
printf("%.1lf\n", x);
if (x > 25) cout << "PANG\n";
else cout << "Hai Xing\n";
return 0;
}
L1-6 幸运彩票
解题思路:模拟
参考代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e2 + 5;
int main() {
int n;
cin >> n;
string s;
while (n > 1) {
n--;
cin >> s;
s = ' ' + s;
int sum1 = 0, sum2 = 0;
for (int i = 1; i <= 3; i++) sum1 += s[i] - '0';
for (int i = 4; i <= 6; i++) sum2 += s[i] - '0';
if (sum1 == sum2) cout << "You are lucky!\n";
else cout << "Wish you good luck.\n";
}
cin >> s;
s = ' ' + s;
int sum1 = 0, sum2 = 0;
for (int i = 1; i <= 3; i++) sum1 += s[i] - '0';
for (int i = 4; i <= 6; i++) sum2 += s[i] - '0';
if (sum1 == sum2) cout << "You are lucky!";
else cout << "Wish you good luck.";
return 0;
}
L1-7
解题思路:
参考代码
L1-8
解题思路:
参考代码
L2-1 特立独行的幸福
解题思路:用图把各个数字的关系存起来,入度为的0的即为特立独行的幸福数
参考代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e4 + 5;
int f(int x) {
int sum = 0;
while (x > 0) {
sum += pow(x % 10, 2);
x /= 10;
}
return sum;
}
bool g[N][N];
bool is[N];
bool check(int x) {
int cnt = 0;
while (1) {
cnt++;
if (x == 1) break;
if (cnt > 10) return 1;
g[x][f(x)] = 1;
x = f(x);
}
return 0;
}
bool is_p[N];
vector<int>pri(1);
bool iss[N];
void init() {
for (int i = 1; i <= 10000; i++) {
if (check(i)) is[i] = 1;
}
for (int i = 2; i <= 10000; i++) {
if (iss[i] == 0) pri.push_back(i);
for (int j = 1; j < pri.size() && i * pri[j] <= 10000; j++) {
iss[i * pri[j]] = 1;
if (i % pri[j] == 0) break;
}
}
for (int i = 1; i < pri.size(); i++) is_p[pri[i]] = 1;
}
int main() {
init();
int a, b;
cin >> a >> b;
int ok = 0;
for (int i = a; i <= b; i++) {
if (is[i] == 0) {
ok = 1;
int t = 1;
for (int j = a; j <= b; j++) {
if (g[j][i] == 1) {
t = 0;
break;
}
}
if (t) {
cout << i << ' ';
int cnt = 0;
int x = i;
while (1) {
cnt++;
x = f(x);
if (x == 1) break;
}
if (is_p[i]) cnt *= 2;
cout << cnt << endl;
}
}
}
if (!ok) cout << "SAD";
return 0;
}
L2-2
解题思路:
参考代码
L2-3 深入虎穴
解题思路:找到入口,从入口开始BFS找最长路即可
参考代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
int n, k, x;
vector<int>g[N];
int dis;
int ans;
struct node {
int x;
int t;
};
void bfs(int st) {
int res = 0;
queue<node>q;
q.push({st, 1});
while (!q.empty()) {
node now = q.front();
q.pop();
if (res < now.t) {
res = now.t;
ans = now.x;
}
for (int i = 0; i < g[now.x].size(); i++) {
q.push({g[now.x][i], now.t + 1});
}
}
}
bool is[N];
int main() {
int st;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &k);
for (int j = 1; j <= k; j++) {
scanf("%d", &x);
is[x] = 1;
g[i].push_back(x);
}
}
for (int i = 1; i <= n; i++) {
if (is[i] == 0) {
st = i;
break;
}
}
bfs(st);
cout << ans;
return 0;
}
L2-4 彩虹瓶
解题思路:使用栈模拟
参考代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e3 + 5;
int n, m, k;
int a[N];
bool check() {
int cnt = 1;
stack<int>s;
for (int i = 1; i <= n; i++) {
if (a[i] == cnt) {
cnt++;
} else {
while (!s.empty() && s.top() == cnt) {
s.pop();
cnt++;
}
if (s.empty()) s.push(a[i]);
else {
if (s.top() < a[i]) return 0;
else {
if (s.size() == m) return 0;
s.push(a[i]);
}
}
}
}
return 1;
}
int main() {
cin >> n >> m >> k;
while (k--) {
for (int i = 1; i <= n; i++) cin >> a[i];
if (check()) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}