B. Power Sequence

添加链接描述
思路: 这道题关键是要读懂题目。我们知道一个整数序列,同样题目中说明我们可以免费排序,那么根据等比数列的特征,我们肯定会选择从小到大排序。所以我们关键是要确定公比 c ,那么我们可以通过暴力枚举来解决,取成本消耗最少的值。 要注意优化时间,由于我们是不断增加公比去求成本消耗最小值,倘若我们再增加公比的值求得的成本消耗比上一次的还要高,那么这个时候我们就必须要退出了,因为之后再增加还是一样的情况。
这个题很好,观察到2的62次方已经快到1e18了,而a的范围是1e9以内,所以循环的次数不会太多,递增递减的边界循环几次就找到了,所以直接暴力跑,如果发现开始递增直接退出。
而且这题代码细节也很重要,把判断if(sum>ans)放在内层循环,否则会ll溢出

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+5;
const ll INF=1e15;
ll a[maxn];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int c=1;
    ll ans=INF;
    while(1)
    {
    ll sum=0,te=1;
    sum=a[0]-1;
    for(int i=1;i<n;i++)
    {
        te*=c;
        sum+=abs(a[i]-te);
        if(sum>ans)
            break;
    }
    if(sum<=ans)
    {
        ans=sum;
        c++;
    }
    else break;
    }
    cout<<ans<<endl;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
翻译Agent 𝑐 𝑖 . In this paper, we regard each charging station 𝑐 𝑖 ∈ 𝐶 as an individual agent. Each agent will make timely recommendation decisions for a sequence of charging requests 𝑄 that keep coming throughout a day with multiple long-term optimization goals. Observation 𝑜 𝑖 𝑡 . Given a charging request 𝑞𝑡 , we define the observation 𝑜 𝑖 𝑡 of agent 𝑐 𝑖 as a combination of the index of 𝑐 𝑖 , the real-world time 𝑇𝑡 , the number of current avail able charging spots of 𝑐 𝑖 (supply), the number of charging requests around 𝑐 𝑖 in the near future (future demand), the charging power of 𝑐 𝑖 , the estimated time of arrival (ETA) from location 𝑙𝑡 to 𝑐 𝑖 , and the CP of 𝑐 𝑖 at the next ETA. We further define 𝑠𝑡 = {𝑜 1 𝑡 , 𝑜2 𝑡 , . . . , 𝑜𝑁 𝑡 } as the state of all agents at step 𝑡. Action 𝑎 𝑖 𝑡 . Given an observation 𝑜 𝑖 𝑡 , an intuitional design for the action of agent𝑐 𝑖 is a binary decision, i.e., recommending 𝑞𝑡 to itself for charging or not. However, because one 𝑞𝑡 can only choose one station for charging, multiple agents’ actions may be tied together and are difficult to coordinate. Inspired by the bidding mechanism, we design each agent 𝑐 𝑖 offers a scalar value to "bid" for 𝑞𝑡 as its action 𝑎 𝑖 𝑡 . By defining 𝑢𝑡 = {𝑎 1 𝑡 , 𝑎2 𝑡 , . . . , 𝑎𝑁 𝑡 } as the joint action, 𝑞𝑡 will be recommended to the agent with the highest "bid" value, i.e., 𝑟𝑐𝑡 = 𝑐 𝑖 , where 𝑖 = arg max(𝑢𝑡)
07-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值