Birthday Cake UVA 10167

#include <stdio.h>
#define MAXN 100+5

int main(){
  int x[MAXN],y[MAXN];
  int i,n;
  int A,B;
  int P,N,sign;
  //freopen("data","r",stdin);
  while(scanf("%d",&n)&&n){
   for(i=0;i<2*n;i++)
     scanf("%d%d",&x[i],&y[i]);

   sign=0;

   for(A=-500;A<=500;A++){
     for(B=-500;B<=500;B++){
       P=N=0;
       for(i=0;i<2*n;i++){
        if(A*x[i]+B*y[i]==0)//樱桃在分界线上舍去
          break;
	else if(A*x[i]+B*y[i]<0)//根据表达式求出结果的正负,即可判断位于分界线的哪一侧
	  N++;
	else
	  P++;

	if(N>n||P>n)
	  break;
       }
       if(N==n&&P==n) break;
     }
     if(N==n&&P==n) break;
   }

   printf("%d %d\n",A,B);
  }

  return 0;
}

时间: 2024-10-09 06:17:46

Birthday Cake UVA 10167的相关文章

[UVA] 10167 - Birthday Cake

 Problem G. Birthday Cake  Background Lucy and Lily are twins. Today is their birthday. Mother buys a birthday cake for them.Now we put the cake onto a Descartes coordinate. Its center is at (0,0), and the cake's length of radius is 100. There are 2N

uva 10167 Birthday Cake(暴力/枚举)

uva 10167 Birthday Cake Background Lucy and Lily are twins. Today is their birthday. Mother buys a birthday cake for them.Now we put the cake onto a Descartes coordinate. Its center is at (0,0), and the cake's length of radius is 100. There are 2N (N

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=1108&mosmsg=Submission+received+with+ID+14413715 Mean: http://luckycat.kshs.kh.edu.tw/

UVA - 10167 - Birthday Cake (简单枚举)

思路:简单枚举 AC代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> using namespace std; int x[105], y[105]; int main() { int A, B, N; while(scanf("%d", &N), N) { for(int

uva 10167 Birthday Cake(暴力枚举)

....还不是完全自己独立做出来的题目,虽然很暴力,好像是范围为[-500,500],但是题上为什mustn't in呢,我还白痴的用点到直线的距离求个数,判断是在直线上还是下应该直接带入就ok了!!!看是大于0还是小于0,不过通过这个我又知道了点到直线距离公式,之前给忘了,d = abs(Ax+By+c)/sqrt(A*A+B*B) 贴代码了: #include<stdio.h> #include<string.h> #include<stdlib.h> #inclu

UVa 10167 生日蛋糕

题意:有一个半径为100的圆形蛋糕,蛋糕上有一些樱桃.现在妈妈要把蛋糕分两半,因为要均分给两人,所以肯定是从原点切出来的.然后还需要两半蛋糕各含一半数目的樱桃,而且所切的地方不会切到樱桃.求所切下的这条直线的方程,Ax+By=0 中的 A 和 B 的值. cherry 樱桃:beeline 直线:coordinate 坐标 思路:可以看到大体的思路就是找到一条直线,使得所有樱桃的坐标满足 Ax+By>0 和 <0 的个数各一半,而且没有等于0的.而且很容易看到应该不止一条直线,甚至对同一条直线

UVA 10831 - Gerg&#39;s Cake(数论)

UVA 10831 - Gerg's Cake 题目链接 题意:说白了就是给定a, p,问有没有存在x^2 % p = a的解 思路:求出勒让德标记,判断如果大于等于0,就是有解,小于0无解 代码: #include <stdio.h> #include <string.h> long long a, p; long long pow_mod(long long x, long long k, long long mod) { long long ans = 1; while (k

uva 10831 - Gerg&#39;s Cake(勒让德记号)

题目链接:uva 10831 - Gerg's Cake 题目大意:给定a和p,p为素数,问说是否存在x,使得x2≡a%p 解题思路:勒让德记号,判断ap?12≡1%p #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; ll pow_mod (ll a, ll n, ll mod) { ll ans = 1; while

uva 10831 - Gerg&amp;#39;s Cake(勒让德符号)

题目链接:uva 10831 - Gerg's Cake 题目大意:给定a和p.p为素数,问说是否存在x,使得x2≡a%p 解题思路:勒让德记号,推断ap?12≡1%p #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; ll pow_mod (ll a, ll n, ll mod) { ll ans = 1; while