【模板库】二维凸包

参考例题:http://poj.org/problem?id=3348
备注:可以处理重点,坐标值可以是整数和小数

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define LL long long
using namespace std;

const int N = 100000;
const double EPS = 1e-8;

int n,cnt;

struct Point{
	double x,y;
	inline Point() {}
	inline Point(double a, double b):x(a),y(b) {}
	inline Point operator + (const Point &A) {return Point(x+A.x, y+A.y);}
	inline Point operator - (const Point &A) {return Point(x-A.x, y-A.y);}
	inline Point operator / (double A) {return Point(x/A, y/A);}
	inline Point operator * (double A) {return Point(x*A, y*A);}
	inline double operator * (const Point &A) {return x*A.x + y*A.y;}
	inline double operator ^ (const Point &A) {return x*A.y - A.x*y;}
	inline bool operator < (const Point &B) const {return x < B.x - EPS || (fabs(x-B.x) < EPS && y < B.y - EPS);}
	inline bool operator == (const Point &B) const {return fabs(x - B.x) + fabs(y - B.y) < EPS;}
}p[N],cvx[N]; 

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

inline void ConvexHull(int tot, Point *a, int &sz, Point *ret) {
	if (!tot) {sz = 0; return;}
	sort(a+1, a+1+tot); ret[sz=1] = a[1];
	tot = unique(a+1, a+1+tot) - a - 1;
	for (int i=2;i<=tot;i++) {
		while (sz > 1 && ((ret[sz] - ret[sz-1]) ^ (a[i] - ret[sz])) < EPS) sz--;
		ret[++sz] = a[i];	
	}
	for (int i=tot-1,mn=sz;i>0;i--) {
		while (sz > mn && ((ret[sz] - ret[sz-1]) ^ (a[i] - ret[sz])) < EPS) sz--;
		ret[++sz] = a[i];
	} 
	sz -= sz > 2;
} 

int main() {
	n = read();
	for (int i=1;i<=n;i++) p[i].x = read(), p[i].y = read();
	ConvexHull(n, p, cnt, cvx);
	double vout = 0; 
	for (int i=2;i<cnt;i++) 
		vout += (cvx[i] - cvx[1]) ^ (cvx[i+1] - cvx[1]) / 2;
	printf("%d\n",(int)(vout/50));
	return 0;
}

