ZZNU17级新生周赛第六场

A :n-1位数

题目要求输出一个n位数的后n-1位数。
我们可以在读入该数时不存它的第一位,只存后n-1位输出。

#include <stdio.h>

int main()
{
    int T,n;

    scanf("%d",&T);

    while(T--)
    {
        scanf("%*1d%d",&n);
        printf("%d\n",n);
    }
    return 0;
}

B :货币兑换
 根据题意这个人进行了两次兑换。
每次兑换都是现有钱数除以X乘以y

#include <stdio.h>

int main()
{
    double x,y,z;

    scanf("%lf%lf%lf",&x,&y,&z);

    printf("%.2lf\n",z/x/x*y*y);

    return 0;
}

 
C : 递归的效率问题 
只需修改题中给出的代码即可
 
#include<stdio.h>

int cnt;

int fib(int n)

{
    cnt++;

 if(n<=2)

    return 1;

 else

    return fib(n-1)+fib(n-2);

}

int main()

{

   int n;

   scanf("%d",&n);
   
   cnt=0;

   printf("%d\n",fib(n));
   printf("%d\n",cnt);

}

D : 直线与圆
根据两点式求出直线方程。
算出圆心到直线距离与圆半径比较大小即可。

#include<stdio.h>
#include<math.h>

int main()
{
    double A,B,C,x1,x2,y1,y2,x,y,r,d;

    while(~scanf("%lf%lf%lf%lf%lf%lf%lf",&x,&y,&r,&x1,&y1,&x2,&y2))
    {
        A=y1-y2;

        B=x2-x1;

        C=(x1-x2)*y2+(y2-y1)*x2;

        d=fabs((A*x+B*y+C)/sqrt(A*A+B*B));

        if(fabs(d-r)<1e-10)
        {
            printf("1\n");
        }
        else if(d>r)
        {
            printf("0\n");
        }
        else
        {
            printf("2\n");
        }
    }

    return 0;
}
E :QAQ
题目源于code force
三重for循环搜索。
#include <stdio.h>
#include <string.h>

int main()
{
    char str[110];

    int i,j,l,cnt;

    scanf("%s",str);

    cnt=0;

    for(i=0;i<strlen(str);i++)
    {
        if(str[i]=='Q')
        {
            for(j=1;i+j<strlen(str);j++)
            {
                if(str[i+j]=='A')
                {
                    for(l=1;i+j+l<strlen(str);l++)
                    {
                        if(str[i+j+l]=='Q')
                        {
                            cnt++;
                        }
                    }
                }
            }
        }
    }

    printf("%d\n",cnt);

    return 0;
}
F : LMX的可乐罐  
计算可乐余量和,和最大容量的两个易拉罐容量和比较大小即可。注意数据和会超int 推荐使用 long long
#include <stdio.h>
#include <math.h>
#define ll long long

int main()
{
    ll sum,max1,max2,x,tmp;
    int n,i;
    scanf("%d",&n);
    sum=0;
    max1=max2=-1;
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&x);
        sum+=x;
    }
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&x);
        max2=max2>x ? max2:x;
        if(max2>max1)
        {
            tmp=max1;
            max1=max2;
            max2=tmp;
        }
    }
    if(sum>max2+max1)
    {
        printf("NO\n");
    }
    else
    {
        printf("YES\n");
    }
    return 0;
}









  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值