建议降红
查看原帖
建议降红
746240
linmoxi楼主2024/12/18 22:21

P1035 [NOIP2002 普及组] 级数求和(红题)

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,t=0,cnt=0;
	cin>>n;
	while(n){
		n--;
		t++;
		cnt++;
		if(t==3){
			n++;
			t=0;
		}
	}
	cout<<cnt;
}

本题:

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    int n;
    double t=0.0;
    cin>>n;
    for(int i=1; ;i++){
    	t+=1.0/i;
    	if(t>n*1.0){
    		cout<<i;
    		return 0;
    	}
    }
    return 0;
}

我就说,AC代码这么短,算法又不复杂,为什么不降红???

2024/12/18 22:21
加载中...