常州大学新生寒假训练会试 - (E,G,H)

中午忘了这个比赛,晚了两个小时才打的,A了8题,感觉G题还不错,G题是队里的TaylorLi大佬用Taylor公式做出来的,Orz。E题说是数学题,只能说是个高中数学题,H题明明按题意做就行不知为什么大家都WA,可能卡到了什么细节。

E 这是一个数学题
解析:

对公式两边的阶乘化简的到公式:Ai=A0*(n-i)/n+An/n;

题中说数据保证了对于Ai的每一项都是整数,那么可得A0和An都是n的倍数,

于是令A0'=A0/n、An'=An/n,原公式变为:Ai=A0'*n+(An'-A0')*i

由于利用等差数列公式:[1,n]的和等于n*(1+n)/2,

得∑ (l<=i<=r)Ai=A0'*n*(r-l+1)+(r*(1+r)/2-(l-1)*(1+l-1)/2)*(An'-A0');

代码:

#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;
#define M 5005
ll n,a0,an;
int l,r,Q;

int main()
{
    //int i;
    ll ans,res;
    scanf("%lld%lld%lld%d",&n,&a0,&an,&Q);
    a0=a0/n; an=an/n;
    while(Q--)
    {
        scanf("%d%d",&l,&r);
        res=r*(1+r)/2;
        res-=(l-1)*(l)/2;
        ans=a0*n*(r-l+1)+(an-a0)*res;
        printf("%lld\n",ans);
    }
    return 0;
}

G 零下e度
利用泰勒展开式:e^x=1+(1/1!)*x+(1/2!)*x^2+(1/3!)*x^3+...+(1/n!)*x^n+O(x^n+1)

因为求n!/e所以令x=-1得到公式这里加到第n+1项就ok了,最终可以直接得到一个整数。

代码:

#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<string>
using namespace std;
typedef long long ll;
#define mod 998244353
const double e=exp(1.0);
ll qpow(ll a,ll b)
{
    ll ans=1;
    for (;b;a=a*a%mod,b>>=1)
        if (b&1)ans=ans*a%mod;
    return ans;
}
int main()
{
    ll n,i;
    while(scanf("%lld",&n)!=EOF)
    {
        if(n<=3)
        {
            ll ans=1;
            for(i=1;i<=n;i++)
            {
                ans*=i;
            }
            cout<<int(ans/e)<<endl;
        }else{
            ll ans=0;
            ll fun=1;
            ll temp;
            if(n%2)
            {
                temp=1;
                ans=-1;
            }else{
                temp=-1;
                ans=1;
            }
            for(i=n;i>=3;i--) //从后往前加
            {
                fun=fun*i%mod;
                ans=(ans+temp*fun)%mod;
                temp=-temp;
            }
            cout<<(ans+mod)%mod<<endl;
        }
    }
}


H 酸碱滴定
按题意做就ok

代码:

#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;
#define exp 0.000001
double a,b,c;
double ans;

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lf%lf%lf",&a,&b,&c);
        ans=a*c/b;
        ans=ans*10000;
        ll temp=ans;
        bool f=false;
        if(fabs(ans-1.0*temp)>exp)
            f=true;   //后面有数
        int t1,t3;
        t1=(temp/10)%10; //百位
        //t2=temp%10;      //个位
        t3=(temp/100)%10;//千位
        if(t1<=4)
        {
            temp=temp-temp%100;
        }else if(t1>=6)
        {
            temp=temp-temp%100+100;
        }else{
            if(f)
            {
                temp=temp-temp%100+100;
            }else{
                if(t3&1)
                    temp=temp-temp%100+100;
                else
                    temp=temp-temp%100;
            }
        }
        cout<<fixed<<setprecision(2)<<(1.0*temp/10000)<<endl;
    }
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值