A 组队比赛
仅一行,包含四个整数 a, b, c, d (1≤a,b,c,d≤36811 \leq a, b, c, d \leq 36811≤a,b,c,d≤3681),中间以空格分隔,分别表示四个人的 CrossFire 分数。
在一行输出一个整数,表示两个队伍实力差的最小值。
输出
0
2263 2110 2172 2109
90
题解:这题就是将4个数分成两组,然后考虑如何分能得到两组之差最小值。
用sort排序然后abs(a[3]+a[0]-a[1]-a[2])就好
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { int a[4]; for(int i=0;i<4;i++) { cin>>a[i]; } sort(a,a+4); int s1=a[0]+a[3]; int s2=a[1]+a[2]; int ans=abs(s1-s2); cout<<ans; return 0; }
B 每日一报
第一行包含一个整数 n (1≤n≤1001 \leq n \leq 1001≤n≤100),表示需要处理的报送记录。
接下来 n 行,每行代表一条报送记录。
每一条记录包含两个整数和一个浮点数,中间空格分隔,分别表示报送日期、学号和体温,格式如题目描述中所述
输入保证所有的报送日期是 2020 年 1 月 30 日至今(2020 年 4 月 18 日)的合法日期,同一个学号不会在同一天进行多次报送。
第一行输出一个整数 m,表示需要上报备案的记录数量。
接下来 m 行,每行为一条记录。
记录的顺序应符合题目要求,记录格式应与输入格式中所述记录格式保持一致。
5 20200229 17122490 37.0 20200301 17122490 38.4 20200229 17122640 39.0 20200301 17122640 38.4 20200301 16122138 38.1
4 20200301 17122490 38.4 20200301 17122640 38.4 20200301 16122138 38.1 20200229 17122640 39.0
题解:就是算出超过38°的个数,并按要求排序,先按时间,时间相等按度数,度数相等按学号,自己写一个cmp就好
#include<bits/stdc++.h> using namespace std; typedef long long ll; struct f { int day; int num; float tem; }; bool cmp(f a,f b) { if(a.day!=b.day) { return a.day>b.day; } else if(a.tem!=b.tem) { return a.tem>b.tem; } else { return a.num<b.num; } } int main() { int n,i,j,k; cin>>n; int ans=0; struct f a[200]; for(i=0;i<n;i++) { cin>>a[i].day>>a[i].num>>a[i].tem; if(a[i].tem>=38.0) { ans++; } } sort(a,a+n,cmp); cout<<ans<<endl; cout<<fixed<<setprecision(1); int p=0; for(i=0;i<n;i++) { if(a[i].tem>=38.0) { cout<<a[i].day<<‘ ‘<<a[i].num<<‘ ‘<<a[i].tem<<endl; p++; } if(p==ans) { break; } } return 0; }
c:最长非公共子序列
Lemon 丢给你两个字母序列 s1s_1s1? 和 s2s_2s2? ,并无情地交给了你一个奇怪的任务——求最长非公共子序列。
第一行包含一个字符串 s1s_1s1? ,第二行包含一个字符串 s2s_2s2?。 (1≤∣s1∣,∣s2∣≤50001 \leq |s_1|, |s_2| \leq 50001≤∣s1?∣,∣s2?∣≤5000)
输入保证 s1s_1s1? 和 s2s_2s2? 均只包含小写字母。
在一行输出一个整数,表示最长非公共子序列的长度。
特别地,如果不存在非公共子序列,输出 -1 。
aba abc
3
lemon lemon
-1
题解:找出最长的非公共子序列是多大,如果这两个字符串长度不同但是内容不相等,那最长的子序列肯定两个字符串中更长的那个,
如果长度内容完全相等,那就没有非公共的子序列就输出-1,如果长度相等内容不相等,那最长的非公共子序列就是他们的长度,因为他们两个不相等
#include<bits//stdc++.h> using namespace std; typedef long long ll; int main() { string s1,s2; int len1,len2; cin>>s1>>s2; len1=s1.size(); len2=s2.size(); if(len1!=len2) { cout<<max(len1,len2); } else { if(s1==s2) { cout<<-1; } else { cout<<len1; } } return 0; }
D.最大字符集
仅一行,包含一个整数 n(1≤n≤3001 \leq n \leq 3001≤n≤300)
第一行输出这个集合的大小 k。
接下来 k 行每行输出一个 01 字符串,表示这个集合的一个元素。
答案不唯一,任何符合要求的答案都会被判为正确。
1
1 1
5
4 00 110 1010 11111
题解:这题主要就是找字串不同的有几种,其实就是一个规律题,列几个例子就会发现1的时候是1或者0只有一种,2的时候是0,和11
其他情况就是在00里面加个1就好,3的时候就是00 010,4的时候是00 010 0110
#include<iostream> using namespace std; int main() { int n,t=1; string a="00"; cin>>n; if(n==1) { cout<<1<<endl; cout<<"1"<<endl; } else if(n==2) { cout<<2<<endl; cout<<"1"<<endl; cout<<"00"<<endl; } else { cout<<n-1<<endl; cout<<a<<endl; while(t!=n-1) { a.insert(1,"1"); cout<<a<<endl; t++; } } }
E.美味的序列
链接:https://ac.nowcoder.com/acm/contest/5278/E
来源:牛客网
第一行包含一个整数 n (1≤n≤1051\leq n \leq 10 ^ 51≤n≤105) ,表示序列的长度。
第二行包含 n 个整数 a1,a2,…,ana_1, a_2 , \ldots ,a_na1?,a2?,…,an? (0≤∣ai∣≤1090 \leq |a_i| \leq 10^90≤∣ai?∣≤109),中间以空格分隔,分别表示这个序列每一部分的美味度。
在一行输出一个整数,表示吃完这个序列能获得的最大美味度的和。
3 3 2 3
5
1 -10
-10
题解:每吃掉一个数,其他数都会减1,问最后你能吃掉的最大数是多少,一道规律题,你减去的数是固定的是n(n-1),然后把
所有值算出来-去要减去的数就ok了
#include<iostream> #include<cmath> #include<iomanip> #include<cstdio> using namespace std; typedef long long ll; int a[100000+8]; int main() { ll i,j,k,n; cin>>n; ll sum=0; for(i=0;i<n;i++) { cin>>a[i]; sum+=a[i]; } ll s1=0; s1=((1+n-1)*(n-1))/2; cout<<sum-s1; return 0; }
F.日期小助手
链接:https://ac.nowcoder.com/acm/contest/5278/F
来源:牛客网
第一行包含一个整数 T (T≤100T \leq 100T≤100),表示测试数据的组数。
对于每组数据,包含三个整数 y, m, d,中间以空格分隔,分别表示今天的年、月、日。
输入保证是一个在公元 2000 年 1 月 1 日 到 2100 年 12 月 31 日间的合法日期。
对于每组数据,在一行输出下一个需要准备礼物的节日和日期。格式参考样例输出。
7 2000 1 1 2001 1 1 2002 1 1 2003 1 1 2020 1 1 2020 5 10 2020 6 21
Mother‘s Day: May 14th, 2000 Mother‘s Day: May 13th, 2001 Mother‘s Day: May 12th, 2002 Mother‘s Day: May 11th, 2003 Mother‘s Day: May 10th, 2020 Father‘s Day: June 21st, 2020 Mother‘s Day: May 9th, 2021
题解:这题首先要知道2000年的的4月最后一天是星期几和5月最后一天是星期几,然后有个顺序就是第二年如果不是闰年就+1是闰年就+2,这样就可以
当年的父亲节和母亲节是什么时候,然后再进行判断下一个节日是母亲节还是父亲节,输出注意号数不同后面的字母也不同,我用map一个一个列出来- -。
#include<iostream> #include<map> #define N 10001 using namespace std; int main(){ map<int,string>mp; mp[1]="st"; mp[2]="nd"; mp[3]="rd"; mp[4]="th"; mp[5]="th"; mp[6]="th"; mp[7]="th"; mp[8]="th"; mp[9]="th"; mp[10]="th"; mp[11]="th"; mp[12]="th"; mp[13]="th"; mp[14]="th"; mp[15]="th"; mp[16]="th"; mp[17]="th"; mp[18]="th"; mp[19]="th"; mp[20]="th"; mp[21]="st"; mp[22]="nd"; mp[23]="rd"; mp[24]="th"; mp[25]="th"; mp[26]="th"; mp[27]="th"; mp[28]="th"; mp[29]="th"; mp[30]="th"; mp[31]="st"; mp[32]="nd"; mp[33]="rd"; mp[34]="th"; mp[35]="th"; mp[36]="th"; mp[37]="th"; mp[38]="th"; mp[39]="th"; mp[40]="th"; int t,p,q,p1; int year,month,day; int flagm,flagf; cin>>t; while(t--){ p=5,q=1; cin>>year>>month>>day; for(int i=2000;i<=year;i++){ if((i%4==0&&i%100!=0)||(i%400==0)){ p=p+2;q=q+2; } else{ p=p+1;q=q+1; } } p=p%7;q=q%7; p1=p; for(int i=1;i<=31;i++){ p++; if(p/7==2){ flagm=i; break; } } for(int i=1;i<=31;i++){ q++; if(q/7==3){ flagf=i; break; } } if(month<5||(month==5&&day<flagm)){ cout<<"Mother‘s Day: May "<<flagm<<mp[flagm]<<","<<" "<<year<<endl; } else if((month==5&&day>=flagm)||(month==6&&day<flagf)){ cout<<"Father‘s Day: June "<<flagf<<mp[flagf]<<","<<" "<<year<<endl; } else{ //cout<<p1<<endl; year++; if((year%4==0&&year%100!=0)||(year%400==0)){ p1=p1+2; } else{ p1++; } p1=p1%7; //cout<<p1<<endl; for(int i=1;i<=30;i++){ p1++; if(p1/7==2){ flagm=i; break; } } cout<<"Mother‘s Day: May "<<flagm<<mp[flagm]<<","<<" "<<year<<endl; } } return 0; }
“科大讯飞杯”第18届上海大学程序设计联赛春季赛暨高校网络友谊赛补题报告2020.4.20
原文:https://www.cnblogs.com/liyongqi/p/12739536.html