urumqi 网络赛 C Coconut 水题

本文介绍了一个有趣的算法问题:如何判断给定的椰子数量和站点距离能否满足每日消耗需求到达终点。通过简单直接的方法实现,提供了完整的代码示例。

  题目链接: 放不出来

  题目描述: 每个站点有a[i] 个 椰子, 相邻站点的距离给出, 每天需要b个椰子, 问是否能够坚持到终点。

  解题思路: 水一波儿

  代码: 

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iterator>
#include <cmath>
#include <algorithm>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <queue>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define mem0(a) memset(a,0,sizeof(a))
#define sca(x) scanf("%d",&x)
#define de printf("=======\n")
typedef long long ll;
using namespace std;

const int maxn = 1e4;
int a[maxn];
int c[maxn];

int main() {
    int t;
    sca(t);
    int n, b;
    while( t-- ) {
        scanf( "%d%d", &n, &b );
        int sum = 0;
        for( int i = 0; i < n; i++ ) {
            sca(a[i]);
        }
        for( int i = 1; i < n; i++ ) {
            sca(c[i]);
        }
        sum += a[0];
        int flag = 1;
        for( int i = 1; i < n; i++ ) {
            sum -= c[i];
            if( sum < 0 ) {
                flag = 0;
                break;
            }
            sum += a[i];
        }
        if( flag ) {
            printf( "Yes\n" );
        }
        else {
            printf( "No\n" );
        }
    }
    return 0;
}
View Code

  思考: 水水更健康, 就是这题敲的还是有点儿慢

转载于:https://www.cnblogs.com/FriskyPuppy/p/7499468.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值