Problem A. Collecting Coins
Solution
Observe that the easiest solution would be increase every one‘s number of coins to \(\max(A,B,C)\)
Then all we have to do is to distribute the coins left evenly to three of them
which is typically just checking if the number of coins left is divisible to 3
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 #define sf scanf 5 #define pf printf 6 #define fo(i,s,t) for(int i = s; i <= t; ++ i) 7 #define fd(i,s,t) for(int i = s; i >= t; -- i) 8 #define mp make_pair 9 #define fi first 10 #define se second 11 #define VI vector<int> 12 #define pii pair<int,int> 13 #define fp freopen 14 #ifdef MPS 15 #define D(x...) printf(x) 16 #else 17 #define D(x...) 18 #endif 19 typedef long long ll; 20 typedef double db; 21 22 int main() 23 { 24 #ifdef MPS 25 fp("1.in","r",stdin); 26 fp("1.out","w",stdout); 27 #endif 28 int t; 29 sf("%d",&t); 30 while(t--) 31 { 32 int a,b,c,n; 33 sf("%d%d%d%d",&a,&b,&c,&n); 34 int mx = max(a,max(b,c)); 35 int d = (mx-a)+(mx-b)+(mx-c); 36 if(d > n) pf("NO\n"); 37 else if((n-d)%3) pf("NO\n"); 38 else pf("YES\n"); 39 } 40 return 0; 41 }
Problem B. Collecting Packages
Solution
Observe that the only situation where there is a solution is you can rearrange packages in a way that the x-cor is increasing and y-cor is increasing simultaneously
Printing the path would be an easy job to do
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 #define sf scanf 5 #define pf printf 6 #define fo(i,s,t) for(int i = s; i <= t; ++ i) 7 #define fd(i,s,t) for(int i = s; i >= t; -- i) 8 #define mp make_pair 9 #define fi first 10 #define se second 11 #define VI vector<int> 12 #define pii pair<int,int> 13 #define fp freopen 14 #ifdef MPS 15 #define D(x...) printf(x) 16 #else 17 #define D(x...) 18 #endif 19 typedef long long ll; 20 typedef double db; 21 22 const int maxn = 1005; 23 24 int n; 25 pii a[maxn]; 26 27 int main() 28 { 29 #ifdef MPS 30 fp("1.in","r",stdin); 31 fp("1.out","w",stdout); 32 #endif 33 int t; 34 sf("%d",&t); 35 while(t--) 36 { 37 sf("%d",&n); 38 fo(i,1,n) sf("%d%d",&a[i].fi,&a[i].se); 39 sort(a+1,a+n+1); 40 int cx = 0, cy = 0; 41 string ans = ""; 42 fo(i,1,n) 43 { 44 while(cx < a[i].fi) 45 { 46 cx ++; 47 ans += "R"; 48 } 49 while(cy < a[i].se) 50 { 51 cy ++; 52 ans += "U"; 53 } 54 if(cx != a[i].fi || cy != a[i].se) 55 { 56 pf("NO\n"); 57 goto gg; 58 } 59 } 60 pf("YES\n"); 61 cout << ans << endl; 62 gg:; 63 } 64 return 0; 65 }
Codeforces Round 615 div3 Solution
原文:https://www.cnblogs.com/psmao/p/12238620.html