Brute Force --- UVA 10167: Birthday Cake

简介:  Problem G. Birthday Cake    Problem's Link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=13&...

 

 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

analyse:

 由于A,B的范围在-500~500之间,所以直接枚举就可以了。

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 long
using 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;
}

  

目录
相关文章
|
6天前
Strange fuction(HDU--2899)
Strange fuction(HDU--2899)
|
人工智能
P8969 幻梦 | Dream with Dynamic
P8969 幻梦 | Dream with Dynamic
146 0
LeetCode 202. Happy Number
一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 1,也可能是无限循环但始终变不到 1。如果可以变为 1,那么这个数就是快乐数。
90 0
LeetCode 202. Happy Number
|
人工智能
Practical Skill Test——AT
题目描述 We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is Ai,j.
80 0
ZOJ - Problem Set - 3960 What Kind of Friends Are You?
ZOJ - Problem Set - 3960 What Kind of Friends Are You?
64 0
ZOJ - Problem Set - 3960 What Kind of Friends Are You?
HDOJ 1096 A+B for Input-Output Practice (VIII)
HDOJ 1096 A+B for Input-Output Practice (VIII)
78 0
|
机器学习/深度学习
LeetCode之Happy Number
LeetCode之Happy Number
123 0
|
机器学习/深度学习 人工智能 BI
[LeetCode] Happy Number
Well, no matter whether the number is happy or not, its sum-of-squared-digits sequance has a cycle. Well, do you still remember the algorithm for dete...
870 0