/ Randle /

记录详情

Wrong Answer


  
# 状态 耗时 内存占用
#1 Wrong Answer 6ms 4.941 MiB
#2 Accepted 7ms 4.82 MiB
#3 Accepted 4ms 3.445 MiB
#4 Wrong Answer 111ms 5.32 MiB
#5 Wrong Answer 56ms 4.441 MiB
#6 Accepted 73ms 4.453 MiB
#7 Accepted 80ms 4.816 MiB
#8 Accepted 89ms 3.574 MiB
#9 Accepted 78ms 3.742 MiB
#10 Accepted 109ms 3.566 MiB

代码

#include <bits/stdc++.h>
using namespace std;
int a[100001],b[100001];//原始数据 
double s[100001];//前序和 
struct node
{
	int p;
	double v;
	inline bool operator < (node x)
	{
		return v<x.v;
	}
}c[100001];//HASH
int HASH[100001];
int d[400001];//没错我就是树状数组!! 
inline int read()
{
	char ch=getchar();
	int x=0;
	while(!isdigit(ch))
		ch=getchar();
	while(isdigit(ch))
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x;
}
int n,k;

inline int sum(int x)
{
	int ans=0;
	while(x)
	{
		ans+=d[x];
		x-=(x&-x); 
	}
	return ans;
}
inline void in(int x)
{
	while(x<=n)
	{
		d[x]++;
		x+=(x&-x);
	}
}
bool judge(double x)
{
	memset(d,0,sizeof(d));
	int i,ans=0;
	for(i=1;i<=n;i++)
	{
		s[i]=s[i-1]+(double)a[i]-(double)b[i]*x;
		c[i].p=i,c[i].v=s[i];
	}
	sort(c+1,c+n+1);//HASH,将数转化为整数; 
	for(i=1;i<=n;i++)
	{
		HASH[c[i].p]=i;
		if(c[i].v==c[i-1].v&&HASH[c[i-1].p]!=0)
			HASH[c[i].p]=HASH[c[i-1].p];
	}
	for(i=1;i<=n;i++)//树状数组闪亮登场!!!! 
	{
		ans+=sum(HASH[i]);
		in(HASH[i]+1);
		if(ans>=k+1)
			return true; 
	}
	return false;
}
int main()
{
	int i;
	double l=0,r=0,mid;
	n=read(),k=read();
	for(i=1;i<=n;i++)
		a[i]=read();
	for(i=1;i<=n;i++)
	{
		b[i]=read();
		r=max(r,(double)a[i]/b[i]);
	}
	while(l<r&&r-l>0.003)
	{
		mid=(l+r)/2;
		if(judge(mid)) l=mid;
		else r=mid;
	}
	printf("%.2lf",l);
}

信息

递交者
类型
递交
题目
梁山伯与祝英台(原创)
题目数据
下载
语言
C++
递交时间
2017-10-26 20:28:44
评测时间
2017-10-26 20:28:44
评测机
分数
70
总耗时
616ms
峰值内存
5.32 MiB