UVALive 7501 Business Cycle
细心题
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define ms(arr,a) memset(arr,a,sizeof arr)
#define debug(x) cout<<"< "#x" = "<<x<<" >"<<endl
typedef long long ll;
const int maxn=1e5+5;
int n;
ll g,p;
int a[maxn];
ll dp[maxn],sum[maxn];
bool ok1(ll m)
{
if(m>=g)return true;
int tmp=min(ll(n),p);
for(int i=0;i<tmp;++i)
{
m=m+a[i]<=0?0:m+a[i];
if(m>=g)return true;
}
return false;
}
bool ok2(ll m)
{
for(int i=0;i<n;++i)
{
m=m+a[i]<=0?0:m+a[i];
if(m>=g)return true;
}
ll gain,gg=0;
if(sum[n-1]<=0)
{
int tmp=p<2*n?p-n:n;
gain=dp[tmp-1];
}
else
{
if(p<2*n)gain=dp[p-n-1];
else
{
int tmp=p%n?p%n+n:n;
if(((g-m)/sum[n-1])<=((p-n-tmp)/n))return true;
gain=(p-n-tmp)/n*sum[n-1];
gg=max(dp[tmp%n-1]+sum[n-1],dp[n-1]);
}
}
if(m+gain>=g-gg)return true;
return false;
}
int main()
{
//freopen("Input.txt","r",stdin);
//freopen("1.txt","w",stdout);
int T;scanf("%d",&T);
for(int Case=1;Case<=T;++Case)
{
scanf("%d%lld%lld",&n,&g,&p);
for(int i=0;i<n;++i)scanf("%d",a+i);
sum[0]=a[0];dp[0]=a[0]>0?a[0]:0;
for(int i=1;i<n;++i)
{
sum[i]=sum[i-1]+a[i];
dp[i]=sum[i]>dp[i-1]?sum[i]:dp[i-1];
}
if(p<=n)
{
ll l=0,m,r=g;
while(l<r)
{
m=(l+r)/2;
if(ok1(m))r=m;
else l=m+1;
}
printf("Case #%d: %lld\n",Case,l);
}
else
{
ll l=0,m,r=g;
while(l<r)
{
m=(l+r)/2;
if(ok2(m))r=m;
else l=m+1;
}
printf("Case #%d: %lld\n",Case,l);
}
}
//freopen("CON","w",stdout);
//system("start 1.txt");
}
UVALive 7501 Business Cycle的更多相关文章
- UVALive 7501 Business Cycle(二分)题解
题意:n个数,有一个起始值,按顺序从第一个开始不断循环取数,如果取完后相加小于0就变为0,最多取p个数,问你得到大于等于值g所需要的最小起始值为多少 思路:这题目爆long long爆的毫无准备,到处 ...
- 2015 ACM/ICPC EC-Final
A. Boxes and Balls 二分找到最大的不超过$n$的$\frac{x(x+1)}{2}$形式的数即可. #include <bits/stdc++.h> using name ...
- Machine and Deep Learning with Python
Machine and Deep Learning with Python Education Tutorials and courses Supervised learning superstiti ...
- ORGANISING THE TEST CASES
ORGANISING THE TEST CASES -Test note of “Essential Software Test Design” 2015-09-24 目录 22.1 Test Cas ...
- AIMR 固定收益推荐读物
目录 AIMR Suggested Fixed-Income Readings I. Perspectives on Interest Rates and Pricing of Traditional ...
- UVALive - 5135 - Mining Your Own Business(双连通分量+思维)
Problem UVALive - 5135 - Mining Your Own Business Time Limit: 5000 mSec Problem Description John D ...
- UVALive - 5135 Mining Your Own Business
刘汝佳白书上面的一道题目:题意是给定一个联通分量,求出割顶以及双连通分量的个数,并且要求出安放安全井的种类数,也就是每个双连通分量中结点数(除开 割顶)个数相乘,对于有2个及以上割顶的双连通分量可以不 ...
- UVALive 5135 Mining Your Own Business 双连通分量 2011final
题意:n条隧道由一些点连接而成,其中每条隧道链接两个连接点.任意两个连接点之间最多只有一条隧道.任务就是在这些连接点中,安装尽量少的太平井和逃生装置,使得不管哪个连接点倒塌,工人都能从其他太平井逃脱, ...
- Business Cards UVALive - 4384(画图看图。。)
只能由三种情况 都横着放 都竖着放 横和竖交错放 那就去判断好了... 具体看代码 #include <iostream> #include <cstdio> #inclu ...
随机推荐
- Redis对象——列表(List)
列表(list)类型是用来存储多个有序的字符串,列表中的每个字符串称为元素(element),一个列表最多可以存储232-1个元素.在Redis中,可以对列表两端插入(push)和弹出(pop),还可 ...
- 1044 Shopping in Mars (25分)(二分查找)
Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diam ...
- 一天学一个Linux命令:第一天 ls
文章更新于:2020-03-02 注:本文参照 man ls 手册,并给出使用样例. 文章目录 一.命令之`ls` 1.名字及介绍 2.语法格式 3.输出内容示例 4.参数 二.命令实践 1.`ls ...
- GitHub+PicGo构建免费图床及其高效使用
搭建免费图床全过程! 一.搭建缘由 一开始搭建博客,避免不了要用许多图片,最初使用七牛云来做博客图床,但是后来发现,七牛云只有30天的临时域名,hhhhhhh,果然啊,天下就没有免费的好事啊~后来就发 ...
- 10.6 IoStudentManager
package day11_io_student.student_demo; public class Student { private String id; private String name ...
- 生成3D多棱柱的方法(3D立体图片)
先上一个效果图 主要运用的技术点就是 确认基点,确认每个盒子旋转的度数 3D变换 transform: rotateY(-360deg); 景深 perspective 3D舞台 transfor ...
- 2019-07-31【机器学习】无监督学习之降维PCA算法实例 (鸢尾花)
样本 代码: import matplotlib.pyplot as plt from sklearn.decomposition import PCA from sklearn.datasets i ...
- Starlims Client Request Portal 客户申请门户
用户可以直接在starlims对外的"客户申请门户"上发起检验申请,并追踪检验进度等. 工作流程图示如下:
- 模仿NetFlix首页效果
之前写过UWP 带左右滚动按钮的横向ListView———仿NetFlix首页河的设计,讲述了如何设计一个带有左右滚动按钮横向的ListView. 不过我在半年之前挖了一个坑,由于工作关系,没时间来填 ...
- 发现一款手绘可视化神器!Python绘图还在用Matplotlib?out了 !
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取htt ...