bzoj有毒,看不了自己哪错了。。。根本没法debug、

我到现在还是不知道自己代码为什么会T,二分次数也加限制了,但是还是T。。。救命啊!!!

题干:

Description
著名出题人小Q的备忘录上共有n道可以出的题目,按照顺序依次编号为1到n,其中第i道题目的难度系数被小Q估计
为a_i,难度系数越高,题目越难,负数表示这道题目非常简单。小Q现在要出一套难题,他决定从备忘录中选取编
号连续的若干道题目,使得平均难度系数最高。当然,小Q不能做得太过分,一套题目必须至少包含k道题目,因此
他不能通过直接选取难度系数最高的那道题目来组成一套题。请写一个程序,帮助小Q挑选平均难度系数最高的题
目。
Input
第一行包含两个整数n,k(<=n<=,<=k<=n),分别表示题目的总量和题数的下界。
第二行包含n个整数a_1,a_2,...,a_n(|a_i|<=^),分别表示每道题目的难度系数。
Output 输出一个既约分数p/q或-p/q,即平均难度系数的最大值。
Sample Input - -
Sample Output
/
HINT Source claris原创,本oj版权所有,翻版必究

我的代码:(蜜汁TLE)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
const int INF = << ;
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
db a[];
db s[];
db g[];
int mn[];
db eps = 1e-;
int n,k,ok = ;;ll y,x;
db l,r;
ll gcd(ll a,ll b)
{
if(!b)
return a;
else
return gcd(b,a % b);
}
int main()
{
read(n);read(k);
l=-,r=;
duke(i,,n)
{
scanf("%lf",&a[i]);
s[i] = s[i - ] + a[i];
}
duke(p,,)
{
ok = ;
db mid = (l + r) / ;
duke(i,,n)
{
g[i] = s[i] - (db)i * mid;
}
/*duke(i,1,n)
cout<<g[i]<<" ";
cout<<endl;*/
duke(i,,n)
{
if(g[i] < g[mn[i - ]])
mn[i] = i;
else
mn[i] = mn[i - ];
}
duke(i,k,n)
{
if(g[i] > g[mn[i - k]])
{
x = s[i] - s[mn[i - k]];
y = i - mn[i - k];
ok = ;
break;
}
}
if(ok == )
{
l = mid;
}
else
{
r = mid;
}
}
ll g = gcd(x,y);
if(g < )
g = -g;
if(g)
x /= g,y /= g;
printf("%lld/%lld\n",x,y);
return ;
}
/*
5 3
1 4 -2 -3 6
*/

网上的AC代码:

#include<cstdio>
#include<algorithm>
#include<cctype>
using namespace std;
typedef double db;
typedef long long ll;
const int N=1e5+; int n,k,a[N],mn[N];
ll s[N],A,B,T;
db b[N]; inline int rd()
{
char ch=getchar();
int x=,f=;
while(!isdigit(ch))
{
if(ch=='-') f=-;
ch=getchar();
}
while(isdigit(ch))
{
x=x*+(ch^);
ch=getchar();
}
return x*f;
} bool check(db mid)
{
int i,j;
b[]=a[]-mid;
for(i=; i<=n; ++i)
{
b[i]=b[i-]+a[i]-mid;
mn[i]= b[i] < b[mn[i-]]? i:mn[i-];
}
for(i = k; i<=n; ++i)
{
if(b[i]>b[mn[i-k]])
{
A = s[i] - s[mn[i-k]];
B = i - mn[i-k];
return true;
}
}
return false;
}
inline ll gcd(ll x,ll y)
{
return !y? x:gcd(y,x%y);
} int main()
{
int i,j;
n=rd();
k=rd();
for(i=; i<=n; ++i)
{
a[i]=rd();
s[i]=s[i-]+a[i];
}
db l=-1e8,r=1e8,mid;
mn[]=;
for(i=; i<=; ++i)
{
mid=(l+r)/;
if(check(mid)) l=mid;
else r=mid;
}
T=gcd(A,B);
if(T<) T=-T;
if(T) A/=T,B/=T;
printf("%lld/%lld\n",A,B);
}

没有任何区别好不好!为什么TLE?

