codeforce round 325 C/D/E

C

#include<bits/stdc++.h>
using namespace std;
const int MAX_N=4010;

int n;
long long d[MAX_N],p[MAX_N],v[MAX_N];
int cure[MAX_N];

int main()
{
    freopen("C.in","r",stdin);
    while(~scanf("%d",&n)){
        int ans=0;
        for(int i=0;i<n;i++){
            scanf("%I64d%I64d%I64d",&v[i],&d[i],&p[i]);
        }
        for(int i=0;i<n;i++){
            if(p[i]<0) continue;
            cure[ans++]=i+1;
            long long cur=v[i],extra=0;
            for(int j=i+1;j<n;j++){
                if(p[j]<0) continue;
                p[j]-=(cur+extra);
                if(p[j]<0) extra += d[j];
                if(cur>0) cur--;
            }
        }
        printf("%d\n",ans);
        for(int i=0;i<ans;i++){
            printf("%d ",cure[i]);
        }
        printf("\n");
    }
    return 0;
}
View Code

D

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int n, k, sx;
char a[5][105];
typedef pair<int, int> P;

bool bfs(int sx) {
    queue<P> q; q.push(P(sx, 1));
    while(q.size()) {
        int x = q.front().first, y = q.front().second; q.pop();
        if(isalpha(a[x][++y])) continue;
        if(y >= n) return true;
        for(int i = -1; i <= 1; ++i) {
            int nx = x + i;
            if(nx < 1 || nx > 3) continue;
            if(isalpha(a[nx][y]) || isalpha(a[nx][y + 1])
                    || isalpha(a[nx][y + 2]) || a[nx][y + 2] == 1) continue;
            int ny = y + 2;
//            pr(nx); prln(ny);
            if(ny >= n) return true;
            a[nx][ny] = 1;
            q.push(P(nx, ny));
        }
    }
    return false;
}

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    int t; scanf("%d", &t);
    while(t--) {
        scanf("%d%d", &n, &k);
        memset(a, 0, sizeof a);
        for(int i = 1; i <= 3; ++i) {
            scanf("%s", a[i] + 1);
            if(a[i][1] == 's') sx = i;
        }
        puts(bfs(sx) ? "YES" : "NO");
    }
    return 0;
}
View Code

E

#include<bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
#define INF (1ll<<60)-1

using namespace std;
ll x,y;
ll gcd(ll a,ll b){
    return b==0?a:gcd(b,a%b);
}
int main(){
    scanf("%I64d%I64d",&x,&y);
    if(gcd(x,y)!=1LL) printf("Impossible\n");
    else {
        while(x && y){
            if(x>y){
                if(y==1) x--;
                printf("%I64dA",x/y);
                x=x%y;
            } else {
                if(x==1) y--;
                printf("%I64dB",y/x);
                y=y%x;
            }
        }
    }
    return 0;
}
View Code

 

posted on 2020-05-12 17:12  zsben  阅读(110)  评论(0编辑  收藏  举报

导航