1. 程式人生 > 其它 >2021牛客暑期多校訓練營1 (補題)

2021牛客暑期多校訓練營1 (補題)

賽後補題,賬號不足未參加
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;
}