129 thoughts to “【模板库】二维凸包”

  1. Wow, wonderful blog structure! How long have you ever been blogging for?
    you make blogging look easy. The entire look of your website is fantastic, as neatly as the content!

  2. Good day! This post could not be written any better!
    Reading this post reminds me of my good old room mate! He always kept chatting about this.
    I will forward this article to him. Fairly certain he will have a
    good read. Many thanks for sharing!

  3. I have been surfing online greater than 3 hours as of late, yet I by no
    means found any interesting article like yours.
    It’s lovely value sufficient for me. In my opinion, if all site owners and bloggers made excellent content as you probably did,
    the web shall be much more useful than ever before.

  4. Normally I don’t learn post on blogs, however I wish to say that this write-up very compelled me to try and do it!
    Your writing taste has been amazed me. Thanks, quite nice post.

  5. Woah! I’m really enjoying the template/theme of this website.

    It’s simple, yet effective. A lot of times it’s challenging to get that “perfect balance” between superb usability and
    visual appearance. I must say you have done a superb job with this.
    Also, the blog loads super quick for me on Internet explorer.
    Outstanding Blog!

  6. I absolutely love your site.. Very nice colors & theme. Did you create this amazing site yourself?
    Please reply back as I’m looking to create my own website and
    would like to learn where you got this from or just what the theme is named.

    Cheers!

  7. Hey I am so thrilled I found your site, I really found
    you by error, while I was browsing on Digg for something
    else, Nonetheless I am here now and would just like
    to say kudos for a tremendous post and a all round entertaining blog (I
    also love the theme/design), I don’t have time to read it all
    at the moment but I have saved it and also included your RSS feeds, so when I have time I will be
    back to read a lot more, Please do keep up the
    awesome job.

  8. I think this is among the most significant information for me.
    And i’m glad reading your article. But want to remark
    on some general things, The website style is ideal,
    the articles is really excellent : D. Good job, cheers

  9. We’re a gaggle of volunteers and opening a new scheme in our community.
    Your website provided us with helpful info to work on.
    You’ve performed a formidable task and our entire group will likely
    be thankful to you.

  10. Hello, Neat post. There is a problem along with your web site in web explorer, might check this? IE nonetheless is the marketplace leader and a big component of other people will miss your excellent writing because of this problem.

  11. We stumbled over here by a different web page and thought I may as well check things out. I like what I see so now i’m following you. Look forward to going over your web page for a second time.

  12. I’m impressed, I have to admit. Seldom do I come across a blog that’s equally educative and amusing, and without a doubt, you have hit the nail on the head. The problem is something not enough folks are speaking intelligently about. I’m very happy that I came across this in my hunt for something relating to this.

  13. Excellent blog! Do you have any tips and hints for aspiring writers?
    I’m hoping to start my own blog soon but I’m a little lost on everything.
    Would you suggest starting with a free platform like WordPress
    or go for a paid option? There are so many choices out
    there that I’m totally confused .. Any recommendations?
    Thanks!

  14. Good post. I learn something new and challenging on blogs I stumbleupon everyday.

    It’s always exciting to read articles from other authors and use something from their web sites.

  15. Its like you read my mind! You appear to know a lot about this, like you wrote the book in it
    or something. I think that you could do with some pics to drive the message home
    a bit, but other than that, this is magnificent blog.
    A fantastic read. I will certainly be back.

  16. Heya i am for the primary time here. I found this
    board and I to find It really helpful & it helped me out
    a lot. I hope to offer one thing again and aid others such as
    you helped me.

  17. Pretty nice post. I simply stumbled upon your weblog and
    wanted to mention that I have truly loved browsing your blog
    posts. After all I’ll be subscribing in your feed and I hope you write
    again soon!

  18. I’m extremely impressed with your writing skills as well
    as with the layout on your weblog. Is this a paid theme or did you customize it
    yourself? Either way keep up the nice quality writing, it is rare to see a
    great blog like this one nowadays.

  19. We’re a group of volunteers and opening a new scheme in our community.
    Your web site offered us with valuable information to work on. You’ve done a formidable
    activity and our entire group will likely be grateful to
    you.

  20. Thanks for ones marvelous posting! I quite enjoyed reading it, you happen to be a great author.I
    will be sure to bookmark your blog and will eventually come
    back in the foreseeable future. I want to encourage you
    to definitely continue your great work, have a nice
    holiday weekend!

  21. Have you ever thought about including a little bit
    more than just your articles? I mean, what you say is valuable and everything.
    Nevertheless imagine if you added some great graphics
    or video clips to give your posts more, “pop”! Your content is
    excellent but with images and videos, this blog
    could definitely be one of the very best in its niche.
    Awesome blog!

  22. I think that what you posted made a ton of sense. However,
    what about this? what if you added a little information? I
    am not saying your information is not solid,
    but what if you added something that grabbed people’s attention? I mean 【模板库】二维凸包
    – Qizy's Database is a little boring.
    You ought to look at Yahoo’s front page and see how they write
    post titles to get viewers interested. You might add a related video
    or a related pic or two to grab people excited about what
    you’ve written. Just my opinion, it might make your posts a little bit more interesting.

  23. I have been exploring for a bit for any high-quality articles or
    blog posts on this sort of area . Exploring in Yahoo I at last stumbled upon this website.
    Reading this info So i’m satisfied to express that I have an incredibly
    just right uncanny feeling I found out just what I needed.

    I most no doubt will make sure to don?t overlook this site and provides it a look regularly.

  24. I seriously love your site.. Very nice colors & theme.

    Did you develop this site yourself? Please reply back as I’m wanting
    to create my own site and want to know where you got this from or exactly what the theme is called.
    Thanks!

  25. Today, I went to the beach front with my kids. I found a
    sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.”
    She put the shell to her ear and screamed. There was a hermit crab inside and
    it pinched her ear. She never wants to go back!
    LoL I know this is completely off topic but I had to tell someone!

  26. We absolutely love your blog and find a lot of your post’s to be
    just what I’m looking for. Does one offer guest writers
    to write content to suit your needs? I wouldn’t mind publishing a post or elaborating on a few of the subjects you write regarding here.
    Again, awesome web log!

  27. Greetings I am so grateful I found your website, I really found you by
    error, while I was looking on Google for something else, Regardless I
    am here now and would just like to say thank you for a remarkable post and a all round entertaining blog
    (I also love the theme/design), I don’t have time to browse it all
    at the moment but I have saved it and also added your
    RSS feeds, so when I have time I will be back to read a lot more, Please do keep up the excellent b.

  28. Woah! I’m really enjoying the template/theme of this blog. It’s simple, yet effective.
    A lot of times it’s very difficult to get that “perfect balance” between superb usability and visual appearance.
    I must say that you’ve done a excellent job with this.
    In addition, the blog loads super fast for me on Chrome.
    Superb Blog!

  29. great publish, very informative. I’m wondering why the opposite specialists of this sector do not notice this.
    You must proceed your writing. I’m confident, you have a great readers’ base already!

  30. I loved as much as you will receive carried out right here.
    The sketch is attractive, your authored subject matter stylish.
    nonetheless, you command get got an impatience over that you wish be delivering the following.
    unwell unquestionably come more formerly again since exactly the same nearly a lot often inside case
    you shield this hike.

  31. Its like you read my mind! You seem to know so much about this,
    like you wrote the book in it or something. I think that you can do with a few pics
    to drive the message home a little bit, but instead of that,
    this is fantastic blog. A fantastic read. I’ll definitely be back.

  32. Hey there, I think your site might be having browser compatibility issues.
    When I look at your blog site in Firefox, it looks fine but when opening in Internet Explorer, it has some overlapping.
    I just wanted to give you a quick heads up! Other then that, very good
    blog!

  33. Your style is very unique compared to other
    people I’ve read stuff from. Thanks for posting when you have the
    opportunity, Guess I will just book mark this page.

  34. I’m really impressed with your writing skills and also with the layout
    on your weblog. Is this a paid theme or did you modify it yourself?
    Anyway keep up the excellent quality writing, it is rare to
    see a great blog like this one today.

  35. An outstanding share! I’ve just forwarded this onto a coworker who has been doing a
    little homework on this. And he actually bought me lunch simply because I stumbled upon it for him…
    lol. So let me reword this…. Thanks for the meal!! But yeah, thanx for spending time
    to discuss this issue here on your internet site.

  36. Wonderful site. Plenty of useful info here. I’m sending it to a few buddies ans also sharing in delicious.
    And certainly, thanks for your sweat!

  37. We stumbled over here coming from a different website and thought I might
    check things out. I like what I see so now i’m following you.
    Look forward to finding out about your web page for a second time.

  38. Thanks for your marvelous posting! I quite enjoyed reading it,
    you might be a great author.I will always bookmark your blog and may come back very
    soon. I want to encourage you to continue your great work, have a nice afternoon!

  39. Hey there just wanted to give you a quick heads up and let you know a few of the pictures aren’t loading correctly.
    I’m not sure why but I think its a linking issue.
    I’ve tried it in two different internet browsers and both show the
    same results.

  40. Good day! This post couldn’t be written any better! Reading through this post reminds me of my previous room mate! He always kept talking about this. I will forward this write-up to him. Fairly certain he will have a good read. Thank you for sharing!

  41. Do you mind if I quote a couple of your posts as long as I provide
    credit and sources back to your site? My blog is in the exact same niche as yours and my visitors
    would genuinely benefit from some of the information you present here.

    Please let me know if this ok with you. Thank you!

  42. We’re a group of volunteers and opening a new scheme in our community.
    Your website offered us with valuable information to work on. You have done a formidable job
    and our whole community will be thankful
    to you.

  43. Wonderful beat ! I wish to apprentice while you amend your website, how could i subscribe
    for a blog site? The account aided me a acceptable deal.
    I had been tiny bit acquainted of this your broadcast provided bright clear concept

  44. Definitely consider that that you stated. Your favorite
    reason seemed to be at the net the simplest thing to consider of.

    I say to you, I certainly get irked at the same time as other people consider concerns
    that they just do not recognize about. You managed to hit the nail upon the top and also defined out the entire thing
    with no need side effect , folks could take a
    signal. Will likely be back to get more. Thanks

  45. It is appropriate time to make some plans for the future and it’s time to
    be happy. I’ve read this post and if I could I want to suggest
    you some interesting things or advice. Perhaps you can write next articles referring to this article.
    I desire to read even more things about it!

  46. Unquestionably believe that that you said. Your favourite reason seemed to
    be at the net the simplest thing to take into accout of. I say to you, I certainly get irked whilst other people think about
    concerns that they just do not know about. You controlled to hit the nail upon the highest as smartly as defined out the entire thing without having side
    effect , other people can take a signal. Will likely
    be back to get more. Thanks

  47. My friend is a raincoat, even if I ca n’t think of it on a sunny day, the rainy season will accompany you; my lover is a thick cloth, even if it is not beautiful, it can cover the wind and cold; my parents are old jackets, although they are not fashionable, even stupid, but they are the warmest and warmest .

  48. Someone essentially lend a hand to make critically posts
    I might state. That is the very first time I frequented your website page
    and up to now? I surprised with the analysis you made to create this particular put up extraordinary.
    Wonderful process!

  49. What other people think of you and how you say it is their business, it has nothing to do with you, how you live, how you live, and it has nothing to do with them, be yourself.

  50. I want to be with you, even if it is a headless and tailless farce, I will persist until the moment the world fades after you leave the stage, hold a small lamp and stand in the memory waiting for you.

  51. There is a kind of love that obviously wants to give up, but can’t give up; there is a kind of love, knowing that it is suffering, but can’t hold back; Can’t take it back already.

  52. It’s truly a nice and helpful piece of information. I am happy that you simply shared this helpful info with us. Please keep us informed like this. Thank you for sharing.

Leave a Reply

Your email address will not be published. Required fields are marked *