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?

yukicoder No.63 ポッキーゲーム 解説

Posted at

問題文

解説

まず、一回齧ると$2 K$減る。$L < 2K \times 操作回数$になると操作ができなくなる。そこから、操作できる回数は$\lfloor (L-1) \div 2K \rfloor$となる。よって答えは$\lfloor (L-1) \div 2K \rfloor *K$。これを出力すればよし。

C++での解答例

#include <bits/stdc++.h>
using namespace std;
using ll=long long;

ll downfloor(ll x,ll m){
  // x/mを正確に求める関数
  ll r=(x%m+m)%m;
  return (x-r)/m;
}

int main(){
  int L,K;cin>>L>>K;
  cout<<downfloor(L-1,2*K)*K<<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?