Brute force --- ultraviolet A 10167: birthday cake

Source: Internet
Author: User
 
Problem G. birthday cake
  Problem's link: http://uva.onlinejudge.org/index.php? Option = com_onlinejudge & Itemid = 8 & page = show_problem & category = 13 & problem = 1108 & mosmsg = Submission + received + with + ID + 14413715

 

Mean: 

Http://luckycat.kshs.kh.edu.tw/homework/q10167.htm

Analyze:

Because the range of A and B is-500 ~ Between 500, so you can simply enumerate it.

Time Complexity:O (N * n * m)

 

Source code:

 

//  Memory   Time//  1347K     0MS//   by : Snarl_jsb//   2014-10-24-20.52#include<algorithm>#include<cstdio>#include<cstring>#include<cstdlib>#include<iostream>#include<vector>#include<queue>#include<stack>#include<map>#include<string>#include<climits>#include<cmath>#define N 1000010#define LL long longusing namespace std;struct node{    int x,y;};node p[110];int main(){    ios_base::sync_with_stdio(false);    cin.tie(0);//    freopen("C:\\Users\\ASUS\\Desktop\\cin.cpp","r",stdin);//    freopen("C:\\Users\\ASUS\\Desktop\\cout.cpp","w",stdout);    int n,i,j,k,x,y;    while(cin>>n,n)    {        n<<=1;        for(int i=0;i<n;++i)        {            cin>>x>>y;            p[i].x=x,p[i].y=y;        }        int cnt;        bool f=0;        for(i=-500;i<=500;++i)        {            for(j=-500;j<=500;++j)            {                cnt=0;                for(k=0;k<n;++k)                {                    if(p[k].x*i+p[k].y*j>0) cnt++;                    if(p[k].x*i+p[k].y*j==0) break;                }                if(cnt==n>>1&&k==n)                {                    cout<<i<<" "<<j<<endl;                    f=1;                    break;                }            }            if(f) break;        }    }    return 0;}

  

Brute force --- ultraviolet A 10167: birthday cake

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.