whu 1473 - Check the Identity 乱搞

乱搞.

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<algorithm>

#include<cmath>

#include<stack>

using namespace std;



const double Pi = acos(-1);

const double eps = 1e-8;

char str[310][10];

int n, m;

int sign(double x){

    return x<-eps?-1:(x>eps);

}

stack<double> Q;

double work( double x ){

    while( !Q.empty() ) Q.pop();

    Q.push(x);

    for(int i = 0; i < n; i++){

        switch( str[i][0] ){

            case 's':{

                double t = Q.top();Q.pop();//if( sign(t-Pi/2) == 0 ) return 1; 

                Q.push( sin(t) ); break;}

            case 'c':{

                double t = Q.top();Q.pop();//if( sign(t-Pi/2) == 0 ) return 1; 

                Q.push( cos(t) ); break;}

            case 't':{

                double t = Q.top();Q.pop();//if( sign(t-Pi/2) == 0 ) return 1;  

                Q.push( tan(t) ); break;}

            case '+':{

                double a = Q.top();Q.pop();//if( sign(a-Pi/2) == 0 ) return 1; 

                double b = Q.top();Q.pop();//if( sign(b-Pi/2) == 0 ) return 1; 

                Q.push(b+a); break; }

            case '-':{

                double a = Q.top();Q.pop();//if( sign(a-Pi/2) == 0 ) return 1; 

                double b = Q.top();Q.pop();//if( sign(b-Pi/2) == 0 ) return 1; 

                Q.push(b-a); break; }

            case '*':{

                double a = Q.top();Q.pop();//if( sign(a-Pi/2) == 0 ) return 1; 

                double b = Q.top();Q.pop();//if( sign(b-Pi/2) == 0 ) return 1; 

                Q.push(b*a); break; }

            default:

                Q.push(x);

        }    

    }

    return Q.top();

}

int main(){

    int T;

    scanf("%d",&T);

    for(int Case = 1; Case <= T; Case++){

        scanf("%d", &n);

        bool flag = false;

        for(int i = 0; i < n; i++){

            scanf("%s", str[i] );

            if( str[i][0] == '-' ) flag = true;

        }

        printf("Case %d: ", Case );

    //    if( flag == false ){ puts("No"); continue; } //不存在减法则必定不会为0 

        int num = 0;

        for(int i = 0; i < 100; i++){

            double x = (rand()%100)/100.*Pi/2.;   //此处很神奇,模1000必WA 

            if( sign( work(x) ) == 0 ) num++;

        }    

        if( sign( 1.*num/100. - 0.8 ) >= 0 ) puts("Yes");

        else    puts("No");

    }

    return 0;    

}

 

你可能感兴趣的:(entity)