Greedy Arkady(思维)

k people want to split n

 candies between them. Each candy should be given to exactly one of them or be thrown away.

The people are numbered from 1

 to k, and Arkady is the first of them. To split the candies, Arkady will choose an integer x and then give the first x candies to himself, the next x candies to the second person, the next x candies to the third person and so on in a cycle. The leftover (the remainder that is not divisible by x

) will be thrown away.

Arkady can't choose x

 greater than M as it is considered greedy. Also, he can't choose such a small x that some person will receive candies more than D

 times, as it is considered a slow splitting.

Please find what is the maximum number of candies Arkady can receive by choosing some valid x

.

Input

The only line contains four integers n

kM and D (2n10182kn1Mn1Dmin(n,1000)MDkn

) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can receive candies.

Output

Print a single integer — the maximum possible number of candies Arkady can give to himself.

Note that it is always possible to choose some valid x

.

Examples
input
Copy
20 4 5 2
output
Copy
8
input
Copy
30 9 4 1
output
Copy
4
Note

In the first example Arkady should choose x=4

. He will give 4 candies to himself, 4 candies to the second person, 4 candies to the third person, then 4 candies to the fourth person and then again 4 candies to himself. No person is given candies more than 2 times, and Arkady receives 8

 candies in total.

Note that if Arkady chooses x=5

, he will receive only 5 candies, and if he chooses x=3, he will receive only 3+3=6 candies as well as the second person, the third and the fourth persons will receive 3 candies, and 2 candies will be thrown away. He can't choose x=1nor x=2 because in these cases he will receive candies more than 2

 times.

In the second example Arkady has to choose x=4

, because any smaller value leads to him receiving candies more than 1

 time

.

题意:k个人分n个糖果,第一个人先拿x个,然后每个人轮流拿x个,直至不到x个糖果(可以循环轮流)。

    问第一个人可分的的最多的糖果的个数。

一开始想的用二分,但是精度不好控制,条件不好写。后纯思维,采取暴力。第一个人要想分最多,其他人分

i-1次,第一个人就分i次,才能够保证糖数最多。

代码:

#include<stdio.h>
#include<string.h>
#define ll long long int
int main()
{
   ll n,k,m,d,i,x,countt;

   scanf("%lld %lld %lld %lld",&n,&k,&m,&d);

   countt=0;

   for(i=1;i<=d;i++){

      x=n/(k*(i-1)+1);  //其他人都是i-1次,只有第一个是i次,所以总共的是k*(i-1)+1次;

      if(x==0)
        break;

      if(x>m)
       x=m;

      countt=countt>i*x?countt:i*x;

   }

   printf("%lld\n",countt);

   return 0;
}

### Epsilon-Greedy Algorithm Implementation and Use Cases The epsilon-greedy algorithm is a strategy commonly used in reinforcement learning to balance exploration and exploitation. In this context, exploration refers to trying out new actions to discover potentially better outcomes, while exploitation involves selecting the action that has historically provided the best reward. #### Algorithm Implementation The epsilon-greedy policy selects a random action with probability ε (epsilon) and the greedy action (the one with the highest estimated value) with probability 1 - ε. This ensures that the agent does not always exploit known information but also explores other options to avoid getting stuck in suboptimal strategies[^2]. Below is an implementation of the epsilon-greedy algorithm in Python: ```python import numpy as np def epsilon_greedy_policy(Q, state, epsilon): if np.random.rand() < epsilon: # Exploration: Select a random action return np.random.choice(len(Q[state])) else: # Exploitation: Select the action with the highest value return np.argmax(Q[state]) ``` In this code snippet, `Q` represents the action-value function estimate for each state-action pair, `state` is the current state, and `epsilon` determines the likelihood of choosing a random action over the optimal one. #### Use Cases Epsilon-greedy algorithms are widely applied in various domains where decision-making under uncertainty is required. Some prominent use cases include: 1. **Reinforcement Learning**: The algorithm is fundamental in training agents to solve Markov Decision Processes (MDPs). For instance, it can be employed in games like chess or Go, where the agent must decide between exploring new moves or exploiting known winning strategies[^1]. 2. **Multi-Armed Bandit Problems**: These problems involve maximizing rewards by selecting among multiple options (or "arms") with unknown payoff distributions. Epsilon-greedy policies help determine which arm to pull next by balancing exploration and exploitation. 3. **Recommendation Systems**: In online recommendation systems, such as those used by streaming platforms or e-commerce websites, epsilon-greedy algorithms can suggest items to users. By occasionally recommending less popular items, the system can discover new preferences while primarily offering top-rated suggestions[^3]. 4. **Autonomous Driving**: Self-driving cars use reinforcement learning techniques to navigate roads safely. An epsilon-greedy approach might allow the vehicle to experiment with different driving styles during testing phases before settling on optimal behaviors[^4]. 5. **Resource Allocation**: In cloud computing environments, epsilon-greedy methods can optimize server allocation by dynamically adjusting resources based on historical performance metrics while exploring alternative configurations[^3].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值