B5090 组题 二分答案的更多相关文章

  1. NOIP2015跳石头[二分答案]

    题目背景 一年一度的“跳石头”比赛又要开始了! 题目描述 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石.组委会已经选 择好了两块岩石作为比赛起点和终点.在起点和终点之间,有 N 块岩石( ...

  2. 洛谷P4589 [TJOI2018]智力竞赛(二分答案 二分图匹配)

    题意 题目链接 给出一个带权有向图,选出n + 1n+1条链,问能否全部点覆盖,如果不能,问不能覆盖的点权最小值最大是多少 Sol TJOI怎么净出板子题 二分答案之后直接二分图匹配check一下. ...

  3. BZOJ2653 middle(二分答案+主席树)

    与中位数有关的题二分答案是很常用的trick.二分答案之后,将所有大于它的看成1小于它的看成-1,那么只需要判断是否存在满足要求的一段和不小于0. 由于每个位置是1还是-1并不固定,似乎不是很好算.考 ...

  4. BZOJ5090 组题 BZOJ2017年11月月赛 二分答案 单调队列

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ5090 11月月赛A题 题意概括 给出n个数. 求连续区间(长度大于等于k)最大平均值. 题解 这题 ...

  5. 疫情控制 2012年NOIP全国联赛提高组(二分答案+贪心)

    P1084 疫情控制 题目描述 H 国有 n 个城市,这 n 个城市用 n-1 条双向道路相互连通构成一棵树,1 号城市是首都,也是树中的根节点. H 国的首都爆发了一种危害性极高的传染病.当局为了控 ...

  6. cogs 2109. [NOIP 2015] 运输计划 提高组Day2T3 树链剖分求LCA 二分答案 差分

    2109. [NOIP 2015] 运输计划 ★★★☆   输入文件:transport.in   输出文件:transport.out   简单对比时间限制:3 s   内存限制:256 MB [题 ...

  7. BZOJ_4590_[Shoi2015]自动刷题机_二分答案

    BZOJ_4590_[Shoi2015]自动刷题机_二分答案 Description 曾经发明了信号增幅仪的发明家SHTSC又公开了他的新发明:自动刷题机--一种可以自动AC题目的神秘装置.自动 刷题 ...

  8. Codeforces Round #402 (Div. 2) D. String Game(二分答案水题)

    D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

  9. BZOJ 4590 [Shoi2015]自动刷题机 ——二分答案

    二分答案水题. #include <cstdio> #include <cstring> #include <iostream> #include <algo ...

随机推荐

  1. mongoDB 删除集合后,空间不释放的解决方法

    mongoDB 删除集合后,空间不释放,添加新集合,没有重新利用之前删除集合所空出来的空间,也就是数据库大小只增不减. 方法有: 1.导出导入 dump & restore 2.修复数据库 r ...

  2. Json——一般应用

    引用命名空间 using Newtonsoft.Json; 序列化类或者类的集合 string jsonData1 = JsonConvert.SerializeObject(p1);//序列化类 s ...

  3. 微信小程序php后台实现

    这里简单介绍用php后台实现获取openid并保存到数据库: 微信的登陆流程是这样的 首先前端发送请求到服务器: wx.login({ success: function (res) { var co ...

  4. C# 获得枚举值中所有数据到Array(数组)中

    Array LogType = Enum.GetValues(LogTypes.登录.GetType()); public enum LogTypes { 登录, 添加, 修改, 删除, 导出, 异常 ...

  5. SpringMVC进行json数据交互

    请求key/value.输出json.此方法在开发中比较常用. 在注解适配器中加入messageConverters <!--注解适配器 --> <bean class=" ...

  6. switch方法中使用数字区间

    function getCategory(age) { var category = ""; switch (true) { case isNaN(age): category = ...

  7. Linux 下phpstudy的安装使用补充说明

    (1)使用方法 在终端中使用sudo 或者 使用管理员账号运行 phpstudy start 开启 (2)命令列表: phpstudy start | stop | restart        开启 ...

  8. 在Unity中对注册表的信息进行操作

      问题1 在对注册表进行操作时无法生成注册表相关的类  解决办法:     增加头文件using Microsft.Win32; 问题2                    在运行程序时报错同时注 ...

  9. vue 打印 页面特定部分转pdf

    https://www.jb51.net/article/147040.htm https://www.jianshu.com/p/dd120b65446a  //转pdf

  10. Django - Ajax初识

    当需要在弹出的对话框中,做判断操作时,需要用到ajax 1.host.html <!DOCTYPE html><html lang="en"><hea ...