题解 CF409G 【On a plane】
JustinRochester · · 题解
其实本蒟蒻是看到以前有大犇用main()函数递归写了程序,于是才心血来潮写的代码......
【分析】
其实我们需要的量只有n,sumy(y的总和)而已,其它的量根本不需要维护。
因此,我们对于每次输入,直接忽略x。且输入y后累加到sumy。最后直接将sumy/n+5输出即可。
这里引入一个变量count,记录循环的次数,达到n次以后跳出即可。
【代码】
那本蒟蒻就代码附上:
#include<cstdio>
using namespace std;
int n=0,count=0;
float sumy=0;
int main(){
if(!n) { scanf("%d",&n); main();}
//未输入n时特判一下
else if(count==n) { printf("%.3f",5+sumy/n); return 0; }
else{
float x;scanf("%*f %f",&x);
sumy+=x;count++;
main();
}
}