AtCoder ABC345 A-D题解

比赛链接:ABC345

Problem A:

先签个到。

#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin>>S;
    if(S=='<'+string(S.size()-2,'=')+'>')
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}

Problem B:

就是上取整。

#include <bits/stdc++.h>
using namespace std;
int main(){
	long long X;
	cin>>X;
	if(X>0)
		cout<<(X-1)/10+1<<endl;
	else
		cout<<X/10<<endl;
	return 0;
}

当然,也可以用ceil函数。

Problem C:

非常简单的组合数学。说到底就是握手问题。

#include <bits/stdc++.h>
using namespace std;
int cnt[30];
int main(){
	string S;
	cin>>S;
	for(auto c:S)
		cnt[c-'a']++;
	int n=S.size();
	long long ans=0;
	for(int i=0;i<26;i++)
		ans+=(1LL*cnt[i]*(cnt[i]-1)/2);
	ans=1LL*n*(n-1)/2-ans;
	cout<<ans<<endl;
	return 0;
}

注意小心ans为0的情况,以及long long。

Problem D:

不可以,总司令!然后:

得25pts。

----------------------------------------------------------------------------------------------------------------------------

这题dfs爆搜即可,就是代码量有点大。

#include <bits/stdc++.h>
using namespace std;
const int maxn=50;
int N,H,W;
int A[maxn],B[maxn];
bool vis[maxn],f[maxn][maxn];
void dfs(int x,int y){
    if(x==H){
    	cout<<"YES"<<endl;
    	exit(0);
	}
    if(y==W)
        dfs(x+1,0);
    if(f[x][y])
        dfs(x,y+1);
    for(int i=0;i<N;i++){
        if(!vis[i]){
            vis[i]=true;
            for(int t=0;t<2;t++){
                if(x+A[i]<=H && y+B[i]<=W){
                    bool ok=true;
                    for(int u=0;u<A[i];u++){
                        for(int v=0;v<B[i];v++){
                            if(f[x+u][y+v])
                                ok=false;
                        }
                    }
                    if(ok){
                        for(int u=0;u<A[i];u++){
                            for(int v=0;v<B[i];v++)
                                f[x+u][y+v]=true;
                        }
                        dfs(x,y+1);
                        for(int u=0;u<A[i];u++){
                            for(int v=0;v<B[i];v++)
                                f[x+u][y+v]=false;
                        }
                    }
                }
                swap(A[i],B[i]);
            }
            vis[i]=false;
        }
    }
}
int main(){
    cin>>N>>H>>W;
    for(int i=0;i<N;i++)
        cin>>A[i]>>B[i];
    dfs(0,0);
    cout<<"NO"<<endl;
    return 0;
}

好了Y(^o^)Y,以上就是本期的全部内容。我们下期再见!

温馨提示:本期的代码都有问题,请不要无脑Ctrl C+Ctrl V

  • 8
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值