The 15th Heilongjiang Provincial Collegiate Programming Contest (A、G、H、L)

The 15th Heilongjiang Provincial Collegiate Programming Contest

链接:https://codeforces.com/gym/102803

A. August

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+5;
const double PI=acos(-1.0);

int t,a,b;

double f(double x)
{
    double y=acos((x+1.0*a)/a)-PI;
    y=y*2*b/PI;
    if(y<0) y=-y;
    return y;
}

double simpson(double l,double r)
{
    return (f(l)+f(r)+4*f((l+r)/2))*(r-l)/6;
}
double asr(double l,double r,double exps,double val)
{
    double mid=(l+r)/2;
    double lval=simpson(l,mid),rval=simpson(mid,r);
    if(fabs(lval+rval-val)<=15*exps)
    {
        return lval+rval+(lval+rval-val)/15;
    }
    return asr(l,mid,exps/2,lval)+asr(mid,r,exps/2,rval);
}

double asme(double l,double r,double exps)
{
    return asr(l,r,exps,simpson(l,r));
}
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&a,&b);
        double ans=PI*a*a;
        double res=asme(-2*a,0,1e-7);
        res*=2;
        printf("%.8lf\n",ans+res);
    }
    return 0;
}

G. Goodbye

#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std;
const int maxn=1e5+5;

int t,n;
vector<pair<int,int> > vec;
void solve(int n)
{
    for(int i=2; i*i<=n; ++i)
    {
        if(n%i==0)
        {
            int cnt=0;
            while(n%i==0)
                n/=i,cnt++;
            vec.push_back({i,cnt});
        }
    }
    if(n>1) vec.push_back({n,1});
}

int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        vec.clear();
        solve(n);
        int cnt=0;
        for(auto x: vec) cnt+=x.se;
        if(cnt<=1) puts("0");
        else if(cnt==2) puts("-1");
        else
        {
            auto x1=vec.back();
            vec.pop_back();
            auto x2=vec.back();
            int ans=1;
            if(x1.se>=2) ans=x1.fi*x1.fi;
            else if(x1.se==1) ans=x1.fi*x2.fi;
            printf("%d\n",ans);
        }
    }
    return 0;
}

H. Hate That You Know Me

#include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;
const int maxn=1e5+5;

ll a,b,n;

ll pre_x1(ll n)
{
    ll a=n,b=(n+1);
    if(a&1) b/=2;
    else a/=2;
    return a*b;
}

ll pre_x2(ll n)
{
    ll a=n,b=n+1,c=2*n+1;
    if(a&1) b/=2;
    else a/=2;
    if(a%3==0) a/=3;
    else if(b%3==0) b/=3;
    else if(c%3==0) c/=3;
    return a*b*c;
}

ll pre_x3(ll n)
{
    ll a=n,b=n+1;
    if(a&1) b/=2;
    else a/=2;
    return a*a*b*b;
}

ll solve(ll l,ll r,ll a)
{
    if(a==0) return r-l+1;
    if(a==1) return pre_x1(r)-pre_x1(l-1);
    if(a==2) return pre_x2(r)-pre_x2(l-1);
    if(a==3) return pre_x3(r)-pre_x3(l-1);
}

ll f(ll a,ll n)
{
    ll l=1,r;
    ll ans=0;
    while(l<=n)
    {
        r=n/(n/l);
        ans+=solve(l,r,a)*(n/l);
        l=r+1;
    }
    return ans;
}

int main()
{
    cin>>a>>b>>n;
    ll ans=f(a,n)^f(b,n);
    cout<<ans<<"\n";
    return 0;
}

L. Let’s Get Married

#include <bits/stdc++.h>
#define ll long long
#define int ll
using namespace std;
const int maxn=1e6+5;

int t;
int nowx,nowy;

int f(int x)
{
    if(x<=0) return 0;
    return 2ll*(1+x)*x;
}

int find(int id)
{
    int L=0,R=1e9;
    while(L<R)
    {
        int mid=(L+R)>>1;
        if(f(mid)>=id) R=mid;
        else L=mid+1;
    }
    return L;
}

void solve1(int id)
{
    int n=find(id);
    id-=f(n-1);
    int x,y;
    if(id==0) x=0,y=0;
    else if(id==1) x=0,y=n;
    else if(id<=2*n-1)
    {
        int r=id%2;
        int t=id/2;
        if(!r) x=t,y=n-t;
        else x=-t,y=n-t;
    }
    else if(id<=3*n)
    {
        id-=2*n;
        y=-id;
        x=n-id;
    }
    else if(id<=4*n)
    {
        id-=3*n;
        x=-id;
        y=-(n-id);
    }
    printf("%lld %lld\n",x-nowx,y-nowy);
    nowx=x,nowy=y;
}
void solve2(int x,int y)
{
    int n=abs(x)+abs(y);
    int id;
    id=f(n-1);
    if(y>0)
    {
        if(x>0) id+=2*abs(x);
        else id+=2*abs(x)+1;
    }
    else
    {
        if(x>=0) id+=2*n+abs(y);
        else id+=3*n+abs(x);
    }
    if(n==0) id=0;
    printf("%lld\n",id);
    nowx=x,nowy=y;
}
main()
{
    scanf("%lld",&t);
    nowx=0,nowy=0;
    while(t--)
    {
        int op,id,x,y;
        scanf("%lld",&op);
        if(op==1)
        {
            scanf("%lld",&id);
            solve1(id);
        }
        else
        {
            scanf("%lld%lld",&x,&y);
            solve2(x,y);
        }
    }
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值