记录详情

Accepted

foo.cc: In function ‘int main()’:
foo.cc:27:28: warning: unused variable ‘maxn’ [-Wunused-variable]
   27 |         double l=0,r=0,ans,maxn=0;
      |                            ^~~~
In file included from /nix/gcc-14.2.1.20250322/include/c++/14.2.1.20250322/istream:41,
                 from /nix/gcc-14.2.1.20250322/include/c++/14.2.1.20250322/sstream:40,
                 from /nix/gcc-14.2.1.20250322/include/c++/14.2.1.20250322/complex:45,
                 from /nix/gcc-14.2.1.20250322/include/c++/14.2.1.20250322/ccomplex:39,
                 from stdc++.h:127:
In member function ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>]’,
    inlined from ‘int main()’ at foo.cc:44:32:
/nix/gcc-14.2.1.20250322/include/c++/14.2.1.20250322/ostream:232:25: warning: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
  232 |       { return _M_insert(__f); }
      |                ~~~~~~~~~^~~~~
foo.cc: In function ‘int main()’:
foo.cc:27:24: note: ‘ans’ was declared here
   27 |         double l=0,r=0,ans,maxn=0;
      |                        ^~~
# 状态 耗时 内存占用
#1 Accepted 2ms 504.0 KiB
#2 Accepted 4ms 504.0 KiB
#3 Accepted 8ms 612.0 KiB
#4 Accepted 8ms 504.0 KiB
#5 Accepted 8ms 504.0 KiB
#6 Accepted 4ms 488.0 KiB
#7 Accepted 5ms 504.0 KiB
#8 Accepted 5ms 364.0 KiB
#9 Accepted 5ms 496.0 KiB
#10 Accepted 7ms 532.0 KiB

代码

#include <bits/stdc++.h>
using namespace std;
const int N=100000+10;
const double PI=acos(-1),modn=1e-5;
double num[N];
int n,m;
double V(int n) {
	double v=n*n*PI;
	return v;
}
bool check(double x) {
	int tans=0;
	for(int i=0; i<n; i++) {
		tans+=floor(num[i]/x);
	}
	if(tans>=m+1) {
		return true;
	} else {
		return false;
	}
}
int main() {
	/*
	freopen("data10.in","r",stdin);
	freopen("data10.out","w",stdout);
	*/
	double l=0,r=0,ans,maxn=0;
	int temp;
	cin>>n>>m;
	for(int i=0; i<n; i++) {
		cin>>temp;
		num[i]=V(temp);
		r=max(r,num[i]);
	}
	while(r-l>modn) {
		double mid=(l+r)/2;
		if(check(mid)) {
			ans=mid;
			l=mid;
		} else {
			r=mid;
		}
	}
	cout<<fixed<<setprecision(3)<<ans;
	return 0;
}

信息

递交者
类型
递交
题目
P1001 小Q的生日派
题目数据
下载
语言
C++
递交时间
2025-05-10 17:47:22
评测时间
2025-05-10 17:47:22
评测机
分数
100
总耗时
60ms
峰值内存
612.0 KiB