题目地址:天梯赛
#include<bits/stdc++.h>
using namespace std;
int main() {
puts("To iterate is human, to recurse divine.");
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int a, b, c;
int main() {
cin >> a >> b >> c;
cout << a - b * c;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
char s[6];
int y, m;
int main() {
cin >> s;
if(strlen(s) == 6) {
cout << s[0] << s[1] << s[2] << s[3] << "-" << s[4] << s[5];
} else {
sscanf(s, "%2d%2d", &y, &m);
if(y < 22) cout <<"20";
else cout << "19";
printf("%02d-%02d", y, m);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
double n, m, k;
int main() {
cin >> n >> m;
while(n--) {
cin >> k;
if(k < m) printf("On Sale! %.1f\n", k);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int a[24], x;
int main() {
for(int i = 0; i < 24; ++i) {
cin >> a[i];
}
while(cin >> x) {
if(x < 0 || x >= 24) return 0;
cout << a[x] << " " << (a[x] > 50 ? "Yes" : "No") << endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int n, m;
string s, ans = "Wo AK le";
int main() {
cin >> n >> m, getchar();
for(int i = 0; i < n; ++i) {
getline(cin, s);
if(s.find("qiandao") == s.npos && s.find("easy") == s.npos) {
--m;
if(m < 0) ans = s;
}
}
cout << ans;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int n, x;
map<int, int> mp;
int main() {
cin >> n;
while(n--) {
cin >> x;
++mp[x];
}
cout << mp.begin()->first << " " << mp.begin()->second << endl << mp.rbegin()->first << " " << mp.rbegin()->second;
return 0;
}
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int a[N], n, x;
int main() {
cin >> a[0] >> a[1] >> n;
for(int i = 0, j = 2;; ++i) {
x = a[i] * a[i + 1];
if(x > 9) a[j++] = x / 10, a[j++] = x % 10;
else a[j++] = x;
if(j >= n) {
for(int i = 0; i < n; ++i) {
cout << (i ? " " : "") << a[i];
}
return 0;
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> mp;
int N, n, m, k, a, b, v, ans = INT_MAX, flag, cnt;
int f[205];
int main(){
cin >> N >> m;
while(m--) {
cin >> a >> b >> v;
mp.insert({{a, b}, v}), mp.insert({{b, a}, v});
}
cin >> k;
for(int i = 1; i <= k; ++i) {
unordered_set<int> st;
bool is_right = true;
int res = 0, now = 0;
cin >> n;
for(int i = 0; i < n; ++i) {
cin >> f[i];
if(st.count(f[i])) is_right = false;
st.emplace(f[i]);
}
if(!is_right || N != n) goto here;
f[n++] = 0;
for(int i = 0; i < n; ++i) {
if(mp.count({now, f[i]})) res += mp[{now, f[i]}], now = f[i];
else goto here;
}
++cnt;
if(ans > res) flag = i, ans = res;
here:;
}
cout << cnt << endl << flag << " " << ans;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n, m, s, x;
char a;
stack<char> st;
queue<char> vt[105];
int main() {
cin >> n >> m >> s;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < m; ++j) {
cin >> a;
vt[i].push(a);
}
}
while(cin >> x) {
if(x == -1) {
return 0;
}
if(!x) {
if(st.empty()) continue;
cout << st.top();
st.pop();
} else {
if(vt[x - 1].empty()) continue;
if(st.size() == s) {
cout << st.top();
st.pop();
}
st.push(vt[x - 1].front()), vt[x - 1].pop();
}
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int n, k, x, ans, flag, cnt;
vector<int> from[N];
int f[N];
int dfs(int x) {
if(f[x] != -1) return f[x];
int maxx = 0;
for(int i = 0; i < from[x].size(); ++i) {
maxx = max(maxx, dfs(from[x][i]));
}
f[x] = maxx + 1;
return f[x];
}
void print(int x) {
if(cnt) cout << " ";
++cnt, cout << x, k = N;
for(int i = 0; i < from[x].size(); ++i) {
if(f[from[x][i]] == f[x] - 1) k = min(k, from[x][i]);
}
if(k == N) return;
print(k);
}
int main() {
cin >> n;
for(int i = 0; i < n; ++i) {
cin >> k;
for(int j = 0; j < k; ++j) {
cin >> x;
from[i].push_back(x);
}
}
memset(f, -1, sizeof(f));
for(int i = 0; i < n; ++i) {
x = dfs(i);
if(x > ans) {
ans = x, flag = i;
}
}
cout << ans << endl;
print(flag);
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int n, m, x, cnt;
const int N = 1e4 + 5;
struct P{
vector<int> vt;
int sizes;
}p[N];
map<vector<int>, int> mp;
int main() {
cin >> n >> m;
for(int i = 0; i < n; ++i) {
vector<int> now;
for(int j = 0; j < m; ++j) {
cin >> x;
now.push_back(x);
}
++mp[now];
}
for(auto i : mp) {
p[cnt].sizes = i.second, p[cnt++].vt = i.first;
}
sort(p, p + cnt, [](P A, P B){
return A.sizes > B.sizes || A.sizes == B.sizes && A.vt < B.vt;
});
cout << cnt << endl;
for(int i = 0; i < cnt; ++i) {
cout << p[i].sizes;
for(int j : p[i].vt) {
cout << " " << j;
}
cout << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> a[N];
unordered_map<int, int> mp;
int n, m, k, x, now = 1;
int main() {
cin >> n >> m;
for(int i = 1; i <= n; ++i) {
cin >> k;
for(int j = 1; j <= k; ++j) {
cin >> x;
a[i].push_back(x);
}
}
while(m--) {
cin >> k >> x;
if(k == 0) now = a[now][x - 1];
else if(k == 1) mp[x] = now, cout << now << endl;
else now = mp[x];
}
cout << now;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n, m, k, x;
int main() {
cin >> n;
vector<int> a(n), res;
for(int i = 0; i < n; ++i) {
cin >> a[i];
}
cin >> m;
vector<vector<int>> b(m);
for(int i = 0; i < m; ++i) {
cin >> k, b[i].resize(k);
for(int j = 0; j < k; ++j) {
cin >> b[i][j];
}
}
auto print = [&]() {
for(int i = 0; i < (int)res.size(); ++i) {
cout << (i ? " " : "") << res[i] + 1;
}
};
function<void(int)> dfs = [&](int x) {
if(x == n - 1) {
print();
exit(0);
}
for(int i = 0; i < m; ++i) {
bool flag = true;
for(int j = 0; j < b[i].size(); ++j) {
if(b[i][j] != a[j + x]) {
flag = false;
break;
}
}
if(flag) {
res.push_back(i);
dfs(x + b[i].size() - 1);
res.pop_back();
}
}
};
for(int i = 0; i < m; ++i) {
bool flag = true;
for(int j = 0; j < b[i].size(); ++j) {
if(b[i][j] != a[j]) {
flag = false;
break;
}
}
if(flag) {
res.push_back(i);
dfs(b[i].size() - 1);
res.pop_back();
}
}
return 0;
}