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();
}