Ultraviolet A Problem Solution: 10089-repackaging

Source: Internet
Author: User

 

First, convert each package P = (S1, S2, S3) to a vector (S2-S1, S3-S1 ). all the packages forms convex hull. if point (0, 0) is in this convex hull, then there will be a solution, otherwise not. I can not tell the proof of this now, if you have any ideas, please let me know.

 

In fact, point (0, 0) is not in this convex hull if and only if all the vectors fall into a sector whose angle is less than Pi. this is obviusly correct. so we can use this point to get our answer.

 

BTW, you must care about data overflow. I 've got AC after lots of was just by change date type from int to long.

 

/*************************************** ********************************** <Br/> * copyright (c) 2008 by Liu kaipeng * <br/> * liukaipeng at gmail dot com * <br/> ******************** **************************************** * **************/<br/>/* @ judge_id 00000 10089 C ++ "repackaging" */<br/> # include <algorithm> <br/> # include <cstdio> <br/> # include <cstring> <br/> # include <deque> <br/> # include <Fstream> <br/> # include <iostream> <br/> # include <list> <br/> # include <map> <br/> # include <queue> <br/> # include <set> <br/> # include <stack> <br/> # include <string> <br/> # include <vector> <br/> using namespace STD; </P> <p> typedef long llint; <br/> llint const maxn = 1001; <br/> bool repackage (llint pkgs [] [3], llint npkgs) <br/> {<br/> for (llint I = 0; I <npkgs; ++ I) {<br/> pkgs [I] [0]-= pkgs [I] [2]; <br/> pkgs [I] [1]-= pkgs [I] [2]; <br/>}</P> <p> llint X1 = pkgs [0] [0], Y1 = pkgs [0] [1], x2 = pkgs [0] [0], y2 = pkgs [0] [1]; <br/> for (llint I = 1; I <npkgs; ++ I) {<br/> llint x = pkgs [I] [0], y = pkgs [I] [1]; <br/> llint a1 = Y1 * X, b1 = x1 * y, a2 = Y2 * X, b2 = x2 * Y; <br/> If (a1 = b1) <br/> If (x1 * x + Y1 * Y <= 0) return true; <br/> else continue; <br/> If (A2 = b2) <br/> If (X2 * x + Y2 * Y <= 0) return true; <br/> else continue; <br/> If (A1 <B1) x1 = x, Y1 = y; <br/> If (A2> B2) x2 = x, y2 = y; <br/> If (x1 = X2 & Y1 = Y2) return true; <br/> If (Y1 * X2 = Y2 * X1) <br/> If (x1 * X2 + Y1 * Y2 <= 0) return true; <br/> else continue; <br/> If (Y1 * X2 <Y2 * X1) return true; <br/>}< br/> return false; <br/>}</P> <p> int main (INT argc, char * argv []) <br/>{< br/> # ifndef onl Ine_judge <br/> freopen (string (argv [0]) + ". in "). c_str (), "r", stdin); <br/> freopen (string (argv [0]) + ". out "). c_str (), "W", stdout); <br/> # endif <br/> llint pkgs [maxn] [3]; <br/> for (llint npkgs; cin> npkgs & npkgs! = 0;) {<br/> for (llint I = 0; I <npkgs; ++ I) <br/> CIN> pkgs [I] [0]> pkgs [I] [1]> pkgs [I] [2]; <br/> If (repackage (pkgs, npkgs) <br/> cout <"Yes/N "; <br/> else <br/> cout <"No/N"; <br/>}< br/> return 0; <br/>}< br/>

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.