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

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

4238 Save the Princess

#include 
#include 
#include 
#include 
#include 
#include 
#include 
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 
#include 
#include 
#include 
#include 
#include 
#include 
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 
#include 
#include 
#include 
#include 
#include 
#include 
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 
#include 
#include 
#include 
#include 
#include 
#include 
#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)-rprintf("%.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 
#include 
#include 
#include 
#include 
#include 
#include 
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;iif(i==cnt1-1)   printf("%d\n",v[i]);
            else printf("%d ",v[i]);
        }

    }
    return 0;
}

4245 KI的斐波那契

#include 
#include 
#include 
#include 
#include 
#include 
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 
#include 
#include 
#include 
#include 
#include 
#include 
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;
}

你可能感兴趣的:(数学,暴力,acm,zstuoj)