CodeForces - 1073D Berland Fair
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of nnbooths, arranged in a circle. The booths are numbered 11 through nn clockwise with nnbeing adjacent to 11. The ii-th booths sells some candies for the price of aiai burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most TT burles at the fair. However, he has some plan in mind for his path across the booths:
- at first, he visits booth number 11;
- if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately;
- then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
Input
The first line contains two integers nn and TT (1≤n≤2⋅1051≤n≤2⋅105, 1≤T≤10181≤T≤1018) — the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the price of the single candy at booth number ii.
Output
Print a single integer — the total number of candies Polycarp will buy.
Examples
3 38
5 2 5
10
5 21
2 4 100 2 6
6
Note
Let's consider the first example. Here are Polycarp's moves until he runs out of money:
- Booth 11, buys candy for 55, T=33T=33;
- Booth 22, buys candy for 22, T=31T=31;
- Booth 33, buys candy for 55, T=26T=26;
- Booth 11, buys candy for 55, T=21T=21;
- Booth 22, buys candy for 22, T=19T=19;
- Booth 33, buys candy for 55, T=14T=14;
- Booth 11, buys candy for 55, T=9T=9;
- Booth 22, buys candy for 22, T=7T=7;
- Booth 33, buys candy for 55, T=2T=2;
- Booth 11, buys no candy, not enough money;
- Booth 22, buys candy for 22, T=0T=0.
No candy can be bought later. The total number of candies bought is 1010.
In the second example he has 11 burle left at the end of his path, no candy can be bought with this amount.
题目大意:
n种糖果围成一圈,每种糖果每个ai元。初始时你有t元,接着你从1开始疯狂地绕圈。一旦你发现有糖果能买,你就买一个。直到一个糖果都买不起。问最后你买了多少个糖果。
稍微带点技巧的模拟。
若一个周期的和小于剩余的t,就直接买几个周期,不必一个个模拟。
然后遇到买不起的则将他从周期中删除。
注意用long long
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<iostream>
#define lol long long
#define maxn 200000 using namespace std; lol a[maxn+]; int main()
{
lol n,t;
scanf("%lld%lld",&n,&t);
lol sum=;
for(int i=;i<=n;i++)
{
scanf("%lld",a+i);
sum+=a[i];
} lol ans=;
lol cur=n;
lol num=n;
while()
{
ans+=(t/sum)*num;
t=t%sum;
//printf("%lld\n",t);
for(int i=;;i++)
{
//printf("%lld %lld\n",a[(cur+i-1)%n+1],t);
if(a[(cur+i-)%n+]==-)
continue;
if(a[(cur+i-)%n+]>t)
{
sum-=a[(cur+i-)%n+];
num--;
a[(cur+i-)%n+]=-;
cur=(cur+i-)%n+;
break;
}
t-=a[(cur+i-)%n+];
ans++;
} if(num==)
break;
}
printf("%lld\n",ans); return ;
}
好久没有更新博客了。
曾经被炒上天的ACM,如今却有些人走茶凉的味道。
正确的事是要坚持的。
CodeForces - 1073D Berland Fair的更多相关文章
- codeforces 897A  Scarborough Fair  暴力签到
		codeforces 897A Scarborough Fair 题目链接: http://codeforces.com/problemset/problem/897/A 思路: 暴力大法好 代码: ... 
- 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 ... 
- codeforces1073d   Berland Fair    思维(暴力删除)
		题目传送门 题目大意:一圈人围起来卖糖果,标号从1-n,每个位置的糖果都有自己的价格,一个人拿着钱从q开始走,能买则买,不能买则走到下一家,问最多能买多少件物品. 思路:此题的关键是不能买则走到下一家 ... 
- [Codeforces 1005F]Berland and the Shortest Paths(最短路树+dfs)
		[Codeforces 1005F]Berland and the Shortest Paths(最短路树+dfs) 题面 题意:给你一个无向图,1为起点,求生成树让起点到其他个点的距离最小,距离最小 ... 
- Codeforces 1073D:Berland Fair(模拟)
		time limit per test: 2 secondsmemory limit per test: 256 megabytesinput: standard inputoutput: stand ... 
- 【Codeforces 1073D】Berland Fair
		[链接] 我是链接,点我呀:) [题意] 题意 [题解] 我们可以从左到右枚举一轮. 定义一个cost表示这一轮花费的钱数 如果cost+a[i]<=T那么就可以买它,并且买下它(模拟题目要求) ... 
- [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,如果 ... 
- Educational Codeforces Round 53 (Rated for Div. 2) D. Berland Fair
		题意:一个人 有T块钱 有一圈商店 分别出售 不同价格的东西 每次经过商店只能买一个 并且如果钱够就必须买 这个人一定是从1号店开始的!(比赛的时候读错了题,以为随意起点...)问可以买多少个 ... 
- CodeForces 567B  Berland National Library
		Description Berland National Library has recently been built in the capital of Berland. In addition, ... 
随机推荐
- react-router重定向
			① ②通过this.props重定向 
- golang学习--go中'继承'和多态
			golang中没有继承的概念,这个struct属性上的继承,但是可以用匿名字段来模拟这个过程,方法上面的继承要使用接口.多态可以通过接口实现.可以看一下代码. package main import ... 
- 小白学 Python 爬虫(4):前置准备(三)Docker基础入门
			人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ... 
- 读写分离很难吗?springboot结合aop简单就实现了
			目录 前言 环境部署 开始项目 注意 參考: 前言 入职新公司到现在也有一个月了,完成了手头的工作,前几天终于有时间研究下公司旧项目的代码.在研究代码的过程中,发现项目里用到了Spring Aop来实 ... 
- 京东物流出问题了?褥了30块羊毛 & 浅析系统架构
			本人亲身经历,但后续的流程分析都是个人猜测的,毕竟没有实际做过这块的业务. 订单物流阻塞经过 火热的双11刚刚退去,截止今日,我在京东购买的矿泉水终于到货啦,下单两箱还只收到了一箱 :( ,从下单到收 ... 
- Android 获取 SHA1值3步完成
			未经允许,禁止 
- 线程中synchronized关键字和lock接口的异同
			一.synchronized关键字 1.可以用来修饰代码块 synchronized (this) { // 同步的关键字 this 表示当前线程对象 if (num == 0) { break; } ... 
- oracle插入,更新,删除数据
			插入,更新,删除数据 oracle提供了功能丰富的数据库管理语句 包括有效的向数据库中插入数据的insert语句 更新数据的update语句 以及当数据不再使用时删除数据的delete语句 更改数据之 ... 
- 2019-10-30:渗透测试,基础学习,mssql堆叠内联注入,mongodb基础语法
			使用xp_cmdshell需要堆叠注入,http://192.168.190.148/less-1.asp?id=1';EXEC sp_configure 'show advanced options ... 
- pyenv virtualenv和virtualwrapper
			pyenv pyenv最大的优势是:可以在”全局”管理不同版本的Python, 可以随时配置当前的使用的Python版本,并对其他使用Python解释器的程序生效.当系统安装多个版本的Python,使 ... 
