loading...

Daily Coding Challenge #84

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.


/*
AtCoder Beginner Contest 174 - A - Air Conditioner
https://atcoder.jp/contests/abc174/tasks/abc174_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()  
{ 
    FAST_INP;
    int x;
    cin >> x;
    if(x>=30) cout << "Yes\n";
    else cout << "No\n";
    return 0;
} 

/*
AtCoder Beginner Contest 174 - B - Distance
https://atcoder.jp/contests/abc174/tasks/abc174_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;

int main()  
{ 
    FAST_INP;
    ll n,d,x,y;
    cin >> n >> d;
    int ans=0;
    for (int i=0; i<n; i++) {
        cin >> x >> y;
        if(x*x+y*y<=d*d) ans++;
    }
    cout << ans << endl;
    return 0;
} 

/*
AtCoder Beginner Contest 174 - C - Repsept
https://atcoder.jp/contests/abc174/tasks/abc174_c
*/

#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()  
{ 
    FAST_INP;
    // use modular arithmetic to find the remainders 
    // and check if the val is 0, which means it can divided by k
    int k;
    cin >> k;
    int val=7%k;
    for(int i=1;i<1e7;i++){
        if(val==0){
            cout << i << endl;
            return 0;
        }
        val=(val*10+7)%k;
    }
    cout << "-1" << endl;
    return 0;
} 

/*
AtCoder Beginner Contest 174 - D - Alter Altar
https://atcoder.jp/contests/abc174/tasks/abc174_d
*/

#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()  
{ 
    FAST_INP;
    // change it to sequence like
    // RRRRR..RWWWW..W
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r=0, w=0, swap=0;
    for (int i=0;i<n;i++) {
        if(s[i]=='W') w++;
        else r++;
    }
    int ans = min(w,r);
    for (int i=0;i<r;i++) {
        if(s[i]=='W') swap++;
    }
    ans=min(ans,swap);
    cout << ans << endl;
    return 0;
} 

/*
AtCoder Beginner Contest 174 - E - Logs
https://atcoder.jp/contests/abc174/tasks/abc174_e
*/

#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()  
{ 
    FAST_INP;
    // binary search 
    int n,k;
    cin >> n >> k;
    vector<ll> a(n);
    ll l=1,r=0;
    for(int i=0;i<n;i++) {
        cin >> a[i];
        r=max(r,a[i]);
    }
    while(l!=r){
        int m = l+(r-l)/2;
        ll kk=0;
        for(int i=0;i<n;i++){
            kk+=(a[i]-1)/m;
        }
        if(kk<=k) r=m;
        else l=m+1;
    }
    cout << l << endl;
    return 0;
} 

The source code is available in corresponding repo 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 🏆

Posted on by:

wingkwong profile

Wing-Kam

@wingkwong

Consultant by day. Developer by night. AWS certified. Exploring #CloudNative currently.

Discussion

markdown guide