loading...

Daily Coding Challenge #94

wingkwong profile image Wing-Kam ・2 min read

About

This is a series of Daily Coding Challenge. Each day I show a few solutions written in C++. The questions are from coding practice/contest sites such as HackerRank, LeetCode, Codeforces, Atcoder and etc.


/*
Codeforces Round #664 (Div. 2) - Boboniu Likes to Color Balls
https://codeforces.com/contest/1395/problem/A
*/

#include <bits/stdc++.h>
using namespace std; 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long ll; 
const ll MOD = 1000000007;

int main()  
{ 
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
    #endif
    FAST_INP;
    ll t,r,g,h,w,ok;
    cin >> t;
    while(t--){
        ok=0;
        cin >> r >> g >> h >> w;
        // if there is more than 1 odd types of balls, then no solution 
        // because it has to be something like abcba or abba
        ok|=((r&1)+(g&1)+(h&1)+(w&1)<=1);
        // if three balls can be picked, pick it and add them to white balls and check again
        if(r&&g&&h) r--, g--, h--, w+=3;
        // same logic
        ok|=((r&1)+(g&1)+(h&1)+(w&1)<=1);
        cout << (ok?"Yes":"No") << endl;
    }
    return 0;
} 

/*
Codeforces Round #664 (Div. 2) - B. Boboniu Plays Chess
https://codeforces.com/contest/1395/problem/B
*/


#include <bits/stdc++.h>
using namespace std; 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long ll; 
const ll MOD = 1000000007;

ll solve(ll x, ll y, ll m, ll n){
    ll i; // store the last col
    if(y==1) for(i=1;i<=m;i++) cout << x << " " << i << endl;
    else if (y==m) for(i=m;i>=1;i--) cout << x << " " << i << endl;
    else {
        for(i=y;i<=m;i++) cout << x << " " << i << endl;
        for(i=y-1;i>=1;i--) cout << x << " " << i << endl;
    }
    return i==0?1:i;
}

int main()  
{ 
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
    #endif
    FAST_INP;
    ll n,m,x,y;
    cin >> n >> m >> x >> y;
    // UPD after contest: 
    // I think it can be just traverse from 1<=n and 1<m, skip if i=x and j=y
    // It should be more simple
    if(x==1) {
        for(int i=1;i<=n;i++){
            y = solve(i,y,m,n);
        }
    }else if(x==n){
        for(int i=n;i>=1;i--){
            y = solve(i,y,m,n);
        }
    }else{
        y = solve(x,y,m,n);
        for(int i=1;i<=x-1;i++){
            y = solve(i,y,m,n);
        }
        for(int i=x+1;i<=n;i++){
            y = solve(i,y,m,n);
        }
    }
    return 0;
} 


There are other programming solutions in the following repositories below. Star and watch for timely updates!

GitHub logo wingkwong / leetcode

πŸ† A Collection of my LeetCode Solutions with Explanations πŸ†

GitHub logo wingkwong / hackerrank

πŸ† A Collection of my HackerRank Solutions with Explanations πŸ†

GitHub logo wingkwong / codeforces

πŸ† A Collection of my Codeforces Solutions with Explanations πŸ†

GitHub logo wingkwong / atcoder

πŸ† A Collection of my AtCoder Solutions with Explanations πŸ†

GitHub logo wingkwong / cses

πŸ† A Collection of my CSES Solutions with Explanations πŸ†

GitHub logo wingkwong / timus

A Collection of my Timus Solutions

Discussion

pic
Editor guide