这次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