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>
#include<math.h>
int dx[105];
int dy[105];
int main()
{
	int n,m,a,b,i,j,k;
	while(scanf("%d",&n),n)
	{
		memset(dx,0,sizeof(dx));
		memset(dy,0,sizeof(dy));
		for(i=1; i<=2*n; i++)
		{
			scanf("%d%d",&dx[i],&dy[i]);
		}
		int flag = 0;
		int flag1 = 0;
		for(i=-500; i<=500; i++)
		{
			for(j=-500; j<=500; j++)
			{
				if(i==0&&j==0)
					continue;
				int ans1 = 0;
				int ans2 = 0;
				flag1 = 0;
				for(k=1; k<=2*n; k++)
				{
					if(i*dx[k]+j*dy[k] == 0)
					{
						flag1 = 1;
						break;
					}
					else if(i*dx[k]+j*dy[k] > 0)
					{
						ans1++;
					}
					else if(i*dx[k]+j*dy[k]<0)
					{
						ans2++;
					}
				}
				if((ans1 == ans2)&&(flag1==0))
				{
					flag = 1;
					printf("%d %d\n",i,j);
					break;
				}
			}
			if(flag)
				break;
		}
	}
} 

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-28 04:11:03

uva 10167 Birthday Cake(暴力枚举)的相关文章

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

[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 565 - Pizza Anyone?(暴力枚举 + 二进制)

题目:uva 565 - Pizza Anyone?(暴力枚举 + 二进制) 题目大意:题目是说有一个人要帮他的朋友们定批萨,然后每个朋友都有自己的口味要求,问能不能定一个批萨然后满足每个朋友的至少一个要求. 能就输出所定批萨里面加的东西,,输出要求按字典序: 不能就输出:No pizza can satisfy these requests. 解题思路:这题里面有16种材料,每种材料只有取与不取的可能,这样就有 2^16 种( 0 - 2^16 - 1),枚举出每种情况然后在分别看是否能满足每

uva 725 Division(暴力枚举)

uva 725  Division Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that the first number divided by the second is equal to an integer N, where . That is, abcde / fghij =

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

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 11210 Chinese Mahjong(暴力枚举)

uva 11210 Chinese Mahjong Mahjong () is a game of Chinese origin usually played by four persons with tiles resembling dominoes and bearing various designs, which are drawn and discarded until one player wins with a hand of four combinations of three

UVa 10603 Fill [暴力枚举、路径搜索]

10603 Fill There are three jugs with a volume of a, b and c liters. (a, b, and c are positive integers not greater than 200). The rst and the second jug are initially empty, while the third is completely lled with water. It is allowed to pour water f

UVA 725 division【暴力枚举】

[题意]:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果.如果没有找到则输出“There are no solutions for N.”.这里2<=n<=79. [分析]: 1.因为n>=2,且abcde=fghij×n,满足abcde>fghij.若a=0,则fghij的最小值为12345,abcde<fghij,矛盾.所以a≠0. 2.因为a≠0,所以12345<=abcde&l