upc组队赛7 Slimming Plan
Slimming Plan
题目描述
Chokudai loves eating so much. However, his doctor Akensho told him that he was overweight, so he finally decided to lose his weight.
Chokudai made a slimming plan of a D-day cycle. It is represented by D integers w0,...,wD−1. His weight is S on the 0-th day of the plan and he aims to reduce it to T (S>T). If his weight on the i-th day of the plan is x, it will be x+wi%D on the (i+1)-th day. Note that i%D is the remainder obtained by dividing i by D. If his weight successfully gets less than or equal to T, he will stop slimming immediately.
If his slimming plan takes too many days or even does not end forever, he should reconsider it.
Determine whether it ends or not, and report how many days it takes if it ends.
输入
The input consists of a single test case formatted as follows.
S T D
w0...wD−1
The first line consists of three integers S, T, D (1≤S,T,D≤100,000,S>T). The second line consists of D integers w0,...,wD−1(−100,000≤wi≤100,000 for each i).
输出
If Chokudai's slimming plan ends on the d-th day, print d in one line. If it never ends, print −1.
样例输入
65 60 3
-2 3 -4
样例输出
4
题意+题解
一个人从体重s要减肥到t,有d周期的减肥计划,计算需要多少天能减肥成功。如果永远不可能成功输出-1
先在第一轮周期中遍历每一天,如果s<=t 就说明成功了,直接输出
如果没有,一轮后计算出周期和 ,如果是正数那么不可能减肥成功
然后得考虑减的最多的那天情况,如果在最后一个周期中减肥成功了,但是可能在最小值那里就成功了,所以我们在最后一个周期中也得逐个计算
代码
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rep(i,a,n) for(int i=a;i<n;++i)
#define readc(x) scanf("%c",&x)
#define read(x) scanf("%d",&x)
#define sca(x) scanf("%d",&x)
#define sca2(x,y) scanf("%d%d",&x,&y)
#define sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define print(x) printf("%d\n",x)
#define mst(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&-x
#define lson(x) x<<1
#define rson(x) x<<1|1
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> P;
const int INF =0x3f3f3f3f;
const ll inf = 99999999999;
const int mod = 1e9+7;
const int MAXN = 105;
const int maxn =1000005;
using namespace std;
int t,d;
ll s;
int a[maxn];
int main(){
scanf("%lld",&s);
sca2(t,d);
ll mi = inf; // 最小值
ll sum = 0; // 周期的和
for(int i = 0; i < d; i++){
sca(a[i]);
sum += a[i];
if(s + sum <= t){
printf("%d\n", i + 1);
return 0;
}
mi = min(mi,sum);
}
if(sum >= 0){
printf("-1\n");
return 0;
}
ll cnt = 1;
while(cnt * sum + mi + s > t){
cnt++;
}
ll day = cnt * d;
s += cnt * sum;
for(int i = 0; i < d; i++){
if(s + a[i] > t){
day++;
s += a[i];
}
else{
day++;
break;
}
}
printf("%lld\n",day);
return 0;
}
upc组队赛7 Slimming Plan的更多相关文章
- Slimming Plan
问题 B: Slimming Plan 时间限制: 1 Sec 内存限制: 128 MB 题目描述 Chokudai loves eating so much. However, his docto ...
- upc组队赛5 Ingenious Lottery Tickets【排序】
Ingenious Lottery Tickets 题目描述 Your friend Superstitious Stanley is always getting himself into trou ...
- upc组队赛3 Chaarshanbegaan at Cafebazaar
Chaarshanbegaan at Cafebazaar 题目链接 http://icpc.upc.edu.cn/problem.php?cid=1618&pid=1 题目描述 Chaars ...
- upc组队赛1 过分的谜题【找规律】
过分的谜题 题目描述 2060年是云南中医学院的百年校庆,于是学生会的同学们搞了一个连续猜谜活动:共有10个谜题,现在告诉所有人第一个谜题,每个谜题的答案就是下一个谜题的线索....成功破解最后一个谜 ...
- upc组队赛1 不存在的泳池【GCD】
不存在的泳池 题目描述 小w是云南中医学院的同学,有一天他看到了学校的百度百科介绍: 截止到2014年5月,云南中医学院图书馆纸本藏书74.8457万册,纸质期刊388种,馆藏线装古籍图书1.8万册, ...
- upc组队赛1 黑暗意志【stl-map】
黑暗意志 题目描述 在数千年前潘达利亚从卡利姆多分离之时,迷雾笼罩着这块新形成的大陆,使它不被外来者发现.迷雾同样遮蔽着这片大陆古老邪恶的要塞--雷神的雷电王座.在雷神统治时期,他的要塞就是雷电之王力 ...
- upc组队赛1 闪闪发光 【优先队列】
闪闪发光 题目描述 一所位于云南昆明的中医药本科院校--云南中医学院. 因为报考某专业的人数骤减,正面临着停招的危机. 其中有九名少女想到一条妙计--成为偶像, 只要她们成为偶像,学校的名气便会增加, ...
- upc组队赛1 流连人间的苏苏
流连人间的苏苏 题目描述 苏苏在做红尘仙的任务时,发现坐落于风景秀丽.四季如春的昆明市的云南中医学院. 没过多久,苏苏就喜欢上了这个学校.以致于苏苏忘了回涂山的时间,现在她只剩下d天的时间待在云南中医 ...
- upc组队赛18 THE WORLD【时间模拟】
THE WORLD 题目链接 题目描述 The World can indicate world travel, particularly on a large scale. You mau be l ...
随机推荐
- row_number() over partition by 分组聚合
分组聚合,就是先分组再排序,可以的话顺手标个排名:如果不想分组也可以排名:如果不想分组同时再去重排名也可以 ROW_NUMBER() OVER( [PARTITION BY column_1, col ...
- Reciting(second)
It is subtly revealed in the caricature that a son is expressing his concern about disposing of nu ...
- 在Python中写入文件时,权限被拒绝错误
我想创建一个文件并在python中写一些整数数据.例如,我有一个变量abc = 3,我试图将它写入一个文件(它不存在,我假设python将自己创建): fout = open("newfil ...
- 使用腾讯地图请求来源未被授权, 此次请求来源域名/ip:servicewechat.com
原文:微信小程序使用腾讯地图请求来源未被授权, 此次请求来源域名:servicewechat.com 版权声明:本文为博主原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接和本声明 ...
- VIM编辑器使用及插件配置
1.VIM的三种模式: 普通模式.插入模式.命令行模式2.三种模式的转换: 2.1进入普通模式 ①打开VIM默认为普通模式 ②处于插入模式/命令行模式时,按ESC进入普通模式 2.2进入插入模式: A ...
- HDFS学习笔记二
文章来源于:https://blog.csdn.net/xuejingfu1/article/details/52554174 文件写入staging(分阶段进行) 一个客户端的创建文件的请求并不直接 ...
- smb.conf - Samba组件的配置文件
总览 SYNOPSIS smb.conf是Samba组件的配置文件,包含Samba程序运行时的配置信息.smb.conf被设计成可由swat (8)程序来配置和管理.本文件包含了关于smb.conf的 ...
- 2019牛客暑期多校训练营(第六场)C E H G
C Palindrome Mouse E Androgynos 参考https://blog.csdn.net/birdmanqin/article/details/98479219这位大佬的.构造题 ...
- Node.js定时邮件的那些事儿
近开发一个项目,需要在Node.js程序里实现定期给管理员发邮件的功能. 笔者平时只会在Web界面收发邮件.对邮件的原理完全不懂(可能大学教过,然而全忘了),直到要解决这个问题.请教了几个业务的同事, ...
- jQuery HTML-设置
例子1 html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> &l ...