Educational Codeforces Round 34 (Rated for Div. 2) A B C D

Educational Codeforces Round 34 (Rated for Div. 2)

A Hungry Student Problem

题目链接:

http://codeforces.com/contest/903/problem/A

思路:

直接模拟

代码:

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    scanf("%d",&n);
    while(n--) {
        int num,flag=0;
        scanf("%d",&num);
        for(int i=0;i<=num/3;++i) for(int j=0;j<=num/7;++j) if(3*i+7*j==num) flag=1;
        if(flag) printf("YES
");
        else printf("NO
");
    }
    return 0;
}

B The Modcrab

题目链接:

http://codeforces.com/contest/903/problem/B

思路:

模拟打怪兽的过程,需要注意的是,能够尽量打的情况坚决不舔包。就是说在一个回合中,怪兽能把你打死,但是你也能打死怪兽,这个时候先下手为强。其余情况下,保证自己活到下一回合。

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e7+5;
ll d[maxn];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll h1,h2,a1,a2,c1,tot=0;
    cin>>h1>>a1>>c1;
    cin>>h2>>a2;
    while(!(h2<=0)) {
        if(h2-a1<=0) {
            d[tot]=1;
            h2=h2-a1;
        } else if(h1-a2>0) {
            d[tot]=1;
            h2=h2-a1;
        } else {
            d[tot]=0;
            h1=h1+c1;
        }
        tot=tot+1;
        h1=h1-a2;
    }
    cout<<tot<<endl;
    for(int i=0;i<tot;i=i+1) {
        if(d[i]) {
            cout<<"STRIKE"<<endl;
        } else {
            cout<<"HEAL"<<endl;
        }
    }
    return 0;
}

C Boxes Packing

题目链接:

http://codeforces.com/contest/903/problem/C

思路:

找到某一个数的数量,且该数的数量是全部数里面最大的,就是答案。多此一举的离散化了一下。(¦3」∠)

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 1e9+5;
ll data[5005],ans[5005],res[5005];
int main() {
    ll n,maxnum=0;
    scanf("%I64d",&n);
    for(int i=0;i<n;++i) scanf("%I64d",&data[i]),ans[i]=data[i];
    sort(data,data+n);
    int tot=unique(data,data+n)-data;
    for(int i=0;i<n;++i) {
        ans[i]=lower_bound(data,data+tot,ans[i])-data;
        res[ans[i]]++;
    }
    for(int i=0;i<tot;++i) maxnum=max(maxnum,res[i]);
    printf("%I64d
",maxnum);
    return 0;
}

D Almost Difference

题目链接:

http://codeforces.com/contest/903/problem/D

思路:

爆了long long,所以使用long double。另外是用c++14提交的,c++11提交就是过不了,读入数据部分就会和本地不一样。

代码:


 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200005;
ll a[maxn];
int n;
long double sum=0;
map<ll,int> mp;
int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;++i) {
        scanf("%I64d",&a[i]);
        sum+=(long double)(i-1)*(long double)a[i];
        sum-=(long double)(n-i)*(long double)a[i];
    }
    for(int i=1;i<=n;++i) {
        mp[a[i]]++;
        sum-=(long double)mp[a[i]-1];
        sum+=(long double)mp[a[i]+1];
    }
    printf("%.0Lf
",sum);
    return 0;
}
原文地址:https://www.cnblogs.com/lemonbiscuit/p/8051686.html