细心题

#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的更多相关文章

  1. UVALive 7501 Business Cycle(二分)题解

    题意:n个数,有一个起始值,按顺序从第一个开始不断循环取数,如果取完后相加小于0就变为0,最多取p个数,问你得到大于等于值g所需要的最小起始值为多少 思路:这题目爆long long爆的毫无准备,到处 ...

  2. 2015 ACM/ICPC EC-Final

    A. Boxes and Balls 二分找到最大的不超过$n$的$\frac{x(x+1)}{2}$形式的数即可. #include <bits/stdc++.h> using name ...

  3. Machine and Deep Learning with Python

    Machine and Deep Learning with Python Education Tutorials and courses Supervised learning superstiti ...

  4. ORGANISING THE TEST CASES

    ORGANISING THE TEST CASES -Test note of “Essential Software Test Design” 2015-09-24 目录 22.1 Test Cas ...

  5. AIMR 固定收益推荐读物

    目录 AIMR Suggested Fixed-Income Readings I. Perspectives on Interest Rates and Pricing of Traditional ...

  6. UVALive - 5135 - Mining Your Own Business(双连通分量+思维)

    Problem   UVALive - 5135 - Mining Your Own Business Time Limit: 5000 mSec Problem Description John D ...

  7. UVALive - 5135 Mining Your Own Business

    刘汝佳白书上面的一道题目:题意是给定一个联通分量,求出割顶以及双连通分量的个数,并且要求出安放安全井的种类数,也就是每个双连通分量中结点数(除开 割顶)个数相乘,对于有2个及以上割顶的双连通分量可以不 ...

  8. UVALive 5135 Mining Your Own Business 双连通分量 2011final

    题意:n条隧道由一些点连接而成,其中每条隧道链接两个连接点.任意两个连接点之间最多只有一条隧道.任务就是在这些连接点中,安装尽量少的太平井和逃生装置,使得不管哪个连接点倒塌,工人都能从其他太平井逃脱, ...

  9. Business Cards UVALive - 4384(画图看图。。)

    只能由三种情况 都横着放  都竖着放  横和竖交错放 那就去判断好了... 具体看代码 #include <iostream> #include <cstdio> #inclu ...

随机推荐

  1. P1006 传纸条(二维、三维dp)

    P1006 传纸条 输入输出样例 输入 #1 复制 3 3 0 3 9 2 8 5 5 7 0 输出 #1 复制 34 说明/提示 [限制] 对于 30% 的数据,1≤m,n≤10: 对于 100% ...

  2. webpack4.x 从零开始配置vue 项目(三)

    目标 babel 转换ES6 语法 postCss 增强css功能,如自动增加前缀 vue-loader 解析vue 文件 实现基本的vue项目开发环境,打包等 Babel 由于浏览器对es6语法兼容 ...

  3. Linux基础:Day06

    网路安全介绍背景: 早起的互联网 -- 1980年代 ,我们需要共享数据,传输数据:所传输或者共享的数据均为明文: 随着互连网发展,安全称为了国家的一种战略资源: 我们做的,比如编程,运维 -- 手工 ...

  4. 个推IGt.BaseTemplate.php,不仅有bug,还有bom头,好恶心!

    错误截图,提交吧,还有一个不明飞行物. 去掉utf-8 BOM:set nobomb保留utf-8 BOM:set bomb

  5. 2059 - Authentication plugin 'caching_sha2_password' cannot be loaded dlope

    今天在mac上使用navicat连接mysql报错弄了一下午,各种查询踩坑,总算解决了. 即从mysql5.7版本之后,默认采用了caching_sha2_password验证方式,我用的mysql8 ...

  6. docker、docker-compose安装,卸载

    docker win10安装 一.安装 https://www.docker.com/docker-windows 二.设置 控制面板-->程序-->Hyper-V linux安装: ht ...

  7. Tcl编程第一天,helloworld

    #!/usr/bin/tclsh puts "hello world" 注意:第一行代码表示的是tcl程序运行所需要的文件位置 puts函数代表输出

  8. python如何操作excel 基础代码

    一 基础操作1打开excel表格并获取表格名称 wookbook = load_workbook(filename = 表格文件路径) (注意只能打开存在的表格,不能用该方法创建一个新表格文件) wo ...

  9. bootstrapTable随机改变列颜色

    { title: '运单编号', field: 'waybillNumber', align: 'center', valign: 'middle', cellStyle: function (val ...

  10. AJ整理问题之:NSTimer准确吗?

    NSTimer准确吗? 问题:NSTimer准确吗?如果不准确,怎么办? NSTimer的工作原理:假设timer每隔一段时间执行一次事件,很均匀的(例如每隔多少秒),假设在某一时刻cpu在做疯狂的大 ...