比赛链接
由于本人比较菜,再加上那天还有蓝桥杯模拟赛,所以昨晚前五个题就溜了
前五个题:不是很难,不要想太复杂了
A 组队比赛
先排序,然后sum=a1+a4-(a2+a3),输出sum的绝对值
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[9];
for(int i=1;i<=4;i++)
{
cin>>a[i];
}
sort(a+1,a+5);
int maxx=a[1]+a[4];
int minn=a[2]+a[3];
cout<<abs(maxx-minn);
} B 每日一报
主要考察就是排序,按照不同要求排序,sort+自定义cmp就OK
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
struct node{
int data;
double t;
int id;
}st[104];
bool cmp(node a,node b)
{
if(a.data!=b.data)return a.data>b.data;
if(abs(a.t-b.t)>0.0001)return a.t > b.t;
return a.id<b.id;
}
int main()
{
int n;
cin>>n;
int a,b;
double c;
int cnt=0;
for(int i=1;i<=n;i++)
{
cin>>a>>b>>c;
if(c<38.0)continue;
st[++cnt].data=a;
st[cnt].id=b;
st[cnt].t=c;
}
// cout<<st[1].t-st[4].t<<endl;
sort(st+1,st+1+cnt,cmp);
cout<<cnt<<endl;
for(int i=1;i<=cnt;i++)
{
printf("%d %08d %.1f\n",st[i].data,st[i].id,st[i].t);
}
return 0;
}
//日期 近
// 体温高
// 学号小 C 最长非公共子序列
我开始以为是dp,仔细分析题发现想复杂了。。
我们要仔细分析分析规则:
如果两个字母序列不一样长,那长的字母序列肯定不是短的,那么长的字母序列就是答案。比如abcd和abc,abcd肯定不是abc的子序列,那么最长非公共子序列的长度不就是4吗。也就是两个字母序列长度不一样,长的就是答案,如果一样长,那答案不就是他俩长度吗?反正一样长。但还有一个情况是两个子序列相等,此时输出-1
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s1,s2;
cin>>s1>>s2;
if(s1==s2)printf("-1\n");
else cout<<max(s1.length(),s2.length())<<endl;
}
D 最大字符集
这个题就是找规律,因为答案很多,输出一组即可,说明答案肯定存在某种规律,是方便输出的
样例给你的答案,往往不会带有规律,需要自己探寻
我找的规律就是:
00
010
0110
01110
......
两边是00,中间全是1,你会发现这样完美的符合了要求,而且好输出。
但要注意特殊情况,n=1时输出1
n=2时输出
0
11
#include<bits/stdc++.h>
using namespace std;
const int mod=10000;
int main() {
int n;
cin>>n;
if(n==1)
{
cout<<1<<endl<<1;
return 0;
}
if(n==2)
{
cout<<2<<endl;
cout<<0<<endl<<11<<endl;
return 0;
}
cout<<n-1<<endl;
for(int i=1;i<n;i++)
{
cout<<0;
for(int j=1;j<i;j++)
cout<<1;
cout<<0<<endl;
}
return 0;
}
E 美味的序列
还是找规律,找特点
无论从头还是从尾还是吃,其实降低的美味值得总数只会与n总长度有关,与其他无关
假设:
1 2 3 4 5 .....n
从头开始吃,先吃1,那么还没吃的部分(2.到n)都会下降1,然后吃2,剩下部分(3到n)又会降低1,依次这样
第一轮降低了n-1(从2到n)
第二轮降低了n-2(从3到n)
第三轮降低了n-3
....
第n-1轮降低了1
第n轮全部吃完
那么降低的总值就是1+2+。。。+(n-1)
等差数列求和n*(n-1)/2
再用总值减去
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x[100009];
ll sum=0;
int main()
{
ll n;
cin>>n;
for(int i=1;i<=n;i++)cin>>x[i];
for(int i=1;i<=n;i++)sum+=x[i];
cout<<sum-(n*(n-1)/2);
return 0;
}
F 日期小助手
貌似打表可以做,就是麻烦点,但是保险(狗头)
我们可以统计出母亲节基本是就在8 ~ 14号,父亲节再15 ~ 21号
int mother=14-((year-2000)+(year-2000)/4)%7;
int father=21-((year-1998)+(year-2000)/4+1)%7;
然后再注意一下闰年,特判2100,2100年不是闰年,直接算就可以了
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int year,month,d;
scanf("%d%d%d",year,month,d);
cin>>year>>month>>d;
int mother=14-((year-2000)+(year-2000)/4)%7;
int father=21-((year-1998)+(year-2000)/4+1)%7;
if(year==2100){
mother=9,father=20;
}
if(month>=1&&month<=4){
printf("Mother's Day: May %dth, %d\n",mother,year);
continue;
}
if(month==5){
if(d<mother) printf("Mother's Day: May %dth, %d\n",mother,year);
else{
if(father!=21) printf("Father's Day: June %dth, %d\n",father,year);
else printf("Father's Day: June %dst, %d\n",father,year);
}
continue;
}
if(month==6){
if(d<father){
if(father==21) printf("Father's Day: June %dst, %d\n",father,year);
else printf("Father's Day: June %dth, %d\n",father,year);
}
else{
if(year==2100) mother=8;
else if(year==2099) mother=9;
else mother=14-((year+1-2000)+(year+1-2000)/4)%7;
printf("Mother's Day: May %dth, %d\n",mother,year+1);
}
continue;
}
if(month<=12&&month>=7){
if(year==2100) mother=8;
else if(year==2099) mother=9;
else mother=14-((year+1-2000)+(year-2000+1)/4)%7;
printf("Mother's Day: May %dth, %d\n",mother,year+1);
continue;
}
}
return 0;
}G 血压游戏
H 纸牌游戏
I 古老的打字机
J 能到达吗
K 迷宫
L 动物森友会
感觉二分+网络流可以做

京公网安备 11010502036488号