A.组队比赛
题意:给四个人的分数,两两分队,求最小的实力差值
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; int main(){ int a[4],end; for(int i=0;i<4;i++){ cin>>a[i]; } sort(a,a+4); end=abs(a[0]+a[3]-a[1]-a[2]); cout<<end<<endl; return 0; }
B.每日一报
题意:给n个人的时间,学号,体温,查找其中体温大于等于38度的人,输出人数
并对这几个人按照规定的排序方式进行排序
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<iomanip> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> using namespace std; struct node{ int date; int std; double tep; }x[110],y[110]; bool cmp(node a,node b){ if(a.date!=b.date){ return a.date>b.date; } if(a.tep!=b.tep){ return a.tep>b.tep; } if(a.std!=b.std){ return a.std<b.std; } } int main(){ int n,i,j=0; int counts=0; cin>>n; for(i=1;i<=n;i++){ cin>>x[i].date>>x[i].std>>x[i].tep; if(x[i].tep>=38.0){ y[j].date=x[i].date; y[j].std=x[i].std; y[j].tep=x[i].tep; j++; } } sort(y,y+j,cmp); cout<<j<<endl; cout<<fixed<<setprecision(1); for(i=0;i<j;i++){ cout<<y[i].date<<" "; cout<<y[i].std<<" "; cout<<y[i].tep<<endl; } return 0; }
C.最长非公共子序列
题意:给定两个字符串,找出最长的非公共子序列,并输出其字符数
只要判断两个字符串相不相等就可以,若不相等,输出两个字符串中字符较多的那个
相等就输出-1
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<string> using namespace std; int main(){ string str1,str2; cin>>str1>>str2; if(str1!=str2){ cout<<max(str1.length(),str2.length())<<endl; }else{ cout<<"-1"<<endl; } return 0; }
D.最大字符集
题意:
输入一个n,要求如下:
1.每个字符串由 0 和 1 组成。
2.每个字符串长度在 1 到 n 之间,且两两长度不同。
3.集合中任何一个字符串都不是其他字符串的子串。
输出字符串的个数,然后输出所有字符串。
如果n=1,输出0或1;如果n=2,输出0,11或者1,00;
当n>3时,是有规律的,两头相等中间补
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; int main(){ int n,i,j; 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; for(i=1;i<=n-1;i++){ cout<<"1"; for(j=1;j<i;j++){ cout<<"0"; } cout<<"1"<<endl; } } return 0; }
E.美味的序列
题意:给长度为n的序列,每吃一次,没有被吃的部分就会减1,求最大的美味程度
吃的顺序不影响最后的美味程度,减少的美味程度为
n-1,n-2,n-3,.....,n-(n-1)
即((n-1)+(n-(n-1))*(n-1)/2;
把所有序列加起来减掉这个数即可
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> using namespace std; typedef long long ll; int main(){ ll n; cin>>n; ll sum=0; ll i,num; for(i=1;i<=n;i++){ cin>>num; sum+=num; } sum=sum-(n*(n-1))/2; cout<<sum<<endl; return 0; }