赛后补题,账号不足未参加
2021-07-17 12:00:00 至 2021-07-17 17:00:00
Problem D. Determine the Photo Position
由于不允许分割、旋转或缩放图片,只能平移,而且老师只有一行,故每次考虑学生中每一行是否可以插入老师即可, 需要连续的背景'0'
统计每行连续'0'个数,进行插入并记录次数即可
代码如下:
#include <bits/stdc++.h>
#define ri int
typedef int lll;
typedef long long ll;
using namespace std;
const ll mod=80112002;
const ll inf=999999999;
const ll N=5e4+5;
ll n,m;
string a[3000],b;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> n >> m;
for(ri i=1;i<=n;i++) cin >> a[i];
cin >> b;
ll ans=0;
ll cnt=0;
for(ri i=1;i<=n;i++)
{
for(ri j=0;j<n;j++)
{
if(a[i][j]=='0') ++cnt;
if(a[i][j]!='0'||j==n-1)
{
if(cnt>=m) ans+=(cnt-m+1);
cnt=0;
}
}
}
cout << ans << '\n';
return 0;
}
Problem B. Ball Dropping
一道平面几何题目,可以用三角函数或者相似三角做(几何 × 贪心 √)
代码如下:
#include <bits/stdc++.h>
#define ri int
typedef int lll;
typedef long long ll;
using namespace std;
const ll mod=80112002;
const ll inf=999999999;
const ll N=5e4+5;
double r,a,b,h;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
scanf("%lf%lf%lf%lf",&r,&a,&b,&h);
if(2*r<=b) printf("Drop\n");
else
{
printf("Stuck\n");
double d=b*h/(a-b); //对应图中参数含义
double l=sqrt(d*d+b*b/4);
double ans=2*r*l/b-d;
printf("%.8lf\n",ans);
}
return 0;
}
Problem F. Find 3-friendly Integers
思维题,cf有类似得题目,脑子不够用啊,想不到
可以证明,三位数abc,必定是符合要求3-friendly Integers
比如长度为3的一个数a b c,假如a % 3 = 0则a就是3的倍数。
假如a % 3 = 1 ,那么b % 3 不能等于2,也不能等于0。等于0则 b 就直接是3的倍数,等于2则( a + b ) % 3 = 0 ,ab 就是3的倍数。因此b % 3 必 须 是 1 ,因此c % 3无论是0 , 1 还是2,都能找到3的倍数。
假如a % 3 = 2 ,同样能证明。
因此只要统计1-99之间得个数就可以
直接做check函数拆开判断即可,打表用a[]保存 a[i]表示1-i中符合要求得个数
代码如下:
#include <bits/stdc++.h>
#define ri int
typedef int lll;
typedef long long ll;
using namespace std;
const ll mod=80112002;
const ll inf=999999999;
const ll N=5e4+5;
ll l,r,t;
ll a[105];
bool check(ll x)
{
if(x<=9) return x%3==0;
else
{
ll a,b,k;
k=x;
a=k%10,k/=10,b=k;
return (a%3==0||b%3==0||(a+b)%3==0);
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
for(ri i=2;i<=99;i++)
{
if(check(i)) a[i]=a[i-1]+1;
else a[i]=a[i-1];
}
cin >> t;
while(t--)
{
ll ans=0;
cin >> l >> r;
if(l<=99)
{
if(check(l)) ans=-(a[l]-1);
else ans=-a[l];
if(r<=99) ans+=a[r];
else ans+=(r-100+1+a[99]);
}
else ans=r-l+1;
cout << ans << '\n';
}
return 0;
}