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 i = 0; i < 2 * N; i++) {
			scanf("%d %d", &x[i], &y[i]);
		}

		int flag = 0;
		for(A = -500; A <= 500 && !flag; A++) {
			for(B = -500; B <= 500 && !flag; B++) {
				if(A || B) {
					int c1 = 0, c2 = 0;
					for(int i = 0; i < 2 * N; i++) {
						if(x[i] * A + y[i] * B > 0) c1 ++;
						else if(x[i] * A + y[i] * B < 0) c2 ++;
						if(c1 == c2 && c1 == N) {
							printf("%d %d\n", A, B);
							flag = 1;
						}
					}
				}
			}
		}
	}
	return 0;
}
时间: 2024-08-02 06:54:45

UVA - 10167 - Birthday Cake (简单枚举)的相关文章

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 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

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 10976 Fractions Again?! 简单枚举题

#include<stdio.h> struct pairs{ int x,y; }; struct pairs pairs[10000]; int judge(int k,int i){ if((k*i)%(i-k)==0) return 1; else return 0; } int main(){ int k,count; while(scanf("%d",&k)!=EOF){ count=0; for(int i=k+1;i<=2*k;i++){ if

uva 10976 Fractions Again(简单枚举)

10976 Fractions Again It is easy to see that for every fraction in the form 1 k (k > 0), we can always find two positive integers x and y, x ≥ y, such that: 1 k = 1 x + 1 y Now our question is: can you write a program that counts how many such pairs

UVa 725 Division --- 简单枚举

题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=666 /* UVa 725 Division --- 简单枚举 */ #include <cstdio> #include <cstring> bool used[10]; /* 判断传进来的两个数是否满足条件 */ bool judge(int a, i

简单除法(简单枚举优化)

#include<iostream> #include<algorithm> using namespace std; void panduan(int s,int k) { int n,m;bool l=1; n=s;m=k; int i,sn=0,a[20],j; for(i=0;n!=0;i++) { a[i]=n%10; n=n/10; } for(;m!=0;i++) { a[i]=m%10; m=m/10; } i--; sort(a,a+i); if(i==8) {a

uva 1560 - Extended Lights Out(枚举 | 高斯消元)

题目链接:uva 1560 - Extended Lights Out 题目大意:给定一个5?6的矩阵,每个位置上有一个灯和开关,初始矩阵表示灯的亮暗情况,如果按了这个位置的开关,将会导致周围包括自己位置的灯状态变换,求一个按开关位置,保证所有灯都灭掉. 解题思路: 枚举,枚举第一行的状态,然后递推出后面四行的状态. 高斯消元,对于每个位置对定变量,这样列出30个方程求解. C++ 枚举 #include <cstdio> #include <cstring> #include &