#include<algorithm> #include<cmath> #include<cstring> #include<iostream> #include<map> #include<queue> #include<stack> typedeflonglong ll; #define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define max(a, b) (a > b ? a : b) #define min(a, b) (a < b ? a : b) #define endl '\n' usingnamespace std;
#include<iostream> #include<algorithm> #include<queue> #include<cstring> #include<map> #include<stack> #include<cmath> typedeflonglong ll; #define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define max(a, b) (a > b ? a : b) #define min(a, b) (a < b ? a : b) #define endl '\n' usingnamespace std; intmain() { //IOS; int a, b; cin >> a >> b; cout << a / b; return0; }
如果两个人必须一起进,则输出 qing X zhao gu hao Y,其中 X 是陪同人的编号, Y 是小孩子的编号;
如果两个人都可以进但不是必须一起的,则输出 huan ying ru guan;
如果两个人都进不去,则输出 zhang da zai lai ba;
如果一个人能进一个不能,则输出 X: huan ying ru guan,其中 X 是可以入馆的那个人的编号。
输入样例1:
12 18 18 8
输出样例1:
18-Y 8-Y
qing 1 zhao gu hao 2
输入样例 2:
12 18 10 15
输出样例 2:
10-N 15-Y
2: huan ying ru guan
代码
#include<algorithm> #include<cmath> #include<cstring> #include<iostream> #include<map> #include<queue> #include<stack> typedeflonglong ll; #define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define max(a, b) (a > b ? a : b) #define min(a, b) (a < b ? a : b) #define endl '\n' usingnamespace std;
intmain() { // IOS; int y1, y2, a, b; cin >> y1 >> y2 >> a >> b; if (a > b) { if (b >= y1) { cout << a << "-Y " << b << "-Y" << endl; cout << "huan ying ru guan" << endl; } elseif (b < y1 && a >= y2) { cout << a << "-Y " << b << "-Y" << endl; cout << "qing 1 zhao gu hao 2" << endl; } elseif (a < y1) { cout << a << "-N " << b << "-N" << endl; cout << "zhang da zai lai ba" << endl; } elseif (b < y1 && a < y2) { cout << a << "-Y " << b << "-N" << endl; cout << "1: huan ying ru guan" << endl; } } else { if (a >= y1) { cout << a << "-Y " << b << "-Y" << endl; cout << "huan ying ru guan" << endl; } elseif (a < y1 && b >= y2) { cout << a << "-Y " << b << "-Y" << endl; cout << "qing 2 zhao gu hao 1" << endl; } elseif (b < y1) { cout << a << "-N " << b << "-N" << endl; cout << "zhang da zai lai ba" << endl; } elseif (a < y1 && b < y2) { cout << a << "-N " << b << "-Y" << endl; cout << "2: huan ying ru guan" << endl; } } return0; }
#include<algorithm> #include<cmath> #include<cstring> #include<iostream> #include<map> #include<queue> #include<stack> typedeflonglong ll; #define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define max(a, b) (a > b ? a : b) #define min(a, b) (a < b ? a : b) #define endl '\n' usingnamespace std;
intmain() { // IOS; int a, b; cin >> a >> b; int sum = 1; for (int i = 2; i <= a + b; i++) sum *= i; cout << sum; return0; }
#include<algorithm> #include<cmath> #include<cstring> #include<iostream> #include<map> #include<queue> #include<stack> typedeflonglong ll; #define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define max(a, b) (a > b ? a : b) #define min(a, b) (a < b ? a : b) #define endl '\n' usingnamespace std; int a[7], b[7]; intmain() { // IOS; for (int i = 1; i <= 6; i++) { cin >> a[i]; b[i] = a[i];//记录原始状态 if (a[i] != 6) a[i] = 6; else a[i] = 5; } int n; cin >> n; for (int i = 1; i < n; i++) for (int i = 1; i <= 6; i++) { a[i]--; if (a[i] == b[i]) a[i]--; }
for (int i = 1; i < 6; i++) cout << a[i] << " ";//万恶的格式控制 cout << a[6]; return0; }
L1-6 斯德哥尔摩火车上的题(15分)
题目描述
上图是新浪微博上的一则趣闻,是瑞典斯德哥尔摩火车上的一道题,看上去是段伪代码:
s = ‘’
a = ‘1112031584’
for (i = 1; i < length(a); i++) {
if (a[i] % 2 == a[i-1] % 2) {
s += max(a[i], a[i-1])
}
}
goto_url(‘www.multisoft.se/’ + s)
当然,能通过上述算法得到 112358 的原始字符串 a 是不唯一的。本题就请你判断,两个给定的原始字符串,能否通过上述算法得到相同的输出?
输入样例 1:
1112031584
011102315849
输出样例 1:
112358
输入样例 2:
111203158412334
12341112031584
输出样例 2:
1123583
112358
分析
字符串处理题,伪代码都给出来了,属于是送分。
代码
#include<algorithm> #include<cmath> #include<cstring> #include<iostream> #include<map> #include<queue> #include<stack> typedeflonglong ll; #define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define max(a, b) (a > b ? a : b) #define min(a, b) (a < b ? a : b) #define endl '\n' usingnamespace std;
intmain() { // IOS; string s1 = "", s2 = ""; string a, b; cin >> a >> b; for (int i = 1; i < a.size(); i++) if (a[i] % 2 == a[i - 1] % 2) s1 += max(a[i], a[i - 1]); for (int i = 1; i < b.size(); i++) if (b[i] % 2 == b[i - 1] % 2) s2 += max(b[i], b[i - 1]); if(s1 == s2) cout << s1; else cout << s1 << endl << s2; return0; }
#include<algorithm> #include<cmath> #include<cstring> #include<iostream> #include<map> #include<queue> #include<stack> typedeflonglong ll; #define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define max(a, b) (a > b ? a : b) #define min(a, b) (a < b ? a : b) #define endl '\n' usingnamespace std; constint N = 1e5 + 10; int vis[2][N]; intmain() { IOS; int n, m, q; cin >> n >> m >> q; int t, c; while (q--) { cin >> t >> c; if (!vis[t][c]) //第一次遇见才处理 { vis[t][c] = 1; if (t) m--; else n--; } } cout << n * m; return0; }
#include<algorithm> #include<cmath> #include<cstring> #include<iostream> #include<map> #include<queue> #include<stack> typedeflonglong ll; #define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define max(a, b) (a > b ? a : b) #define min(a, b) (a < b ? a : b) #define endl '\n' usingnamespace std; int stu[300]; int pta[300]; intmain() { IOS; int n, k, s; //人数,批次,分数线 cin >> n >> k >> s; int a, b; for (int i = 0; i < n; i++) { cin >> a >> b; if (a >= 175) //天梯赛175以上是硬性规定,不满足的可以不用考虑 { stu[a]++; //天梯赛分数为a的学生人数+1 if (b >= s) pta[a]++; //可以特招的天梯赛分数为a的学生人数+1 } } int ans = 0; for (int i = 175; i <= 290; i++) { if (stu[i]) { ans += pta[i]; //特招是一定可以全部推荐走的 stu[i] -= pta[i]; if (stu[i]) //如果还剩下的有天梯赛到175分而PTA不到企业规定分数的,则只能按照K个批次来推荐 ans += min(stu[i], k); //所以ans再次加上可以推荐的人数 } } cout << ans << endl; return0; }