0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AtCoder Beginner Contest 198 備忘録

Last updated at Posted at 2021-04-14

ABC198の備忘録
https://atcoder.jp/contests/abc198

A:AC
B:寝落ち⇒後日見直し
C:寝落ち⇒後日見直し
D:未着手
E:未着手
F:未着手

A - Div
N個の互いに区別できないお菓子を、A君とB君で分け合います。
両者とも1個以上の整数個のお菓子を得るような分け方は何通りありますか?

要はNまでの数列で、どこでスプリットするかという話。
=数値の間はいくつかるかってことだけ。
簡単。

# include <bits/stdc++.h>
# include <math.h>
using namespace std;
 
int main() {
  int n;
  cin>>n;
  cout<<n-1<<endl;
  }

B - Palindrome with leading zeros
1E9までのある数字に対して、頭に0をつけて回文にできるかって問題。
例えば 101 はすでに回文なので”Yes”、1210は頭に0をつけると01210で回文になるので"Yes"、123はどう0をつけても回文にならんので、"No"という感じ。
1桁のときは絶対"Yes"。
2桁のときは、ぞろ目(22等)か10の倍数(30等)の時に"Yes"
3桁以降は、1桁目と末桁を比較し、一致する場合は2桁目と末-1桁目を比較、を繰り返す。
最後まで一致がしたらflg on, 一致しない場合はbreakして頭に0を追加し再探索。
最大9桁なので、ちょっと探索範囲広いけどめんどいので無条件で9個ゼロとりあえず足して探索しとく。

# include <bits/stdc++.h>
# include <math.h>
using namespace std;
 
int main() {
  string N;
  cin>>N;
  int count=N.size();
  int flg=0;

if(count==1){ //1桁のとき
 cout<<"Yes"<<endl;
}
else if(count==2){ //2桁のとき
  if(N.at(0)==N.at(1)||N.at(1)=='0'){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}
else{ //3桁以上のとき
  for(int i=0;i<10;i++){
      count=N.size();
    for(int j=0;j<=(count/2);j++){ //両側から探索するので、文字数/2
      if(N.at(j)==N.at(count-1-j)){ //文字の位置は0からなので、1ずらす
            if(j==(count-1)/2) //最後の探索まで来たら、YESフラグ立てる
            {
            flg=1;
            }
       }
      else{
        break; //それ以外は飛ばす
      }
    }
    N=N.insert(0, "0"); //0を頭に足す
  }
  if(flg==1){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}
}

C - Compass Walking
原点スタートでR歩幅で歩くとき、(X,Y)までは最短何歩で行けるか?
(X,Y)までの距離は単純にsqrt(X^2+Y^2)でOK。
最短歩数は距離÷歩幅になるのは直観的に明らか。
距離/歩幅で割り切れる時は商がそのまま答え、割り切れない時は+1すればいい

と思ったら一発目WA。
よくよく考えると、歩幅>距離になるケースを考慮しないとあかん。
一度離れてから、もう一歩いく感じになるので、この時は答えは2になる。
この条件をいれればおk

# include <bits/stdc++.h>
# include <math.h>
using namespace std;
 
int main() {
  long double R,X,Y;
  cin>>R>>X>>Y;
  int step=0;
  long double dis=0;
  dis=sqrt(X*X+Y*Y);
  step=dis/R;
if(dis<R){
  cout<<"2"<<endl;
}
else{
    if(dis/R>step){
    cout<<step+1<<endl;
  }
    else{
    cout<<step<<endl;
  }
}

}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?