【非官方题解】科大讯飞杯第18届上海大学程序设计联赛春季赛
A、组队比赛
最强和最弱一组,其余两个人一组,注意求绝对值,不要输出负数。。我就因为负数WA一发。
https://ac.nowcoder.com/acm/contest/view-submission?submissionId=43475100
#include <bits/stdc++.h>
using namespace std;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
typedef long long ll;
inline int read() {
int s = 0, w = 1; char ch = getchar();
while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); }
while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return s * w;
}
int a[5];
int main() {
for (int i = 1; i <= 4; ++i) a[i] = read();
sort(a + 1, a + 5);
printf("%d\n", abs(a[1] + a[4] - a[2] - a[3])); //别出负数
return 0;
} B、每日一报
输入数据,对体温大于等于38.0的数据加个标记,后面按要求排序,在遍历一遍,标记过的输出。。
这里说一句一定一定要看提示,提示写了按大于等于38.0,就直接写,我按温度-38.0大于等于1e-6,不知道为什么一直WA,可能精度卡住了把。。
https://ac.nowcoder.com/acm/contest/view-submission?submissionId=43483814
#include <bits/stdc++.h>
using namespace std;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
typedef long long ll;
inline int read() {
int s = 0, w = 1; char ch = getchar();
while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); }
while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return s * w;
}
const double eps = 1e-6;
struct Node {
int time;
int id;
double temp;
bool flag;
}a[105];
bool cmp(Node a, Node b) {
if (a.time != b.time) return a.time > b.time;
if (a.temp != b.temp) return a.temp > b.temp;
return a.id < b.id;
}
int main() {
int n = read();
int cnt = 0;
for (int i = 1; i <= n; ++i) {
scanf("%d %d %lf", &a[i].time, &a[i].id, &a[i].temp);
if (a[i].temp >= 38.0) a[i].flag = true, ++cnt;
else a[i].flag = false;
}
sort(a + 1, a + 1 + n, cmp);
printf("%d\n", cnt);
for (int i = 1; i <= n; ++i)
if (a[i].flag)
printf("%d %d %.1f\n", a[i].time, a[i].id, a[i].temp);
return 0;
} C、最长非公共子序列
简单思维题,如果两个字符串相等,输出-1,否则字符串长的一定不是字符串短的子串,输出A、B两串较长的那个
https://ac.nowcoder.com/acm/contest/view-submission?submissionId=43485496
#include <bits/stdc++.h>
using namespace std;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
string a, b;
int main() {
js;
cin >> a >> b;
int lena = a.size(), lenb = b.size();
if (a == b)
cout << "-1" << endl;
else
cout << max(lena, lenb) << endl;
return 0;
} D、最大字符集
通过上面你会惊奇的发现直接在11直接插入0,都不是上面去头或者去尾的子串。在对1和2进行一下特判就可以A了
https://ac.nowcoder.com/acm/contest/view-submission?submissionId=43490810
#include <bits/stdc++.h>
using namespace std;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
typedef long long ll;
int n;
int main() {
js;
cin >> n;
if (n == 1) {
cout << 1 << endl << 1 << endl;
}
else if (n == 2) {
cout << 2 << endl << "0" << endl << "11" << endl;
}
else {
cout << n - 1 << endl;
string ans = "11";
cout << ans << endl;
for (int i = 3; i <= n; ++i) {
ans.insert(1, "0");
cout << ans << endl;
}
}
return 0;
} E、美味的序列
根据题目要求,全部的都要吃,负数了也要吃进去,所以直接把输入的数据累加求和,减掉 项,公差是1的等差数列前
项和,就是答案。
#include <bits/stdc++.h>
using namespace std;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
typedef long long ll;
inline int read() {
int s = 0, w = 1; char ch = getchar();
while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); }
while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return s * w;
}
ll sum;
int main() {
ll n = read();
for (int i = 1; i <= n; ++i) {
int a = read();
sum += a;
}
sum -= n * (n - 1) >> 1;
printf("%lld\n", sum);
return 0;
} F、日期小助手
在快乐的百度只后我们可以知道1900年算星期的法子。我们2020年的程序员默认知道1900年1月1日星期一,在这个前提下,算天数,就可以找到对应年份的母亲节和父亲节日期,记得判断一下闰年,多加一个1。
这样我们求得输入年份得母亲节,父亲节,还有明年得母亲节,因为如果下个节日在明年,一定只有母亲节。母亲节在 父亲节在
只有21是st,注意特判一下。。
https://ac.nowcoder.com/acm/contest/view-submission?submissionId=43495856
#include <bits/stdc++.h>
using namespace std;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
typedef long long ll;
inline int read() {
int s = 0, w = 1; char ch = getchar();
while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); }
while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return s * w;
}
int calcmother(int year) {
int n, whichday, motherday, s = 0;
for (n = 1900; n < year; n++)
{
if ((n % 4 == 0 && n % 100 != 0) || (n % 400 == 0))
s = s + 366;
else
s = s + 365;
}
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
{
s = s + 121;
whichday = s % 7;
motherday = (14 - whichday);
return motherday;
}
else
{
s = s + 120;
whichday = s % 7;
motherday = (14 - whichday);
return motherday;
}
}
int calcfather(int year) {
int n, whichday, fatherday, s = 0;
for (n = 1900; n < year; n++)
{
if ((n % 4 == 0 && n % 100 != 0) || (n % 400 == 0))
s = s + 366;
else
s = s + 365;
}
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
{
s = s + 152;
whichday = s % 7;
fatherday = (21 - whichday);
return fatherday;
}
else
{
s = s + 151;
whichday = s % 7;
fatherday = (21 - whichday);
return fatherday;
}
}
int main() {
int T = read();
while (T--) {
int year = read(), mon = read(), day = read();
int montherdaynow = calcmother(year);
int montherdaynext = calcmother(year + 1);
int fatherdaynow = calcfather(year);
if (mon < 5 || mon == 5 && day < montherdaynow)
printf("Mother's Day: May %dth, %d\n", montherdaynow, year);
else if (mon < 6 || mon == 6 && day < fatherdaynow)
if (fatherdaynow == 21)
printf("Father's Day: June %dst, %d\n", fatherdaynow, year);
else
printf("Father's Day: June %dth, %d\n", fatherdaynow, year);
else
printf("Mother's Day: May %dth, %d\n", montherdaynext, year + 1);
}
return 0;
} 好了,签到完毕,后面自闭,不会写了。。。

曼迪匹艾公司福利 95人发布
