キーエンスプログラミングコンテスト2024(AtCoder Beginner Contest 374)

A.Takahashi san 2

判断一个字符串是否以 san 结尾

using namespace reader;
int main(){
    string s;
    cin>>s;
    if(s[s.length()-1]=='n' and s[s.length()-2]=='a' and s[s.length()-3]=='s'){
        cout<<"Yes";
    }
    else cout<<"No";
}

B.Unvarnished Report

找两个字符串的第一个不相等位置

using namespace reader;
int main(){
    string a,b;
    cin>>a>>b;
    if(a==b){
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<=min(a.length()-1,b.length()-1);++i){
        if(a[i]!=b[i]){
            cout<<i+1;
            return 0;
        }
    }
    cout<<min(a.length(),b.length())+1;
}

C.Separated Lunch

将序列分成 \(A,B\) 两组,最小化两者较大值

让我想起一场古早时期涛哥保龄的模拟赛,好像是因为贪心贪假了喜保龄

\(N\) 小,搜即可

诶这题不搜怎么做来着,排序后贪心吗

using namespace reader;
#define int long long
int n,ans=0x7fffffff;
int A[21];
void dfs(int now,int a,int b){
    if(now>n){
        ans=min(ans,max(a,b));
        return;
    }
    dfs(now+1,a+A[now],b);
    dfs(now+1,a,b+A[now]);
}
signed main(){
    cin>>n;
    for(int i=1;i<=n;  ++i){
        cin>>A[i];
    }
    dfs(1,0,0);
    cout<<ans;
}

D.Laser Marking

又到了一月一度的 ABC D题放构式时间

若干线段,可以直线从线段一头以 \(S\text{ per }s\) 走到另一头,或者以 \(T\text{ per }s\) 在空间内自由移动,求从 \((0,0)\) 经过所有线段的最短时间

发现直接按题意搜就行

pure shit

using namespace reader;
#define int long long
int n,t,s;
struct node{
    int x,y;
}a[15];
struct edge{
    int to;
    long double w;
};
vector<edge>e[15];
long double dist(node a,node b){
    return sqrtl((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool vis[15];
long double ans=1e9;
void dfs(int s,long double now,int cnt){
    // cout<<s<<" "<<now<<" "<<cnt<<endl;
    vis[s]=true;
    if(s!=0 and s<=n and !vis[s+n]){
        dfs(s+n,now+dist(a[s],a[s+n])/t,cnt+1);
        vis[s]=false;
        return;
    }
    if(s!=2*n+1 and s>n and !vis[s-n]){
        dfs(s-n,now+dist(a[s],a[s-n])/t,cnt+1);
        vis[s]=false;
        return;
    }
    for(edge i:e[s]){
        if(!vis[i.to]){
            dfs(i.to,now+i.w,cnt+1);
        }
    }
    if(cnt==2*n){
        ans=min(ans,now);
    }
    vis[s]=false;
}
signed main(){
    scanf("%lld %lld %lld",&n,&s,&t);
    for(int i=1;i<=n;++i){
        scanf("%lld %lld %lld %lld",&a[i].x,&a[i].y,&a[i+n].x,&a[i+n].y);
    }
    for(int i=1;i<=2*n;++i){
        for(int j=1;j<=2*n;++j){
            if(i!=j and i!=j+n and i+n!=j){
                e[i].push_back({j,dist(a[i],a[j])/s});
            }
        }
    }
    for(int i=1;i<=2*n;++i){
        e[2*n+1].push_back({i,dist({0,0},a[i])/s});
    }
    dfs(2*n+1,0,0);
    printf("%.20Lf",ans);
}

E.Sensor Optimization Dilemma 2

posted @ 2024-10-08 18:56  HaneDaniko  阅读(25)  评论(1编辑  收藏  举报