Codeforces Round #325 (Div. 2)ABC

来源:互联网 发布:c语言心型示爱代码 编辑:程序博客网 时间:2024/05/02 01:22

A - Alena's Schedule

分析:遇到1答案加一,遇到101加一。

#include <iostream>using namespace std;int main(){    int n, ans = 0, a[105];    cin >> n;    for(int i = 0 ; i < n ; i ++) {        cin >> a[i];        ans += a[i];        if(i > 1&&a[i-1] == 0&&a[i-2] == 1&&a[i] == 1) ans ++;    }    cout << ans << endl;    return 0;}
B - Laurenty and Shop
分析:用数组a把第一排房子到第一个房子的距离存下来,再用一个数组c吧第二排房子和最后一个房子的距离存下来,数组c表示第一排和第二排房子之间的距离,则取a+b+c的最小值就是第一个到最后一个房子之间的距离。返回时不走一样的路,把去超市时的c[i]标记一下,下次不走这条路就行了,a+b+c还是取最小值,相加就可以了。

#include <iostream>#include <cstring>using namespace std;const int INF = 999999999;int main(){    int n, t = INF, t2 = INF, j;    int a[2][100], b[100];    memset(a, 0, sizeof(a));    cin >> n;    for(int i = 1 ; i < n ; i ++)        cin >> a[0][i];    for(int i = 0 ; i < n-1 ; i ++)        cin >> a[1][i];    for(int i = 0 ; i < n ; i ++)        cin >> b[i];    for(int i = 1 ; i < n ; i ++)        a[0][i] += a[0][i-1];    for(int i = n-2 ; i >= 0 ; i --)        a[1][i] += a[1][i+1];    for(int i = 0 ; i < n ; i ++) {        if(a[0][i]+a[1][i]+b[i] < t) {            t = a[0][i] + a[1][i] + b[i];            j = i;        }    }    b[j] = INF;    for(int i = 0 ; i < n ; i ++)        if(a[0][i]+a[1][i]+b[i] < t2) t2 = a[0][i] + a[1][i] + b[i];    cout << t+t2 << endl;    return 0;}
C - Gennady the Dentist

分析:模拟。

#include <iostream>#include <cstring>#define LL long longusing namespace std;const int maxn = 4000 + 5;const int INF = 999999999;LL n, b, ans;LL v[maxn], d[maxn], p[maxn], q[maxn], a[maxn];int main(){    ans = 0;    cin >> n;    for(int i = 1 ; i <= n ; i ++) {        cin >> v[i] >> d[i] >> p[i];        q[i] = p[i];    }    for(int i = 1 ; i <= n ; i ++) {        if(p[i] >= 0) {            a[ans++] = i;            b = 0;            for(int j = i+1 ; j <= n ; j ++)                if(p[j] >= 0) {                    p[j] -= v[i] + b;                    if(p[j] < 0) b += d[j];                    if(v[i]) v[i]--;                }        }    }    cout << ans << endl;    for(int i = 0 ; i < ans ; i ++)        cout << a[i] << ' ';    cout << endl;    return 0;}



0 0