QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#111782#6395. Equation Discoveringdo_while_true#WA 2ms3740kbC++143.3kb2023-06-08 19:14:532023-06-08 19:14:55

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-08 19:14:55]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3740kb
  • [2023-06-08 19:14:53]
  • 提交

answer

#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<random>
#include<assert.h>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n';
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n';
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pil>vpil;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
	r=0;bool w=0;char ch=getchar();
	while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
	while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
	return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int mod=998244353;
inline void cadd(int &x,int y){x=(x+y>=mod)?(x+y-mod):(x+y);}
inline void cdel(int &x,int y){x=(x-y<0)?(x-y+mod):(x-y);}
inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
inline int del(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
int qpow(int x,int y){
	int s=1;
	while(y){
		if(y&1)s=1ll*s*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return s;
}
const int N=110;
int n;
ld a[N],b[N];
char op[N];
ld st[N];
int tot;
void check(int len){
	int fl=0;
	for(int i=1;i<=n;i++){
		tot=0;
		for(int j=1;j<=len;j++){
			if(op[j]=='x')st[++tot]=a[i];
			if(op[j]=='s')st[tot]=sin(st[tot]);
			if(op[j]=='c')st[tot]=cos(st[tot]);
			if(op[j]=='+')st[tot-1]=st[tot]+st[tot-1],--tot;
			if(op[j]=='-')st[tot-1]=st[tot]-st[tot-1],--tot;
			if(op[j]=='*')st[tot-1]=st[tot]*st[tot-1],--tot;
			if(op[j]=='/'){
				if(abs(st[tot])<0.01)return ;
				st[tot-1]=st[tot-1]/st[tot],--tot;
			}
		}
		if(abs(st[1]-b[i])/max(1.0,abs(b[i]))>0.001)return ;
//		assert(tot==1);
	}
	string o[110];
	int ct=0;
	for(int i=1;i<=len;i++){
		if(op[i]=='x')o[++ct]="x";
		if(op[i]=='s')o[ct]="sin("+o[ct]+")";
		if(op[i]=='c')o[ct]="cos("+o[ct]+")";
		if(op[i]=='+')o[ct-1]="("+o[ct-1]+")+("+o[ct]+")",--ct;
		if(op[i]=='-')o[ct-1]="("+o[ct-1]+")-("+o[ct]+")",--ct;
		if(op[i]=='*')o[ct-1]="("+o[ct-1]+")*("+o[ct]+")",--ct;
		if(op[i]=='/')o[ct-1]="("+o[ct-1]+")/("+o[ct]+")",--ct;
	}
	cout << o[1] << '\n';
	exit(0);
}
void dfs(int now,int h,int top){
	if((top-1)*2+h>9)return ;
	if(top==1)check(now-1);
	op[now]='x';
	dfs(now+1,h,top+1);
	if(top>1){
		op[now]='+';
		dfs(now+1,h+2,top-1);
		op[now]='-';
		dfs(now+1,h+2,top-1);
		op[now]='*';
		dfs(now+1,h+2,top-1);
		op[now]='/';
		dfs(now+1,h+2,top-1);
	}
	op[now]='s';
	dfs(now+1,h+1,top);
	op[now]='c';
	dfs(now+1,h+1,top);
}
signed main(){
	#ifdef do_while_true
//		assert(freopen("data.in","r",stdin));
//		assert(freopen("data.out","w",stdout));
	#endif
	read(n);
	for(int i=1;i<=n;i++){
		scanf("%lf%lf",&a[i],&b[i]);
	}
	op[1]='x';
	dfs(2,0,1);
    #ifdef do_while_true
		cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
	#endif
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3636kb

input:

3
1.000000 1.000000
2.000000 4.000000
3.000000 9.000000

output:

(x)*((x)+((x)*((x)-(x))))

result:

ok great!!

Test #2:

score: 0
Accepted
time: 2ms
memory: 3740kb

input:

3
0.618000 1.517072
0.314000 3.132637
1.414000 0.494016

output:

(x)/((x)*((x)*((x)/(sin(x)))))

result:

ok great!!

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 3700kb

input:

5
77.685777 233.057331
-66.445083 -199.335249
79.966717 239.900151
84.982130 254.946390
-31.528900 -94.586700

output:

(x)-((x)+((x)+((x)+(x))))

result:

wrong answer fail to discover