2021牛客暑期多校训练营1

news/2024/7/20 20:55:51 标签: ios, 字节跳动, typescript, interceptor, laravel

A.Alice and Bob

正常打表状态转移(如果该点可以转移到0点则当前点一定赢)

#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
bool vis[5005][5005];
void solve(){
    int x,y;
    cin>>x>>y;
    cout<<(vis[x][y]?"Alice\n":"Bob\n");
}
int main()
{
    for(int i=0;i<=5000;i++){
        for(int j=0;j<=5000;j++){
            if(vis[i][j])continue;
            for(int k=1;i+k<=5000;k++)
                for(int s=0;s*k+j<=5000;s++)
                    vis[i+k][s*k+j]=true;
            for(int k=1;j+k<=5000;k++)
                for(int s=0;s*k+i<=5000;s++)
                    vis[s*k+i][j+k]=true;
            break;
        }
    }
    ios::sync_with_stdio(false);
    int t=1;
    cin>>t;
    while(t--)
        solve();
    return 0;
}

b.Ball Dropping

高中计算几何

#include <bits/stdc++.h>
#define pll __builtin_popcountll
using namespace std;
using ll = long long ;
void solve()
{
    double r,a,b,h;
    cin>>r>>a>>b>>h;
    if(2.0*r<b){
        cout<<"Drop";
        return ;
    }
    double S=2.0*h/sqrt(4.0*h*h+(a-b)*(a-b));
    double C=(a-b)/sqrt(4.0*h*h+(a-b)*(a-b));
    double T=(2.0*h/(a-b));
    cout<<"Stuck\n";
    printf("%.10lf",r/C-b/2.0*T);
}
int main()
{
    //ios::sync_with_stdio(false);
    int t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

d.Determine the Photo Position

题意:把连续m个2的1xm的串插入方框0中有几种可能(签到直接暴力就行)

#include <bits/stdc++.h>
#define pll __builtin_popcountll
using namespace std;
using ll = long long ;
char s[2002][2002];
char u[2002];
void solve()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>s[i];
    cin>>u;
    ll ans=0;
    for(int i=0;i<n;i++){
        int res=0;
        for(int j=0;j<n;j++){
            if(s[i][j]=='0')res++;
            else {
                if(res>=m)
                ans+=res-m+1;
                res=0;
            }
        }
        if(res>=m)ans+=res-m+1;
    }
    cout<<ans<<"\n";
}
int main()
{
    ios::sync_with_stdio(false);
    int t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

f.Find 3-friendly Integers

找到区间内有多少个数是完美数(连续子串的和可以被3整除)
题解:
通过鸽巢原理可以发现当n>=100时候全是完美数

#include <bits/stdc++.h>
#define pll __builtin_popcountll
using namespace std;
using ll = long long ;
bool a[104];
void solve()
{
    ll l,r;
    cin>>l>>r;
    if(l>=100){
        cout<<r-l+1<<"\n";
        return ;
    }
    ll ans=0;
    for(ll i=l;i<=min(r,99*1ll);i++)
        ans+=a[i];
    if(r>=100)ans+=r-100+1;
    cout<<ans<<"\n";
}

int main()
{
    ios::sync_with_stdio(false);
    int t=1;
    for(int i=0;i<100;i++){
        if(i<10){
            if(i%3==0)
                a[i]=true;
        }
        else{
            int aa=i%10,bb=i/10;
            if(aa%3==0||bb%3==0||(aa+bb)%3==0)a[i]=true;
        }
        //cout<<i<<" "<<a[i]<<endl;
    }
    cin>>t;
    while(t--)
        solve();
    return 0;
}

h.Hash Function

题意:输出一个最小的数使得这个数对所有数取模可以得到n个不同的数(我当时没读懂被题目理解错了真以为是hash没想到是签到)
题解:直接枚举暴力就行

#include <bits/stdc++.h>
using namespace std;
int a[500005];
bool vis[500005];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
        vis[a[i]]=true;
    }
    sort(a+1,a+1+n);
    for(int i=n;;i++){
        bool f=1;
        for(int j=n;a[j]>=i;j--){
            if(vis[a[j]%i]){
                f=0;
                break;
            }
        }
        if(f) return cout<<i,0;
    }
}

k.Knowledge Test about Match

未完待续...


http://www.niftyadmin.cn/n/1082331.html

相关文章

myeclipse jsp和java字体设置

1、jsp字体 Window-->Preferences-->General-->Appearance-->Colors and Fonts-->Basic-->Text Font-->Chang 里面的“Text Font”即是针对文本编辑 器的字体进行设置的地方。直接在JSP文件编辑器上点击右键&#xff0c;然后选择属性&#xff0c;就可以设…

抓ipv6的数据包linux,如何限定apt-get使用IPv4或IPv6协议下载

如果你希望手动控制 Debian 或 Ubuntu 系统在使用 apt-get 更新系统或软件时走 IPv4 或 IPv6&#xff0c;可以通过配置其 Acquire group 选项来实现。Acquire group只有如下两个选项可供我们选择&#xff1a;ForceIPv4&#xff1a;全局强制使用 IPv4 协议下载ForceIPv6&#xf…

第一个ajax小实例(借助dwr包)

先说下引入这个dwr包的好处&#xff1a; 第一&#xff0c;它可以让js和后台语言交互&#xff0c;而且用户不用太了解它的逻辑。 第二&#xff0c;它可以让用户不用懂太宽泛的后台知识&#xff0c;只要会配置文件即可&#xff0c;不会涉及什么servlet。 第三&#xff0c;它能让后…

linux hostname机制,linux 查看服务器hostname

弹性云服务器 ECS弹性云服务器(Elastic Cloud Server)是一种可随时自助获取、可弹性伸缩的云服务器&#xff0c;帮助用户打造可靠、安全、灵活、高效的应用环境&#xff0c;确保服务持久稳定运行&#xff0c;提升运维效率三年低至5折&#xff0c;多种配置可选了解详情什么是弹性…

Hdu-1102 Constructing Roads

题目链接&#xff1a;http://acm.hdu.edu.cn/showproblem.php?pid1102 题目大意&#xff1a; N个村庄修路&#xff0c;给你他们之间的花费&#xff0c;然后还有一部分村庄已经修好路&#xff0c;求最小花费。 思路&#xff1a; 赤裸裸的最小生成树算法 prime算法代码如下&am…

BSGS

求解关于x的的方程\(a^xy{\mbox{%p}}\)证明P2485计算器 #include <bits/stdc.h> #define noans cout<<"Orz, I cannot find x!\n" using namespace std; using ll long long ; const int HashMod 100007; ll mi(ll a,ll b,ll mod){ll r1;while(b){if(1…

直方图中最大的矩形(单调栈)

直方图中最大的矩形 #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N 100000 ; using ll long long ; ll q[N],a[N]; int main() {ios::sync_with_stdio(false);int n;while(cin>>n,n){for(int i1;i…