4238: Save the Princess
博弈题,直接判断n奇偶以及k的位置是否是边界。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
int T,n,k;
cin>>T;
while(T--){
cin>>n>>k;
if(k!=1&&k!=n+1) puts(n%2?"BH":"LYF");
if(k==1||k==n+1) puts("LYF");
}
return 0;
}
4240: 极差
#include<bits/stdc++.h>
using namespace std;
int main(){
int T;
cin>>T;
while(T--){
int n,x;
scanf("%d",&n);
int mx=-1,mn=INT_MAX;
cout<<mn<<endl;
for(int i=1;i<=n;i++){
scanf("%d",&x);
if(mx<x) mx=x;
if(mn>x) mn=x;
}
printf("%d\n",mx-mn);
}
return 0;
}
4243: 牛吃草
这道题奇怪的被卡,由于比赛时没有直接出结果,没发现错误。结束了拍了一下,发现前半部分写的有问题。。。。
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
double get(long long x0,long long y0,long long x1,long long y1) {
return (double)sqrt( (x1-x0)*(x1-x0)*1.0 + (y1-y0)*(y1- y0)*1.0 );
}
int dsgn(double x){return x < -eps ? -1 : x > eps;}
double area(long long x0,long long y0,double r1,long long x1,long long y1,double r2){
double d = get(x0,y0,x1,y1);
double a1=acos((r1*r1+d*d-r2*r2)/(2.0*r1*d));
double a2=acos((r2*r2+d*d-r1*r1)/(2.0*r2*d));
return (a1*r1*r1+a2*r2*r2-r1*d*sin(a1));
}
double Area(double r, double R, double l){
if(dsgn(l - r - R) >= 0) return 0;
else if(dsgn(l - fabs(r - R)) <= 0){
if(r > R) r = R;
return pi * r * r;
}
double a = acos((l * l + r * r - R * R) / (2 * l * r));
double b = acos((l * l + R * R - r * r) / (2 * l * R));
double s1 = a * r * r, s2 = b * R * R;
double S1 = r * r * sin(a) * cos(a), S2 = R * R * sin(b) * cos(b);
return s1 + s2 - S1 - S2;
}
int main(){
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
long long T;
cin>>T;
while(T--){
long long x0,y0,x1,y1,r;
cin>>x0>>y0>>x1>>y1>>r;
double s1 = pi * r * r;
double dist = get(x0,y0,x1,y1);
double s2 = s1 / 2.0;
double r_=sqrt(s2/pi);
double lr_=max(0.0,dist-r),rr_=1e5,ansr;
while(dsgn(rr_-lr_)>0){
double midr_=(lr_+rr_)/2.0;
double s_=area(x0,y0,r,x1,y1,midr_);
if(dsgn(2.0 * Area(r, midr_, dist) - pi * r * r) < 0){
lr_ = midr_+0.000000001;
ansr=midr_;
}
else rr_=midr_-0.000000001;
}
printf("%.4lf\n",ansr);
}
return 0;
}
4244: 众数
#include <bits/stdc++.h>
using namespace std;
int stu[1111];
int ans[1111];
int main(){
int T;
cin>>T;
while(T--){
memset(stu,0,sizeof(stu));
int n,x;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&x);
stu[x]++;
}
int mx=0;
ans[0]=0;
for(int i=0;i<=1000;i++){
if(mx<stu[i]){
mx=stu[i];
ans[0]=1;
ans[ans[0]]=i;
}
else if(mx==stu[i]){
ans[0]++;
ans[ans[0]]=i;
}
}
for(int i=1;i<=ans[0];i++){
if(i-1) printf(" ");
printf("%d",ans[i]);
}
puts("");
}
return 0;
}
4245: KI的斐波那契
斐波那契,f[n-1]和f[n]表示的恰好是a+b和a的个数,每次去掉最大的,看最后结果情况。
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL read(){
LL x=0; char ch=getchar();
while (ch<'0' || ch>'9') ch=getchar();
while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
return x;
}
LL f[99];
bool dfs(LL n,LL m){
if(n==2) return m==1;
if(n==1) return 1;
if(m> f[n-1]) dfs(n-2,m-f[n-1]);
else dfs(n-1,m);
}
int main(){
LL T,n,m;
cin>>T;
f[0]=1;f[1]=1;
for(int i=2;i<=91;i++) f[i]=f[i-1]+f[i-2];
while(T--){
n=read();m=read();
puts(dfs(n,m)?"a":"b");
}
return 0;
}
吐槽一下,比赛时没有出评测结果,结果就GG了,赛后写的。
等待补充。。。