1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| #include<bits/stdc++.h> using namespace std; const double eps=1e-5; long long n,sum=0; double m; int i; int a,b,c,d,kl=0,kl1=0; int flag=0; char ch1,ch2={'+','-','*','/'}; struct ss { int a1,a2,a3,a4,a5; }e; void shuchu(){cout<<i<<ch1<<i<<ch1<<i<<ch1<<i<<' '<<flag<<endl;} inline void cun() { int i1=i,i2=i,i3=i,i4=i; sort(i+1,i+5); e.a1=i; e.a2=i; e.a3=i; e.a4=i; e.a5=flag; i=i1,i=i2,i=i3,i=i4; } inline double ji(double num1,double num2,char ch) { //flag=0; double ans,hj; if(ch=='+')ans=num1+num2; if(ch=='-')ans=num1-num2; if(ch=='*')ans=num1*num2; if(ch=='/'&&num2-0>=eps)ans=num1/num2; if(ch=='/'&&num2-0.0<=eps)return -30000; int aa=ans; if((double)(ans*1.0-(double)aa*1.0)<0.0)hj=0.0-(double)(ans*1.0-(double)aa*1.0); else hj=(double)(ans*1.0-(double)aa*1.0); //if(i==1&&i==1&&i==1&&i==12)cout<<hj<<' '<<ans<<endl; if(hj<eps)flag=-1; return ans; } inline bool Ji(double num1,double num2,char ch) { double ans,hj; if(ch=='+')ans=num1+num2; if(ch=='-')ans=num1-num2; if(ch=='*')ans=num1*num2; if(ch=='/'&&num2-0>=eps)ans=num1/num2; if(ch=='/'&&num2-0.0<=eps)return 0; if((double)(ans-(double)m)<0.0)hj=0.0-(double)(ans-(double)m); else hj=(double)(ans-(double)m); /*if(i==8&&i==3&&i==8&&i==3) { printf("%0.20lf %lf\n",hj,m); shuchu(); if(hj<eps)cout<<"^&%&$%^"<<endl; }*/ if(hj<eps)return 1; return 0; } inline void dfs(int now) { if(now==4) { flag=0; if(Ji(ji(ji(i,i,ch1),i,ch1),i,ch1)){flag=((flag==-1)?(-1):1);cun();}flag=0; if(Ji(ji(i,ji(i,i,ch1),ch1),i,ch1)){flag=((flag==-1)?(-1):1);cun();}flag=0; if(Ji(i,ji(ji(i,i,ch1),i,ch1),ch1)){flag=((flag==-1)?(-1):1);cun();}flag=0; /*if(i==8&&i==3&&i==8&&i==3) { printf("%0.20lf %lf\n",Ji(i,ji(i,ji(i,i,ch1),ch1),ch1),m); shuchu(); double ans=Ji(i,ji(i,ji(i,i,ch1),ch1),ch1),hj; if((double)(ans*1.0-(double)m*1.0)<0.0)hj=0.0-(double)(ans*1.0-(double)m*1.0); else hj=(double)(ans*1.0-(double)m*1.0); if(hj<eps) cout<<"^&%&$%^"<<endl; }flag=0;*/ if(Ji(i,ji(i,ji(i,i,ch1),ch1),ch1)){flag=((flag==-1)?(-1):1);cun();}flag=0; if(Ji(ji(i,i,ch1),ji(i,i,ch1),ch1)){flag=((flag==-1)?(-1):1);cun();}flag=0; return; } for(int i=0;i<4;i++) { ch1=ch2; dfs(now+1); } } inline bool mycmp(ss s1,ss s2) { if(s1.a1==s2.a1) { if(s1.a2==s2.a2) { if(s1.a3==s2.a3)return s1.a4<s2.a4; return s1.a3<s2.a3; } return s1.a2<s2.a2; } return s1.a1<s2.a1; } int main() { cin>>n>>m; if(n<4){cout<<0<<endl;return 0;} for(i=1;i<=13;i++) { for(i=1;i<=13;i++) { for(i=1;i<=13;i++) { for(i=1;i<=13;i++) { flag=0; dfs(1); } } } } sort(e+1,e+kl+1,mycmp); for(int i=1,fl=0;i<=kl;i++) { fl=0; while(e.a1==e.a1&&e.a2==e.a2&&e.a3==e.a3&&e.a4==e.a4) { if(e.a5==-1)fl=1; if(e.a1==e.a1&&e.a2==e.a2&&e.a3==e.a3&&e.a4==e.a4)i++; else break; } if(fl==0&&e.a5==1)kl1++; } cout<<kl1<<endl; for(int i=1,fl=0;i<=kl;i++) { fl=0; while(e.a1==e.a1&&e.a2==e.a2&&e.a3==e.a3&&e.a4==e.a4) { if(e.a5==-1)fl=1; if(e.a1==e.a1&&e.a2==e.a2&&e.a3==e.a3&&e.a4==e.a4)i++; else break; } if(fl==0&&e.a5==1)printf("%d %d %d %d\n",e.a1,e.a2,e.a3,e.a4); } return 0; }
|