比赛 欢乐水题赛 评测结果 AAAAAAAAAA
题目名称 奶牛的心理阴影 最终得分 100
用户昵称 Satoshi 运行时间 0.010 s
代码语言 C++ 内存使用 0.31 MiB
提交时间 2015-04-24 15:47:50
显示代码纯文本
#include <fstream>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
string S;
bool flag=1;
vector<int> q;
ifstream in("heartarea.in");
ofstream out("heartarea.out");
long double l,r,ans1=0,ans2=0,ans3=0;
int ask=0;
int c;
class point
{
public:
	int a;
	int b;
}po[11];
int mark(int x)
{
	int i;
	int ans=1;
	for(i=1;i<=x;i++)ans*=10;
	return ans;
}
long double F(int l,int x)
{
	int i;
	long double sum=1;
	long double sp=po[x].a/double(x+1);
	//out<<sp<<endl;
	//out<<sp<<endl;
	for(i=1;i<=x+1;i++)sum*=l;
	//out<<sp<<endl;
	sum*=sp;
	//out<<sum<<endl;
	return sum;
}
int main()
{
	int i,j,text1,text2,p=0,Orz=1;
	bool fuhao=0;
	in>>S;
	//out<<S<<endl;
	for(i=0;i<S.length();i++)
	{
		text1=text2=0;
		if(S[i]=='x')
		{
			Orz=0;
			p=0;
			for(j=i-1;j>=0;j--)
			{
				//out<<S[j]<<endl;
				if(S[j]=='+')
				{	
					if(!Orz)Orz=1;
					text1+=Orz;
					break;
				}
				/*if(S[j]=='-')
				{
					if(!Orz)Orz=1;
					text1-=Orz;
					break;
				}*/
				Orz+=int(S[j]-'0')*mark(p);
				p++;
				//out<<j<<endl;
				if(j==0&&(S[j]>='0'||S[j]<='9'))
				{
					//out<<"fuck"<<endl;
					text1+=Orz;
					break;
				}
				//out<<Orz<<endl;
				/*if(S[j]>='0'&&S[j]<='9'&&i==0)
				{
					text1=1;
					break;
				}*/
			}
			if(i==0)text1=1;
			if(i+1<S.length())
			{
				if(S[i+1]=='^')
				{
					//out<<S[i+2]<<endl;
					text2=int(S[i+2]-'0');
				}
				else
				{
					text2=1;
				}
			}
			else text2=1;
		}
		//out<<text1<<' '<<text2<<endl;
		po[text2].a+=text1;
	}
	//out<<S<<endl;
	q.push_back(-1);
	for(i=0;i<S.length();i++)
	{
		if(S[i]=='+')
		{
			q.push_back(i);
		    //out<<i<<' '<<S[i]<<endl;
		}
	}
	q.push_back(S.length());
	//for(i=0;i<q.size();i++)out<<q[i]<<' ';
	for(i=0;i<q.size()-1;i++)
	{
		//out<<i<<' ';
		flag=1;
		int sum=0;
		//out<<q[i]+1<<' '<<q[i+1]-1<<endl;
		for(j=q[i]+1;j<=q[i+1]-1;j++)
		{
			//out<<q[i]+1<<' '<<q[i+1]-1<<endl;
			if(S[j]<'0'||S[j]>'9')
			{
				flag=0;
				break;
			}
		}
		//for(j=q[i]+1;j<=q[i+1]-1;j++)out<<S[j]<<' ';
		if(flag)
		{
			int p=0;
			for(j=q[i+1]-1;j>=q[i]+1;j--)
			{
				sum+=int(S[j]-'0')*mark(p);
				p++;
				//out<<sum<<endl;
			}
			//out<<endl;
		}
		//out<<"fuck"<<endl;
		//out<<sum<<endl;
		po[0].a+=sum;
	}
	in>>c;
	//for(i=0;i<=10;i++)out<<po[i].a<<' ';
	for(i=0;i<=9;i++)po[i].b=i+1;
	in>>ask;
	//out<<ask<<endl;
	for(j=1;j<=ask;j++)
	{
		//out<<ask<<endl;
		ans2=ans1=0;
		in>>l>>r;
		//out<<i<<endl;
		//out<<l<<' '<<r<<endl;
	    for(i=0;i<=9;i++)ans1+=F(l,i);
	    for(i=0;i<=9;i++)ans2+=F(r,i);
	    ans3=ans2-ans1;
		//out<<ans1<<' '<<ans2<<endl;
	    out<<setprecision(c)<<std::fixed<<ans3<<endl;
	}
	return 0;
}