Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 转成 double 的时候丢失了精度？

Posted by 00448247 at 2009-03-25 23:33:11 on Problem 1654
In Reply To:我用的也是经典的求面积的方法，可是怎么会错呢 还请高人指点一二 Posted by:bingbing at 2009-02-15 10:22:14
```> #include <iostream>
> #include <cmath>
>
> using namespace std ;
>
> struct Point
> {
>     __int64 x ;
>     __int64 y ;
> };
>
> char step ;
> Point next ;
> __int64 area ;
>
> void solve()
> {
>     Point tmp = next ;
>
>     switch(step)
>     {
>     case'1': next.x += -1 ; next.y += -1 ; break ;
>     case'2': next.y += -1 ; break ;
>     case'3': next.x += 1 ; next.y += -1 ; break ;
>     case'4': next.x += -1 ; break ;
>     case'6': next.x += 1 ; break ;
>     case'7': next.x += -1 ; next.y += 1 ; break ;
>     case'8': next.y += 1 ; break ;
>     case'9': next.x += 1 ; next.y += 1 ; break ;
>     }
>
>     area += tmp.x*next.y-next.x*tmp.y ;
>
> }
>
> int main()
> {
>     int n ;
>
>     cin >> n ;
>
>     while( n-- )
>     {
>         next.x = next.y = 0 ;
>         area = 0 ;
>         while( cin >> step )
>         {
>             if(step=='5')
>             {
>                 break ;
>             }
>             solve() ;
>         }
>         cout << abs(area/2.0) << endl ;
>     }
>     return 0 ;
> }
```

Followed by: