Thứ Hai, 22 tháng 4, 2019

Tính diện tích một đa giác dùng định thức và xác định tính cùng chiều đồng hồ của các đỉnh

#include<bits/stdc++.h>
#define mp make_pair
#define ll long long
using namespace std;
long double determind(ll x1,ll y1,ll x2, ll y2){
   long double res=(x1*y2)-(x2*y1);
   return res;
}
typedef pair<ll,ll> pi;
pi luu[110];
int main(){
  ll n,i,x,y;
  cin>>n;
  long double res=0;
  for(i=1;i<=n;i++){
     cin>>x>>y;
     luu[i]=mp(x,y);
  }
  luu[n+1]=luu[1];
  for(i=1;i<=n;i++) res+=determind(luu[i].first,luu[i].second,luu[i+1].first,luu[i+1].second);
  if(res>=0){
    cout<<"CCW"<<' ';
    cout<<fixed<<setprecision(1)<<res/2;}
    else {
      cout<<"CW"<<' ';
    cout<<fixed<<setprecision(1)<<-res/2;
    }
    return 0;
}

Không có nhận xét nào:

Đăng nhận xét