本周不是出题人,这是作为参赛选手写的题解。
感谢出题人让我10个题的题解可以贴六个链接完成(还有一个签到都不需要写代码)
A签到 输出6.5
B写两个循环判一下
#include<bits/stdc++.h>
using namespace std;
char s1[10010],s2[10010];
int p1,p2; int len1,len2;
int check(){
int i=0;
for(i=0;i+p1<len1&&i+p2<len2;i++){
if(s1[i+p1]!=s2[i+p2]) return 0;
}
if(s1[i+p1]==s2[i+p2]) return 1;
}
int main(){
scanf("%s",s1);
scanf("%d",&p1);
scanf("%s",s2);
scanf("%d",&p2);
len1=strlen(s1);
len2=strlen(s2);
if(check()){
printf("N0\n");
}
else
printf("YE5\n");
}
C题
《算法竞赛入门经典-训练指南》(即蓝书)54页
D题
原创签到题*1
读入时间后,先%(60*24),因为超过1天是没有意义的 ,如果是负数就变成60*24+t,往回退一天,然后就通过取模判断即可
E题
原创题*1
这题比赛中经过了修改,因为出题人使用了double ,精度比long double低,所以数据不正确。选手提交long double的程序不能通过。 比赛中进行了修改。
题解:
考虑在森林中修的路高2*c,宽x。其他 部分修的路高a-2*c,宽b-x 那两部分的路径长就是三角形斜边边长。设f(x)为修路代价,则f(x)一定在x取0和b时大中间小(一个开口向上的二次函数),那么通过三分即可求得结果。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const long double eps = 1e-7;//x表示精度
int n;
long double l,r;long double a,b,c;
long double f(long double x)
{
long double sum = 0;
sum+=2*sqrt(x*x+4*c*c);
sum+=sqrt((b-x)*(b-x)+(a-2*c)*(a-2*c));
return sum;
}
int main()
{
scanf("%Lf%Lf%Lf",&a,&b,&c);
long double left=0,right=b;
long double midl,midr;
while(left+eps<right){
midl=(left+right)/2;
midr=(midl+right)/2;
if(f(midl)<f(midr)){
right=midr;
}
else{
left=midl;
}
}
printf("%.5Lf",f(left));
return 0;
}
F题
原创题*2
题面是uva10795
但是这个蓝书(上文提到的《算法竞赛入门经典-训练指南》)上的27页,但是蓝书上的题是错的,所以这题很有意义!。
错误的原因看洛谷p1242
G题
蓝书第4页
H题
因为两个人的选取最佳策略,那么无论Alice最后剩下数字为多少,Bob一定会取到和它差值最小的那个,因此答案就是max{min{ai−bj}}
I题
J题