首页 > 其他分享 >UVa 10167 Birthday Cake (枚举)

UVa 10167 Birthday Cake (枚举)

时间:2023-04-12 11:36:49浏览次数:57  
标签:them 10167 two int flag Birthday each UVa line


10167 - Birthday Cake

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=107&page=show_problem&problem=1108

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 is a integer, 1<=N<=50) cherries on the cake. Mother wants to cut the cake into two halves with a knife (of course a beeline). The twins would like to be treated fairly, that means, the shape of the two halves must be the same (that means the beeline must go through the center of the cake) , and each half must have N cherrie(s). Can you help her?

Note: the coordinate of a cherry (x , y) are two integers. You must give the line as form two integers A,B(stands for Ax+By=0), each number in the range [-500,500]. Cherries are not allowed lying on the beeline. For each dataset there is at least one solution.

Input


The input file contains several scenarios. Each of them consists of 2 parts: The first part consists of a line with a number N, the second part consists of 2N lines, each line has two number, meaning (x,y) .There is only one space between two border numbers. The input file is ended with N=0.

Output


For each scenario, print a line containing two numbers A and B. There should be a space between them. If there are many solutions, you can only print one of them.

Sample Input


2
-20 20
-30 20
-10 -50
10 -5
0


Sample Output

0 1



枚举A,B即可。


完整代码:

/*0.015s*/

#include <cstdio>
const int maxn = 30;///不需要500那么大,30足矣

int chx[101], chy[101];

int main()
{
	int n, cnt, a, b, i;
	bool flag;
	while (scanf("%d", &n), n)
	{
		for (i = 0; i < n * 2; ++i)
			scanf("%d%d", &chx[i], &chy[i]);
		flag = false;
		for (a = -maxn; a <= maxn; ++a)
		{
			for (b = -maxn; b <= maxn; ++b)
			{
				cnt = 0;
				for (i = 0; i < n * 2; ++i)
				{
					if (chx[i] * a + chy[i] * b == 0)
					{
						cnt = 0;
						break;
					}
					else if (chx[i] * a + chy[i] * b > 0) ++cnt;
				}
				if (cnt == n)
				{
					printf("%d %d\n", a, b);
					flag = true;
					break;
				}
			}
			if (flag) break;
		}
	}
	return 0;
}




标签:them,10167,two,int,flag,Birthday,each,UVa,line
From: https://blog.51cto.com/u_5535544/6185334

相关文章

  • UVa 129 Krypton Factor (回溯好题)
    129-KryptonFactorTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=65YouhavebeenemployedbytheorganisersofaSuperKryptonFactorContestinwhichcontestantshaveveryhighmental......
  • UVa 11210 Chinese Mahjong (模拟&枚举&回溯)
    11210-ChineseMahjongTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2151Mahjong()isagameofChineseoriginusuallyplayedbyfourpersonswithtilesresemblingdominoesandbearing......
  • UVa 11375 Matches (DP&高精度)
    11375-MatchesTimelimit:2.000secondshttp://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2370Wecanmakedigitswithmatchesasshownbelow:Given N matches,findthenumberofdifferentnumbersrepresentableusing......
  • UVa 11507 Bender B. Rodríguez Problem (模拟&异或)
    11507-BenderB.RodríguezProblemTimelimit:4.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2502Benderisarobotbuiltby Mom'sFriendlyRobotCompany atits......
  • UVa 443 / POJ 2247 Humble Numbers (4因子-丑数&STL灵活运用)
    443-HumbleNumbersTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=384http://poj.org/problem?id=2247Anumberwhoseonlyprimefactorsare2,3,5or7isc......
  • UVa 10673 Play with Floor and Ceil (数论)
    10673-PlaywithFloorandCeilTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=1614TheoremForanytwointegers x and k thereexiststwomoreintegers p ......
  • UVa 10004 Bicoloring (DFS&二分图)
    10004-BicoloringTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=945In1976the``FourColorMapTheorem"wasprovenwiththeassistanceofacomput......
  • UVa 143 Orchard Trees (数学&计算几何&枚举)
    143-OrchardTreesTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=79AnOrchardisthasplantedanorchardinarectanglewithtreesuniformlyspacedinbothdirections.T......
  • Semi-prime H-numbers UVA - 11105
     所有形如4n+1(n为非负整数)的数叫H数。定义1是唯一的单位H数,H素数是指本身不是1,且不能写成两个不是1的H数的乘积。H-半素数是指能写成两个H素数的乘积的H数(这两个数可以相同也可以不同)。 例如,25是H-半素数,但125不是。输入一个H数h(h≤1000001),输出1~h之间有多少个H-半素数。......
  • Zeros and Ones UVA - 12063
      给出n、k(n≤64,k≤100),有多少个n位(无前导0)二进制数的1和0一样多,且值为k的倍数?  f[i][j][k] #include<iostream>#include<cstring>#include<cmath>#include<algorithm>usingnamespacestd;#definelllonglongintn,m;llf[102][102][102];vo......