AtCoder Beginner Contest 175

AtCoder Beginner Contest 175

A - Rainy Season

#include
using namespace std;
typedef long long ll;
const int MAX=1e5+10;

void solve(){
    int n=0,m=0;
    string s;
    cin>>s;
    for (int i = 0; i < 3; ++i) {
        if (s[i]=='R') n++;
        else n=0;
        if (m<n)m=n;
    }
    cout<<m<<endl;
}
int main(){
    int _=1;
//    cin>>_;
    while(_--){
        solve();
    }
}

B - Making Triangle

#include
using namespace std;
typedef long long ll;
const int MAX=1e5+10;
ll l[200];
int solve(){
    int n=0,m=0;
    cin>>n;
    for (int i = 0; i < n; ++i) {
        cin>>l[i];
    }
    //if (n<3) return cout<
    for(int i=0;i<n;i++){
        for (int j = i+1; j < n; ++j) {
            for (int k = j+1; k < n; ++k) {
                if (l[i]!=l[j]&&l[j]!=l[k]&&l[i]!=l[k]){
                  if ((l[i]+l[j]>l[k])&&(l[i]+l[k]>l[j])&&(l[k]+l[j]>l[i]))
                      m++;
                }
            }
        }
    }
    cout<<m<<endl;
    return 0;
}
int main(){
    int _=1;
//    cin>>_;
    while(_--){
        solve();
    }
}

C - Walking Takahashi

#include
using namespace std;
typedef long long ll;
const int MAX=1e5+10;
ll l[200];
int solve(){
    ll x,k,d,m;
    cin>>x>>k>>d;
    if (x==0){
        if (k%2==0)return cout<<0<<endl,0;
        else return cout<<d<<endl,0;
    }
    if (x<0)x=-x;
    ll n=x/d;
    if(x<d){
        if (k%2==0)return cout<<x<<endl,0;
        else return cout<<d-x<<endl,0;
    }
    if (n<k){
        if (n>0) m=x%d;
        if((k-n)%2==0)cout<<m<<endl;
        else cout<<d-m<<endl;
        return 0;
    } else{
        m=x-k*d;
        cout<<m<<endl;
        return 0;
    }
}
int main(){
    int _=1;
//    cin>>_;
    while(_--){
        solve();
    }
}

D - Moving Piece

#include
typedef long long ll;
#define MOD (long long)(1e9+7)
using namespace std;

ll n,k,vis[5005];
ll p[5005],c[5005],sum[5005],ans=-1e18;
int main(){
    cin >> n >> k;
    for(int i=1; i<=n; i++) cin >> p[i];
    for(int i=1; i<=n; i++) cin >> c[i];
    for(int i=1; i<=n; i++){
        ll s=c[i];
        vector<ll> t; t.push_back(s);
        for(int j=p[i]; j!=i; j=p[j]) s+=c[j],t.push_back(s);
        int len=t.size();
        for(int j=0; j<len; j++){
            ll rest=k-j-1;
            if(rest<0) break;
            ans=max(ans,t[j]+(rest/len)*max(s,0LL));
        }
    }
    cout << ans;
}

你可能感兴趣的:(C++,acm,actcoder,atcoder,acm竞赛,c++)