Bzoj 3614 Heoi2014 Logical Translation Division = =heoi2014 Full AC reached?

Source: Internet
Author: User

Topic: Given a polynomial containing n variables of the 2^n term, each variable is selected-1 and 1 generation into the evaluation, to find the coefficients of the polynomial

On how to work out a problem in order to simultaneously card time Card memory card precision card input card output card evaluation

It took a long time to stare at the problem long ago ... Until today, I found that the problem is a stupid problem ...

Let's use three variables to give an example

Suppose f (x) =a0x1x2x3+a1x1x2+a2x1x3+a3x2x3+a4x1+a5x2+a6x3+a7

So we're going to put the items that contain x1 to get

F (x) =x1 (A0X2X3+A1X2+A2X3+A4) + (A3X2X3+A5X2+A6X3+A7)

Then we put x1=1 and x1=-1 into each other, two formulas plus 2, the left side of the equal sign "duang" the ground is gone!

Then we take x1=1 and X1=-1, respectively, the two formulas minus 2, the equal sign of the right "duang" ground is not!

And then.... And then... Then no then spicy ... Recursion is the end ...

So this question is actually how to deal with the problems encountered in the various disgusting situation?

Decisive BZ Countdown First, the tenth point of the machine ran 9s+, so I actually do not calculate AC off this problem?

Last point output 46MB It's freaking dad out.

Souvenir = =


#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define EPS 1e-7using namespace Std;struct ostream{#define L (1<<20) char Buffer[l],*s;ostream () {s=buffer;} void Putchar (char c) {*s++=c;if (s==buffer+l) {fwrite (buffer,1,l,stdout); S=buffer;}} void Print (int x) {static int stack[20],top;if (x<0) Putchar ('-'), X=-x;if (x==0) Putchar (' 0 '), while (x) stack[++top]=x %10,x/=10;while (top) Putchar (stack[top--]+ ' 0 ');} ~ostream () {fwrite (buffer,1,s-buffer,stdout);}} Os;struct Frac{int A, B; Frac () {}frac (Long long _,long long __=1) {int gcd=__gcd (_,__); A=_/gcd;b=__/gcd;if (b<0) a=-a,b=-b;} Friend istream& operator >> (IStream &_,frac &x) {double a;scanf ("%lf", &a); X=frac ((Long Long) (A * 100+ (A<0?-eps:eps)); return _;} Friend Frac operator + (const Frac &x,const Frac &y) {int gcd=__gcd (x.b,y.b), lcm=x.b/gcd*y.b; Frac re (Long Long) x.a* (lcm/x.b) + (Long Long) y.a* (lcm/y.b), LCM); return re;} Friend Frac operator-(const FRAC &x,const FRAC &y) {int gcd=__gcd (x.b,y.b), lcm=x.b/gcd*y.b; Frac re (Long Long) x.a* (lcm/x.b)-(Long Long) y.a* (lcm/y.b), LCM); return re;} Friend Frac operator/(const Frac &x,int y) {Frac re (x.a,x.b*y); return re;} Friend ostream& operator << (ostream &_,const Frac &x) {if (x.b==1) OS. Print (X.A); Elseos. Print (X.A), OS. Putchar ('/'), OS. Print (x.b); return _;}; int n;struct Abcd{int STA; Frac val;friend istream& operator >> (IStream &_,abcd &a) {int i;static char s[30];scanf ("%s", s+1); for ( i=1;i<=n;i++) (a.sta<<=1) |= (s[i]== ' + '? 1:0); Cin>>a.val;return _;} BOOL operator < (const ABCD &a) Const{return sta > A.sta;}} a[1<<20];//I am really the day my family that Meng Da's poi = =void divide_and_conquer (ABCD a[],int n) {int i;if (n==1) return; ABCD *l=a,*r=a+ (n &GT;&GT;1); for (i=0;i<n>>1;i++) {Frac x=l[i].val,y=r[i].val;l[i].val= (x-y)/2;r[i].val= (x+y)/2;} Divide_and_conquer (l,n>>1);D Ivide_and_conquer (r,n>>1); ABCD C=a[n>>1];for (i=n>>1;i;i--) A [i]=a[i-1];a[0]=C;} int main () {int i,j;cin>>n;for (i=0;i<1<<n;i++) cin>>a[i];sort (a,a+ (1<<n));D Ivide_and_ Conquer (A,1<<n); for (i=0;i<1<<n;i++) {if (!A[I].VAL.A) continue;cout<<a[i].val;if (i) OS. Putchar ("); for (j=1;j<=n;j++) if (a[i].sta& (1&LT;&LT;N-J)) OS. Putchar (' x '), OS. Print (j); Os.putchar (' \ n ');} return 0;}


Bzoj 3614 Heoi2014 Logical Translation Division = =heoi2014 Full AC reached?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.