Gym 100187a-potion of Immortality

Source: Internet
Author: User

Test instructions: There are n bottles, there is a poison, and then every time to take the rabbit to try to eat K bottle and can only be K bottle, if the rabbit died know that the bottle is poison, now ask you at least a rabbit to try to eat a few times.

Analysis: This problem card for a long time, in fact very simple. First consider sure to eat n/k times, then the rest if only one bottle or not, then the answer is n/k, if there are more than two bottles, you only need to eat again on the line. Because rabbits only need to eat m-1 bottles in the remaining m bottles, and then in the previous n-m bottle to eat (k-m+1) bottle, you can know that the remaining is poison.

1#include <cstdio>2#include <cmath>3#include <cstring>4#include <ctime>5#include <iostream>6#include <algorithm>7#include <Set>8#include <vector>9#include <sstream>Ten#include <queue> One#include <typeinfo> A#include <fstream> -#include <map> -#include <stack> the using namespacestd; -typedefLong Longll; - intMain () - { + ll N,k; -scanf"%i64d%i64d",&n,&k); +ll ans=n/k,r=n%K; A     if(n==k&&n!=1) printf ("-1\n"); at     Else{ -         if(k==1) printf ("%d\n", N-1); -         Else{ -             if(r==0|| r==1) printf ("%i64d\n", ans); -             Elseprintf"%i64d\n", ans+1); -         } in     } -     return 0; to}

Gym 100187a-potion of Immortality

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.