寝癖頭の解法

学習中の覚え書きを投稿、更新していきます。

AtCoder Problems in C++ #C - Sugar Water

AtCoder Beginner Contestの過去問から、その提出コードの解答例です。
AtCoderとは、コンテストを通じて、プログラミングやアルゴリズムを学習するサービスです。
atcoder.jp
プログラミングコンテストとは、「与えられた問題をいかに素早く、正確に」解くことができるかを競うものです。
競技プログラミング」を略して、「競プロ」などと呼ばれています。

#C - Sugar Water

atcoder.jp

僕が作成、提出したコードは、以下のとおりです。

/*
AtCoder Problems in C++
#C - Sugar Water
https://atcoder.jp/contests/abc074/tasks/arc083_a
提出コードの解答例
https://neguse-atama.hatenablog.com
*/
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
  ll a,b,c,d,e,f,one=-2,two=1;
  cin>>a>>b>>c>>d>>e>>f;
  for(ll i=0;i*100*a<=f;i++){
    for(ll j=0;j*100<=f-i*100*a;j++){
      ll w=i*100*a+j*100*b;
      for(ll x=0;x*c<=f-w;x++){
        for(ll y=0;y*d<=f-w-x*c;y++){
          ll s=x*c+y*d;
          if(s>w/100*e || w+s>f){
            continue;
          }
          if(w+s!=0 && (s*1.0/(w+s)>two*1.0/(one+two))){
            one=w;
            two=s;
          }
        }
      }
    }
  }
  cout<<one+two<<" "<<two<<endl;
  return 0;
}

AtCoder Beginner Contestは、オンラインジャッジによるプログラミングコンテストです。
日本語と英語に対応していて、週末ごとに実施されているみたいです。
https://practice.contest.atcoder.jp/tutorial
アカウントを登録すれば、誰でも参加できます。