/ Randle /

记录详情

Compile Error

/in/foo.cc: In function 'bool judge(double)':
/in/foo.cc:61:3: error: reference to 'hash' is ambiguous
   hash[c[i].p]=i;
   ^~~~
/in/foo.cc:14:5: note: candidates are: int hash [100001]
 int hash[100001];
     ^~~~
In file included from /usr/include/c++/7/bits/basic_string.h:6575:0,
                 from /usr/include/c++/7/string:52,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from /in/foo.cc:1:
/usr/include/c++/7/bits/functional_hash.h:58:12: note:                 template<class _Tp> struct std::hash
     struct hash;
            ^~~~
/in/foo.cc:62:24: error: reference to 'hash' is ambiguous
   if(c[i].v==c[i-1].v&&hash[c[i-1].p]!=0)
                        ^~~~
/in/foo.cc:14:5: note: candidates are: int hash [100001]
 int hash[100001];
     ^~~~
In file included from /usr/include/c++/7/bits/basic_string.h:6575:0,
                 from /usr/include/c++/7/string:52,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from /in/foo.cc:1:
/usr/include/c++/7/bits/functional_hash.h:58:12: note:                 template<class _Tp> struct std::hash
     struct hash;
            ^~~~
/in/foo.cc:63:4: error: reference to 'hash' is ambiguous
    hash[c[i].p]=hash[c[i-1].p];
    ^~~~
/in/foo.cc:14:5: note: candidates are: int hash [100001]
 int hash[100001];
     ^~~~
In file included from /usr/include/c++/7/bits/basic_string.h:6575:0,
                 from /usr/include/c++/7/string:52,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from /in/foo.cc:1:
/usr/include/c++/7/bits/functional_hash.h:58:12: note:                 template<class _Tp> struct std::hash
     struct hash;
            ^~~~
/in/foo.cc:63:17: error: reference to 'hash' is ambiguous
    hash[c[i].p]=hash[c[i-1].p];
                 ^~~~
/in/foo.cc:14:5: note: candidates are: int hash [100001]
 int hash[100001];
     ^~~~
In file included from /usr/include/c++/7/bits/basic_string.h:6575:0,
                 from /usr/include/c++/7/string:52,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from /in/foo.cc:1:
/usr/include/c++/7/bits/functional_hash.h:58:12: note:                 template<class _Tp> struct std::hash
     struct hash;
            ^~~~
/in/foo.cc:67:12: error: reference to 'hash' is ambiguous
   ans+=sum(hash[i]);
            ^~~~
/in/foo.cc:14:5: note: candidates are: int hash [100001]
 int hash[100001];
     ^~~~
In file included from /usr/include/c++/7/bits/basic_string.h:6575:0,
                 from /usr/include/c++/7/string:52,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from /in/foo.cc:1:
/usr/include/c++/7/bits/functional_hash.h:58:12: note:                 template<class _Tp> struct std::hash
     struct hash;
            ^~~~
/in/foo.cc:68:6: error: reference to 'hash' is ambiguous
   in(hash[i]+1);
      ^~~~
/in/foo.cc:14:5: note: candidates are: int hash [100001]
 int hash[100001];
     ^~~~
In file included from /usr/include/c++/7/bits/basic_string.h:6575:0,
                 from /usr/include/c++/7/string:52,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from /in/foo.cc:1:
/usr/include/c++/7/bits/functional_hash.h:58:12: note:                 template<class _Tp> struct std::hash
     struct hash;
            ^~~~

代码

#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)
			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:20:53
评测时间
2017-10-26 20:20:53
评测机
分数
0
总耗时
1434ms
峰值内存
134.09 MiB