为何报错?
查看原帖
为何报错?
959582
dongrunxuan楼主2024/3/29 11:41

rt,当我在C++ 6.3运行时它报了 [Error] no type named 'value_type' in 'struct std::iterator_traits<int>'
判断是setprecision的原因

代码如下

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e4+10;
int l=0,r=10000005;
int n,k,len[maxn];
double t;
bool judge(int x)
{
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		cnt+=(len[i]/x);
	}
	return cnt>=k;
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>t;
		len[i]=t*100;
	}
	sort(l+1,l+n+1);
	double ans=0;
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(judge(mid))
		{
			ans=mid;
			l=mid+1;
		}
		else 
		{
			r=mid-1;	
		}
	}
	cout<<setprecision(2)<<ans/100.0;
	return 0;
}
2024/3/29 11:41
加载中...