Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define sc( x ) scanf( "%d" , &x )
- #define REP( i , n ) for( int i = 0 ; i < n ; i++ )
- #define clr( t , val ) memset( t , val , sizeof(t) )
- #define all(v) v.begin() , v.end()
- #define pb push_back
- #define SZ( v ) ((int)(v).size())
- #define mp make_pair
- #define fi first
- #define se second
- #define test() cerr << "hola que hace ?\n";
- #define DEBUG( x ) cerr << #x << "=" << x << endl;
- #define DEBUG2( x , y ) cerr << #x << "=" << x << " " << #y << "=" << y << endl;
- #define N 160
- #define EPS 1e-8
- typedef long long ll;
- typedef pair< int , int > pii;
- typedef vector< int > vi;
- typedef long double ld;
- typedef vector< ld> poly;
- const ld PI = acos( (ld)(-1.0) );
- poly prod( poly A , poly B ){
- int nA = A.size() , nB = B.size() , nV = nA + nB;
- poly V( nV );
- REP( i , nA ) REP( j , nB ) V[ i + j ] += A[ i ] * B[ j ];
- return V;
- }
- poly Integral( poly P ){
- int nP = P.size();
- poly V( nP + 1 );
- REP( i , nP ) V[ i + 1 ] = P[ i ]/( i + 1 );
- return V;
- }
- ld eval( poly &P , ld x ){
- int nP = P.size();
- ld ans = 0;
- for( int i = nP - 1 ; i >= 0 ;--i )
- ans = ans * x + P[ i ];
- return ans;
- }
- ld f( ld A , ld B , ld dx , ld slices ){
- if( A > B ) swap( A , B );
- if( abs( A - B ) < EPS ){
- ld t = sin( (PI * 2.0) / slices );
- return (t * A * A * dx * slices) / 6.0;
- }
- ld x = A * dx / (B - A);
- ld H = x + dx;
- ld t = sin( (PI * 2.0) / slices );
- ld S1 = t * B * B * H / 6.0;
- ld S2 = t * A * A * x / 6.0;
- return (S1 - S2) * slices;
- }
- int main(){
- int cases;
- cin >> cases;
- REP( tc , cases ){
- int n;
- cin >> n;
- poly p(n + 1);
- REP( i , n + 1 ) cin >> p[ i ];
- reverse( all( p ) );
- ld a , b;
- cin >> a >> b;
- int slices , stacks;
- cin >> slices >> stacks;
- poly q = Integral( prod( p , p ) );
- ld S = eval( q , b ) - eval( q , a );
- S *= PI;
- //DEBUG( S );
- ld R = 0;
- ld len = (b - a)/(ld)stacks;
- REP( i , stacks ){
- ld xa = a + len * i;
- ld xb = xa + len;
- R += f( eval( p , xa ) , eval( p , xb ) , len , (ld) slices );
- }
- //DEBUG2( S , R );
- ld ans = abs( S - R ) / S;
- ans *= 100;
- printf( "Case %d: %.4f\n" , tc + 1 , (double)ans );
- //DEBUG( ans );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement