第二题是巧克力吗? import java.util.Scanner; /** public class Main4 {     public static void main(String[] args) {         Scanner in = new Scanner(System.in);         int N = in.nextInt();         int M = in.nextInt();         int lo = 1, hi = M;         while (lo + 1 < hi) {             int mid = lo + (hi - lo) / 2;             if (isScatisfy(mid, N, M)) {                 lo = mid;             } else {                 hi = mid - 1;             }         }         if (isScatisfy(lo+1, N, M)) {             System.out.println(lo + 1);         } else {             System.out.println(lo);         }     }     public static boolean isScatisfy(int v, int N, int M) {         int ans = v;         for (int i = 1; i < N; i++) {             if (v == 1) {                 ans += N - i;                 break;             } else {                 ans += (v + 1) / 2;                 v = (v + 1) / 2;             }         }         return ans <= M;     } }
点赞 7

相关推荐

点赞 评论 收藏
分享
10-17 12:16
同济大学 Java
7182oat:快快放弃了然后发给我,然后让我也泡他七天最后再拒掉,狠狠羞辱他一把😋
点赞 评论 收藏
分享
牛客网
牛客企业服务