Codeforces Round #615 (Div. 3)(思维大法好)

这次div没打,赛后补的题,除了最后一道树形dp没写,其他都补了

A.Collecting Coins

题解:应使(n+a+b+c)能被3整除并且max(a,b,c)-其他两个值的和<=n才可
代码

#include <bits/stdc++.h>
#define FOPI freopen("INPUT.TXT", "r", stdin)
#define DOPI freopen("OUTPUT.TXT", "w", stdout)
#define FOR(i, x, y) for(int i = x; i <= y; i ++)
#define ROF(i, x, y) for(int i = x; i >= y; i --)
using namespace std;
typedef long long int ll;
const int ind=0x3f3f3f3f,N=1e6+10;
const ll inlld=0x3f3f3f3f3f3f3f3f,mod=998244353;
int main()
{
   
    ios::sync_with_stdio(false);
    ll t,a,b,c,n;cin>>t;
    while(t--){
   
        cin>>a>>b>>c>>n;
        if((a+b+c+n)%3)cout << "NO";
        else {
   
            if(a<b)swap(a,b);
            if(b<c)swap(b,c);
            if(a<b)swap(a,b);
            if(abs(a-b)+abs(a-c)>n)cout<< "NO";
            else cout << "YES";
        }
        cout << endl;
    }
    return 0;
}

B.Collecting Packages

题解:维护一个坐标x,y
从当前坐标向上和向右查找,如果同时存在packages则out NO
否则以向上优先if去判断上面有则ans+U,右边有则ans+R保存后输出即可
代码:

#include <bits/stdc++.h>
#define FOPI freopen("INPUT.TXT", "r", stdin)
#define DOPI freopen("OUTPUT.TXT", "w", stdout)
#define FOR(i, x, y) for(int i = x; i <= y; i ++)
#define ROF(i, x, y) for(int i = x; i >= y; i --)
using namespace std;
typedef long long int ll;
const int ind=0x3f3f3f3f,N=1e3+10;
int s[N][N];
vector<char>ans;
const ll inlld=0x3f3f3f3f3f3f3f3f,mod=998244353;
int main()
{
   
    ios::syn
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值