ZSTUOJ 2016ACM新生选拔赛 (更新中)

只A两题,技不如人~
题解待补完

4238 Save the Princess
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
const int INF=1<<30;
using namespace std;
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n,k;
        scanf("%d %d",&n,&k);
        n=n-1;
        n%2?puts("LYF"):puts("BH");
    }
    return 0;
}
4240 极差
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
const int INF=1<<30;
using namespace std;
const int N=1010;
int a[N];
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++) scanf("%d",&a[i]);
        sort(a+1,a+n+1);
        printf("%d\n",a[n]-a[1]);       
    }
    return 0;   
}
4242 校庆
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
const int INF=1<<30;
using namespace std;
bool leap(int i){
    if(i%4==0&&i%100) return 1;
    else if(i%4==0&&i%100==0&&i%400==0) return 1;
    else return 0;
}
int main(){
    int mon[2018][13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    for(int i=1;i<=2017;i++){
        mon[i][1]=31;
        mon[i][2]=28;
        mon[i][3]=31;
        mon[i][4]=30;
        mon[i][5]=31;
        mon[i][6]=30;
        mon[i][7]=31;
        mon[i][8]=31;
        mon[i][9]=30;
        mon[i][10]=31;
        mon[i][11]=30;
        mon[i][12]=31;

        if(leap(i)) mon[i][2]=29;

    }
    mon[2017][10]=28;
    int t;
    scanf("%d",&t);
    while(t--){
        int y,m,d;
        scanf("%d %d %d",&y,&m,&d); 
        int ans=0;
        int y1=2017-y,m1=10-m,d1=28-d;

        if(y1==0){
            if(m1==0){
                ans=d1;
            }
            else {
                ans=mon[y][m]-d;
                for(int i=m+1;i<=10;i++)
                ans+=mon[y][i];
            }
        }

        else if(y1){
            ans=mon[y][m]-d;
            for(int i=m+1;i<=12;i++){
                ans+=mon[y][i];
            }
            for(int i=1;i<=10;i++){
                ans+=mon[2017][i];
            }
            for(int i=y+1;i<2017;i++){
                for(int j=1;j<=12;j++){
                    ans+=mon[i][j];
                }
            }

        }
        printf("%d\n",ans);
    }
    return 0;   
}
4243 牛吃草
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#define S(l,r,d,a,b,s) l*l*(a-sin(a))+r*r*(b-sin(b))-s 
const double eps=1e-8;
const double PI=3.14159265357;
using namespace std;
double sqr(double x){
    return x*x;
}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        double x0,y0,x1,y1,r;
        scanf("%lf %lf %lf %lf %lf",&x0,&y0,&x1,&y1,&r);

        double a=0.0,b=0.0;
        double d=sqrt(sqr(x0-x1)+sqr(y0-y1));
        double s=sqr(r)*PI;
        double lf=d,rt=sqrt(sqr(r)+sqr(d)),mid=0.0;
        if(d+r/sqrt(2)-r<eps){
            printf("%.4f\n",r/sqrt(2));
            continue;
        }
        /*
2
0 0 10 10 2
        */

        while(rt-lf>eps){
            mid=(rt+lf)/2.0;
            double a=2*acos((sqr(mid)+sqr(d)-sqr(r))/(2.0*mid*d));
            double b=2*acos((sqr(d)+sqr(r)-sqr(mid))/(2.0*d*r));


            if(S(mid,r,d,a,b,s)>eps){
                rt=mid-eps;
            }
            else{
                lf=mid+eps;
            }

        }

        printf("%.4f\n",mid);
    }
}
4244 众数
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
const int INF=1<<30;
using namespace std;
const int N=1010;
int a[N];
int vis[N];
int vis2[N];
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        vector<int> v;
        memset(vis,0,sizeof(vis));
        memset(vis2,0,sizeof(vis2));
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            vis[a[i]]+=1;
            vis2[a[i]]+=1;
        }
        sort(vis+1,vis+1001);
        int cnt1=0;
        int cnt=vis[1000];
        for(int i=1;i<=1000;i++){
            if(vis2[i]==cnt){
                v.push_back(i);
                cnt1++;
            }
        }
        for(int i=0;i<cnt1;i++){
            if(i==cnt1-1)   printf("%d\n",v[i]);
            else printf("%d ",v[i]);
        }

    }
    return 0;
}
4245 KI的斐波那契
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <stack>
#include <algorithm>
typedef long long ll;
using namespace std;
const int N=100;
ll f[N];
void fi(){
    f[0]=1;f[1]=1;
    for(int i=2;i<=90;i++){
        f[i]=f[i-1]+f[i-2];
    }

}
int f1(ll n,ll m){
    if(n==1) return 1;
    if(n==2) return m==1?1:0;
    if(m>f[n-1]) return f1(n-2,m-f[n-1]);
    else return f1(n-1,m);

}
int main(){
    int t;
    scanf("%d",&t);
    fi();

    while(t--){
        ll n,m;
        scanf("%lld %lld",&n,&m);
        f1(n,m)?puts("a"):puts("b");

    }
}
4246 萌新吃果果
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
const int INF=1<<30;
typedef long long ll;
using namespace std;
char s[100010];
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n,k;
        scanf("%d %d",&n,&k);
        scanf("%s",s);
        int ans=n;

        int cnta=0,cntsum=0;

        for(int i=0;s[i];i++){
            if(s[i]=='a'){
                cnta++;
                cntsum++;
            }
            else if(s[i]=='b'){
                cntsum++;
                if(cnta){
                    ans++;
                    cnta=0;
                    cntsum=1;
                }
            }
            else if(s[i]=='c'){
                if(cntsum>=k){
                    ans++;
                    cntsum=1;
                }
                else cntsum++;
                cnta=0;
            }
        }

        printf("%d\n",ans);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值