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

n<=2e5,t<=1e18,a[i]<=1e9

思路:显然购买是有周期的,每次周期变化都会少至少一个人,所以至多进行n次周期的变化

 #include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define N 200010
#define M 200
#define MOD 998244353
#define eps 1e-8
#define pi acos(-1)
#define oo 1000000000 ll a[N]; int main()
{
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
int n;
ll t;
scanf("%d%lld",&n,&t);
ll mn=oo;
for(int i=;i<=n;i++)
{
scanf("%lld",&a[i]);
mn=min(mn,a[i]);
} ll ans=;
while(t>=mn)
{
ll s=;
ll k=;
for(int i=;i<=n;i++)
if(t>=a[i])
{
t-=a[i];
s++;
k+=a[i];
}
ans+=s+t/k*s;
t%=k;
}
printf("%lld\n",ans);
return ;
}

【CF1073D】Berland Fair(模拟)的更多相关文章

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

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

  2. cf1073d Berland Fair

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

  3. CF1073D Berland Fair 二分+线段树

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

  4. 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 ...

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

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

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

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

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

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

  8. CodeForces - 1073D Berland Fair

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

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

    http://codeforces.com/problemset/problem/1073/D 题目大意:有n个物品(n<2e5)围成一个圈,你有t(t<1e18)元,每次经过物品i,如果 ...

随机推荐

  1. ospf多区域实例配置

    需求:是pc1,pc2,pc3直接可以相互通信,ip分别pc1:192.168.1.2 pc2:192.168.3.2 pc3:192.168.5.2 LSW1配置: 首先划分vlan,vlan中配置 ...

  2. Python读取内容UnicodeDecodeError错误

    1.错误现象 环境:Python3.7 描述: 用open方法获取文件句柄: 用read/readlines方法一次读取文件所有内容: 尝试了编码GB2312/GBK/GB18030/UTF-8,发现 ...

  3. Fakeapp 入门教程(3):参数篇

    参数可以让软件自由度更高.Fakeapp的参数并不算多,但是也非常使用.本文就讲解下几个重要的参数.参数设置界面可以通过点击SETTINGS打开. 参数修改无需点击保存,一旦修改直接生效. Proce ...

  4. centos7.3网络配置

    一.关闭NetworkManager 默认状态下最小化安装使用NetworkManager这个服务来控制联网的,但是这个配置在配置生产环境服务器时一般不会使用,而是使用系统自带的network服务,更 ...

  5. python代码notepad++不变色问题。

    原来是文档后缀名是.txt造成的,应该改成.py,疏忽了...

  6. Flow Problem HDU - 3549

    Flow Problem HDU - 3549 Network flow is a well-known difficult problem for ACMers. Given a graph, yo ...

  7. [Poj3133]Manhattan Wiring (插头DP)

    Description 题目大意:给你个N x M(1≤N, M≤9)的矩阵,0表示空地,1表示墙壁,2和3表示两对关键点.现在要求在两对关键点之间建立两条路径,其中两条路径不可相交或者自交(就是重复 ...

  8. Asp.net Mvc Action重定向总结

    摘自博客园 程晓晖 [HttpPost]        public ActionResult StudentList( string StudName, string studName, DateT ...

  9. day14 前端基础 HTML

    从今天开始,学习前端基础. 前端,就是HTML CSS JS 等 对于我们这种初学者,并不知道这些专业术语都是什么,给大家举一个形象的例子: HTML  就是一个人,赤裸裸的人 CSS    就是衣服 ...

  10. Cygwin访问盘符、使用别名、彩色显示、使用adb命令

    Cygwin是一个在Windows平台上运行的类UNIX模拟环境.安装过程我就不重复造轮子了,百度一下即可.其中安装的时候需要装哪些包,要看你用到哪些.比如我就是只用adb shell,所以全部默认安 ...