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, ...
随机推荐
- PHP中Redis扩展无法加载问题
问题: 在重启php-fpm的过程中,发生了如下的错误,redis.so无法载入 1 2 3 4 [root@brand009 modules]# /usr/sbin/php-fpm /usr/sbi ...
- beta week 2/2 Scrum立会报告+燃尽图 01
此作业要求参见https://edu.cnblogs.com/campus/nenu/2019fall/homework/9954 一.小组情况 队名:扛把子 组长:孙晓宇 组员:宋晓丽 梁梦瑶 韩昊 ...
- vue 优化小技巧 之 require.context()
1.require.context() 回忆一下 当我们引入组件时 第一步 创建一个子组件 第二步 import ... form ... 第三步 components:{..} 第四步 页面使用 & ...
- 协议分层(因特网5层模型)及7层OSI参考模型
目录 因特网5层模型及7层OSI参考模型 分层的体系结构: 应用层(软件) 运输层(软件) 网络层(硬件软件混合) 链路层(硬件) 物理层(硬件) OSI模型 表示层 会话层 封装 因特网5层模型及7 ...
- 2019-9-18:渗透测试,基础学习,ubuntu搭建LNMP,phpmyadmin
1,安装nginx:sudo apt-get install nginx 2,安装完成,输入,service nginx start开启服务,输入:netstat -ntulp |grep 80,确定 ...
- 实现自定义的参数解析器——HandlerMethodArgumentResolver
1.为什么需要自己实现参数解析器 我们都知道在有注解的接口方法中加上@RequestBody等注解,springMVC会自动的将消息体等地方的里面参数解析映射到请求的方法参数中. 如果我们想要的信息不 ...
- C语言之修改常量
前言:指针!菜鸟的终点,高手的起点.漫谈一些进阶之路上的趣事:记录一些语言本身的特性以及思想,没有STL,也没有API! 0x01: 程序内存中的存储划分 对于程序在内存中是如何分布的,网上有多个解释 ...
- String对象常量池
对象池的主要目的是实现数据的共享处理, 在java之中对象池可以分为两种: 1.静态常量池 :指*.class加载时会自动将此程序之中保存的 字符串.普通的常量.类和方法的信息等全部经行分配 2.运行 ...
- CentOS6下安装zabbix3.4
安装环境 系统 Centos6.7,最小化安装 CPU 2核 内存 2G 硬盘 200G IP 192.168.100.168/24 主机名 zabbix Zabbix版本 3.4 数据库 mysql ...
- 漫谈LiteOS之开发板-GPIO(基于GD32450i-EVAL)
[摘要] 本文主要从GPIO的定义.工作模式.特色.工作场合.以及GD32450i-EVAL开发板的引脚.对应的寄存器以及GPIO的流水灯示例对GPIO加以介绍,希望对你有所帮助. 1定义 GPIO( ...