前六签到
后六自闭
A. 组队比赛
排序取差
/* * @Author: Gehrychiang * @LastEditTime: 2020-04-18 12:03:45 * @Website: www.yilantingfeng.site * @E-mail: gehrychiang@aliyun.com */ #pragma GCC optimize(2) #include <bits/stdc++.h> using namespace std; int main() { //freopen("","r",stdin); //freopen("","w",stdout); int a[4]; for (int i = 0; i < 4; i++) { cin >> a[i]; } sort(a, a + 4); cout << abs(a[0] + a[3] - a[1] - a[2]) << endl; //fclose(stdin); //fclose(stdout); return 0; }
B. 每日一报
排序
/* * @Author: Gehrychiang * @LastEditTime: 2020-04-18 17:40:50 * @Website: www.yilantingfeng.site * @E-mail: gehrychiang@aliyun.com */ //#pragma GCC optimize(2) #include <bits/stdc++.h> using namespace std; struct node { string date; string ser; double temp; }; node in[105]; bool comp(node a, node b) { if (a.date != b.date) return a.date > b.date; else { if (a.temp != b.temp) return a.temp > b.temp; else { return a.ser < b.ser; } } } int main() { //freopen("","r",stdin); //freopen("","w",stdout); int n; cin >> n; int cnt = 0; for (int i = 0; i < n; i++) { string tmpa, tmpb; double tmpc; cin >> tmpa >> tmpb >> tmpc; if (tmpc >= 38.0) { in[cnt].date = tmpa; in[cnt].ser = tmpb; in[cnt].temp = tmpc; cnt++; } } sort(in, in + cnt, comp); cout << cnt << endl; for (int i = 0; i < cnt; i++) { cout << in[i].date << " " << in[i].ser << " "; printf("%.1lf\n", in[i].temp); } //fclose(stdin); //fclose(stdout); return 0; }
C. 最长非公共子序列
字符串比较即可,如果不相等即最长的非公共子序列即为较长串否则则无非公共子序列
/* * @Author: Gehrychiang * @LastEditTime: 2020-04-18 12:30:15 * @Website: www.yilantingfeng.site * @E-mail: gehrychiang@aliyun.com */ //#pragma GCC optimize(2) #include <bits/stdc++.h> using namespace std; int main() { //freopen("","r",stdin); //freopen("","w",stdout); string a, b; cin >> a; cin >> b; if (a != b) { cout << max(a.length(), b.length()); } else { cout << -1 << endl; } //fclose(stdin); //fclose(stdout); return 0; }
D. 最大字符集
找个小规律
对\(n>=3\)时
1 1 1 0 1 1 0 0 1 1 0 0 0 1 1 0 0 0 0 1 ……
必然不存在子串在集合当中
而当\(n<=2\)时,特判即可
/* * @Author: Gehrychiang * @LastEditTime: 2020-04-18 14:30:30 * @Website: www.yilantingfeng.site * @E-mail: gehrychiang@aliyun.com */ //#pragma GCC optimize(2) #include <bits/stdc++.h> using namespace std; int main() { //freopen("","r",stdin); //freopen("","w",stdout); int n; cin >> n; if (n == 1) { cout << 1 << endl; cout << 1 << endl; } else if (n == 2) { cout << 2 << endl; cout << 0 << endl; cout << 11 << endl; } else { cout << n - 1 << endl; for (int i = 2; i <= n; i++) { for (int p = 0; p < i; p++) { if (p == 0 || p == i - 1) { cout << 1; } else { cout << 0; } } cout << endl; } } //fclose(stdin); //fclose(stdout); return 0; }
E. 美味的序列
水公式
最终结果为\(sum-(n*(n-1)/2)\)
容易理解,每选一个的时候其余的均会减少\(1\)个单位,全局来看求和即可
/* * @Author: Gehrychiang * @LastEditTime: 2020-04-18 12:28:54 * @Website: www.yilantingfeng.site * @E-mail: gehrychiang@aliyun.com */ //#pragma GCC optimize(2) #include <bits/stdc++.h> using namespace std; int main() { //freopen("","r",stdin); //freopen("","w",stdout); long long n; cin >> n; long long sum = 0; for (int i = 0; i < n; i++) { long long tmp; cin >> tmp; sum += tmp; } sum -= (n * (n - 1)) / 2; cout << sum << endl; //fclose(stdin); //fclose(stdout); return 0; }
F. 日期小助手
推规律
次年的节日会在今年的基础上\(-1\)如果遇到闰年则额外\(-1\),考虑到第二周一定\(>=7\),第三周一定\(>=14\),如小于则补偿一周即可
/* * @Author: Gehrychiang * @LastEditTime: 2020-04-18 17:47:01 * @Website: www.yilantingfeng.site * @E-mail: gehrychiang@aliyun.com */ //#pragma GCC optimize(2) #include <bits/stdc++.h> using namespace std; int init[500][2]; bool chk(int a) { if (a % 100 == 0 && a % 400 == 0) { return true; } else if (a % 100 != 0 && a % 4 == 0) { return true; } else { return false; } } int main() { //freopen("","r",stdin); //freopen("","w",stdout); init[2000 - 2000][0] = 14; init[2000 - 2000][1] = 18; for (int i = 2001; i <= 2105; i++) { init[i - 2000][0] = init[i - 2000 - 1][0] - 1; init[i - 2000][1] = init[i - 2000 - 1][1] - 1; if (chk(i)) { init[i - 2000][0]--; init[i - 2000][1]--; } if (init[i - 2000][0] <= 7) { init[i - 2000][0] += 7; } if (init[i - 2000][1] <= 14) { init[i - 2000][1] += 7; } } int t; cin >> t; while (t--) { int yy, mm, dd; cin >> yy >> mm >> dd; if ((mm == 5 && init[yy - 2000][0] <= dd) || (mm == 6 && init[yy - 2000][1] > dd)) { //父亲节 if (init[yy - 2000][1] == 21) { printf("Father's Day: June 21st, %d\n", yy); } else if (init[yy - 2000][1] == 22) { printf("Father's Day: June 22nd, %d\n", yy); } else if (init[yy - 2000][1] == 23) { printf("Father's Day: June 23rd, %d\n", yy); } else { printf("Father's Day: June %dth, %d\n", init[yy - 2000][1], yy); } } else { //母亲节 if (mm >= 6) { yy++; //次年 } printf("Mother's Day: May %dth, %d\n", init[yy - 2000][0], yy); } } //fclose(stdin); //fclose(stdout); return 0; }