AtCoder Beginner Contest 177

AtCoder Beginner Contest 177

A - Don’t be late

#include <bits/stdc++.h>
//#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int MAX = 1e5 + 10;
using namespace std;

int solve() {
    int d,t,s;
    cin>>d>>t>>s;
    cout<<(t*s>=d?"Yes":"No")<<endl;
    return 0;
}

signed main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _ = 1;
//    cin>>_;
    while (_--) {
        solve();
    }
    return 0;
}

B - Substring

#include <bits/stdc++.h>
//#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int MAX = 1e5 + 10;
using namespace std;

void solve() {
    string s,t;
    cin>>s>>t;
    int maxn=-1;
    for (int i = 0; i <=s.size()-t.size(); ++i) {
        int sum=0;
        for (int ii=i,j = 0; j < t.size(); ++j,++ii) {
            if (s[ii]==t[j])sum++;
        }
        if (maxn<sum)maxn=sum;
    }
    cout<<t.size()-maxn<<endl;
}

signed main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _ = 1;
//    cin>>_;
    while (_--) {
        solve();
    }
    return 0;
}

C - Sum of product of pairs

#include <bits/stdc++.h>
//#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int MAX = 2e5 + 10;
using namespace std;
ll a[MAX];
void solve() {
    ll n,sum=0,ans=0;
    cin>>n;
    for (int i = 0; i < n; ++i)
        cin>>a[i],sum+=a[i]%mod;
    for(int i=0;i<n;i++)
        ans=(((sum-a[i])%mod*a[i]%mod)+ans)%mod;
    cout<<(ans%2==0?ans/2:(ans+mod)/2)<<endl;
}

signed main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _ = 1;
//    cin>>_;
    while (_--) {
        solve();
    }
    return 0;
}

D - Friends

#include <bits/stdc++.h>
//#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
using namespace std;

int a[maxn],b[maxn];

int find_(int x){
    return x==a[x]?x:a[x]=find_(a[x]);//路劲压缩
}

void solve() {
    int n,m,max_=0;
    cin>>n>>m;
    for (int j = 0; j<=n; ++j)  a[j]=j,b[j]=1;
    for (int i = 0; i < m; ++i) {
        int x,y;
        cin>>x>>y;
        int fx=find_(x);
        int fy=find_(y);
        if (fx!=fy) a[fx]=fy,b[fy]+=b[fx];
    }
    for (int k =1; k <=n; ++k)  if(b[k]>max_) max_=b[k];
    cout<<max_;
}

signed main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _ = 1;
//    cin>>_;
    while (_--) {
        solve();
    }
    return 0;
}

E - Coprime

#include <bits/stdc++.h>
//#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
using namespace std;

int a[maxn];

int solve() {
    int n,all=0,b,flag=1;
    cin>>n;
    for (int i=0;i<n;++i)
        cin>>b,a[b]++,all=__gcd(all,b);
    for (int i=2;i<maxn;++i) {
        int sum=0;
        for (int j=i;j<maxn;j+=i) sum+=a[j];
        if (sum>1) flag=0;
    }
    return cout<<(flag?"pairwise coprime":all==1?"setwise coprime":"not coprime"),0;
}

signed main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _ = 1;
//    cin>>_;
    while (_--) {
        solve();
    }
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值