2 条题解

  • 1
    @ 2025-1-16 9:58:22
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	int n;
    	double pi = 0.0;
    	cin >> n;
    	for (int i = 1; i <= n; i++){
    		if (i % 2 != 0)
    			pi = pi + 4.0 * 1 / (2 * i - 1);
    		else
    			pi = pi - 4.0 * 1 / (2 * i - 1);
    	} 
    	cout << fixed << setprecision(6) << pi;
    	return 0;
    }
    
    • 0
      @ 2024-10-13 16:19:22
      #include<iostream> 
      #include<iomanip>
      using namespace std;
      int main(){
      	int a;
      	double b,c;
      	cin>>a;
      	for(int i=1;i<a+1;i++){
      		c=i;
      		if((i+1)%2==0){
      			b+=1/(2*c-1);
      		}else{
      			b+=-1/(2*c-1);
      		}
      	}
      	cout<<fixed<<setprecision(6)<<4*b;
      }
      
      • 1

      信息

      ID
      41
      时间
      1000ms
      内存
      256MiB
      难度
      6
      标签
      (无)
      递交数
      238
      已通过
      80
      上传者