2021牛客暑期多校训练营1(未完)

Ball Dropping:

题目链接
思路:利用相似三角形的比例求解,稍微把图画一下就行了

#include<bits/stdc++.h>
using namespace std;
int r,a,b,h;

int main(){
    scanf("%d%d%d%d",&r,&a,&b,&h);
    if(2*r<b){puts("Drop");return 0;}
    else    puts("Stuck");
    double x=(1.0*b*h)/(a-b);
    double ans=2.0*r/b*sqrt(1.0*x*x+b*b/4.0)-x;
    printf("%.8lf",ans);

Find 3-friendly Integers

题目链接
题意:给定一个区间,问这个区间里的数,有多少个是满足子串是三的倍数的
思路:我先打表找了一下规律,先打出1-100的表,再打出100-200的表,发现100-200的表里全部满足题目的要求,然我把100以内的表打出来以后,把1到100之间满足要求的数统计一下,就可以计算结果了,其中[l,r]之间的个数可以通过减去[1,l-r]得到,也就是构造一个前缀和。

#include<bits/stdc++.h>
using namespace std;
const int a[200]={1,
1,1,0,1,1,0,1,1,0,0,
1,0,0,1,0,0,1,0,0,0,
0,1,0,0,1,0,0,1,0,0,
0,0,0,0,0,0,0,0,0,0,
1,0,0,1,0,0,1,0,0,0,
0,1,0,0,1,0,0,1,0,0,
0,0,0,0,0,0,0,0,0,0,
1,0,0,1,0,0,1,0,0,0,
0,1,0,0,1,0,0,1,0,0,
0,0,0,0,0,0,0,0,0,0};
int pre[110];

long long calc(long long x){
    if(x<=100)  return pre[(int)x];
    else    return x-100+pre[100];
}

void solve(){
    for(int i=1;i<=100;i++)
        if(a[i]==0) pre[i]=pre[i-1]+1;
        else    pre[i]=pre[i-1];
    long long l,r,ans1,ans2;
    scanf("%lld%lld",&l,&r);
    if(l>r) swap(l,r);
    ans1=calc(l-1);
    ans2=calc(r);
    printf("%lld\n",ans2-ans1);
}

int main(){
    int T;
    scanf("%d",&T);
    while(T--)  solve();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值