~~~题面~~~

题解:

  可以发现,每走完一圈付的钱和买的数量是有周期性的,即如果没有因为缺钱而买不起某家店的东西,那么这一圈的所以决策将会和上一圈相同,这个应该是很好理解的,想想就好了。

  因为钱数固定时,决策固定,所以每次都O(n)扫一遍看当前情况下走一圈会花多少钱。

  然后直接一直取这么多钱,直到钱不够为止,再进行下一次计算走一圈的钱数,显然用类似取模的东西可以解决。

  为什么这样的复杂度是正确的呢?

  一开始觉得是$n^2$的,还想了半天如何优化,但其实因为每次钱数都取了模,而一个数每次取模至少会减少一半,所以其实只会进行log次,所以复杂度是$nlogn$的

 #include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 230000
#define LL long long int n, top;
LL ans, t, minn = 10000000000000000LL;
LL s[AC]; inline LL read()
{
LL x = ;char c = getchar();
while(c > '' || c < '') c = getchar();
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x;
} inline void upmin(LL &a, LL b){
if(b < a) a = b;
} void pre()
{
n = read(), t = read();
for(R i = ; i <= n; i ++)
s[i] = read(), upmin(minn, s[i]);
} void work()
{
while(t >= minn)
{
LL tmp = t, rnt = ;
for(R i = ; i <= n; i ++)
if(tmp >= s[i]) tmp -= s[i], ++ rnt;
tmp = t - tmp;//获得实际消耗的钱
LL k = t / tmp;
ans += k * rnt;
t -= k * tmp;
}
cout << ans << endl;
} int main()
{
// freopen("in.in", "r", stdin);
pre();
work();
// fclose(stdin);
return ;
}

cf1073d Berland Fair的更多相关文章

  1. cf1073D Berland Fair (二分答案+树状数组)

    用一个树状数组维护前缀和,每次我二分地找一个位置,使得我能一路买过去 但这个买不了 那以后肯定也都买不了了,就把它改成0,再从头二分地找下一个位置,直到这一圈我可以跑下来 然后就看跑这一圈要花多少钱. ...

  2. CF1073D Berland Fair 二分+线段树

    考场上切的,挺简单的~ Code: #include <cstdio> #include <algorithm> #define N 200005 #define inf 10 ...

  3. CodeForce edu round 53 Div 2. D:Berland Fair

    D. Berland Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  4. codeforces1073d Berland Fair 思维(暴力删除)

    题目传送门 题目大意:一圈人围起来卖糖果,标号从1-n,每个位置的糖果都有自己的价格,一个人拿着钱从q开始走,能买则买,不能买则走到下一家,问最多能买多少件物品. 思路:此题的关键是不能买则走到下一家 ...

  5. 【数据结构】【CF1073D】 Berland Fair

    Description 给定 \(n\) 个商店,他们围成一个圆圈,按照顺时针从 \(1\) 到 \(n\) 编号.你有 \(T\) 元钱,从 \(1\) 号点开始按照顺时针方向走,每到一个商店,只要 ...

  6. 【CF1073D】Berland Fair(模拟)

    题意:初始有t元,每次从1开始买,从1到n依次有n个人,每个人的东西价格为a[i],该人依次能买就买,到n之后再回到1从头开始,问最后能买到的东西数量 n<=2e5,t<=1e18,a[i ...

  7. CodeForces - 1073D Berland Fair

    XXI Berland Annual Fair is coming really soon! Traditionally fair consists of nnbooths, arranged in ...

  8. Codeforces 1073D:Berland Fair(模拟)

    time limit per test: 2 secondsmemory limit per test: 256 megabytesinput: standard inputoutput: stand ...

  9. Educational Codeforces Round 53 (Rated for Div. 2) D. Berland Fair

    题意:一个人  有T块钱 有一圈商店 分别出售 不同价格的东西  每次经过商店只能买一个  并且如果钱够就必须买 这个人一定是从1号店开始的!(比赛的时候读错了题,以为随意起点...)问可以买多少个 ...

随机推荐

  1. logback.xml日志文件配置

    放在resources目录下面就可以自动读取<?xml version="1.0" encoding="UTF-8"?> <configura ...

  2. SAX-xml解析

    <?xml version="1.0" encoding="UTF-8"?><bookstore> <book id=" ...

  3. Unbuntu安装RVM

    apt-get install curl #安装rvm curl -L https://get.rvm.io | bash #执行启动 source /home/mafei/.rvm/scripts/ ...

  4. 分享一个 UiPath Studio 相关的公众号

    RPA 和 UiPath 方面的资料比较少,因此我们自己创建了一个公众号,专门用于传播 UiPath 相关的知识. 会定期发布 UiPath 学习相关的信息.是目前难得的 UiPath 中文资源. 公 ...

  5. redmine本地安装部署

    1.railsinstaller-3.2.0.exe 下载地址 http://railsinstaller.org/en 安装railsinstaller  一直点next就可以了,安装完成之后C盘会 ...

  6. wpf基础使用_修改窗体图标

    废话不多说,直接开始修改图标步骤: 当然直接使用绝对路径添加图标也是可以的,这种方式不可取,一旦图标移动位置或被删除,就会导致找不到图标文件报错,这里我们介绍的是另一个方式,使用资源文件的方式添加 1 ...

  7. eclipse格式化

    一.eclipse格式化的必要性 1.便于阅读 2.便于协作 二.eclipse格式化快捷键 ctrl shift + F

  8. JAVA基础学习之路(二)方法定义,重载,递归

    一,方法的定义: package test; public class test1 { public static void main(String args[]) { int result = ad ...

  9. EasyUI学习心得

    因为要修改十几年前的一个项目界面,打9月份开始学习EasyUI,很多事情都要自己试过才知道,小问题会浪费很多时间.所以,就在此记录一下,随时更新. 一.引号 EasyUI的自定义关键字的识别,API文 ...

  10. beego 笔记

    1.开发文档 https://beego.me/docs/intro/ 2.bee run projectname demo controller package autoscaler import ...