Hoj 2183 Extrusion

Source: Internet
Author: User

The core of this question is to find the area of any polygon. We can use cross product to calculate. Take any one point and take two adjacent points clockwise to form two vectors with this point for cross product. All cross-border products obtained in a clockwise week are divided by two, that is, the area of the polygon. [Cpp] # include <iostream> # include <stdio. h> # include <stdlib. h> # include <string. h> # include <math. h ># include <vector> using namespace std; struct Point {double x; double y ;}; Point p [100000]; double cross (Point O, Point A, Point B) {return (. x-O. x) * (B. y-O. y)-(B. x-O. x) * (. y-O. y);} int main () {# ifndef ONLINE_JUDGE freopen ("in.txt", "r", stdin); # endif int n; double vol; while (scanf ("% D", & n )! = EOF & n> = 3) {p [0]. x = p [0]. y = 0; for (int I = 1; I <= n; I ++) {scanf ("% lf", & p [I]. x, & p [I]. y);} scanf ("% lf", & vol); p [n + 1]. x = p [1]. x; p [n + 1]. y = p [1]. y; double area = 0; for (int I = 1; I <= n; I ++) {area + = cross (p [0], p [I], p [I + 1]);} area =-area; area/= 2; double len; len = vol/area; printf ("BAR LENGTH: %. 2lf \ n ", len );}}

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.