`
hellobin
  • 浏览: 65499 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

UVA 10167 - Birthday Cake

    博客分类:
  • UVA
 
阅读更多

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

 

总结问题:
1 产生a,b 用两个for,没用随机数,导致WA
2 没有用while 和n=0的判断,WA
3 数组开的太小了,WA
 
 
#define RUN
#ifdef RUN

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <cctype> 
#include <algorithm>
#include <utility>
#include <math.h>
#include <ctime>

using namespace std;

#define MAXN 110

int input[MAXN][2];
int n;

void printout(){
	cout << "2*n:" << 2*n << endl;
	for(int i=0; i<2*n; i++){
		printf("%d %d\n", input[i][0], input[i][1]);
	}
}


void play(){
	
	int pos=0, neg=0;

	while(true){
		int a = -500 + (rand()%1001);
		int b = -500 + (rand()%1001);

		pos = 0;
		neg = 0;
		for(int k=0; k<2*n; k++){
			int sign = a*input[k][0] + b*input[k][1];
			if(sign > 0){
				pos++;
			}
			else if(sign < 0){
				neg++;
			}

			if(pos>=n && neg>=n){
				printf("%d %d\n", a, b);
				return;
			}
		}
	}
}


int main(){

#ifndef ONLINE_JUDGE
	freopen("10167.in", "r", stdin);
	freopen("10167.out", "w", stdout);
#endif

	srand ( time(NULL) );
	while(scanf("%d",&n)==1 && n!=0){
		memset(input, 0, sizeof(input));
		for(int i=0; i<2*n; i++){
			scanf("%d%d", &input[i][0], &input[i][1]);
		}
		play();
		//printout();
	}
	
	return 0;
}


#endif


分享到:
评论

相关推荐

    UVaOJ-401(Palindromes).zip_401 Palindromes

    标题中的"UVaOJ-401(Palindromes)"表明这是一个关于解决UVa Online Judge(UVa OJ)上编号为401的编程挑战,该挑战的主题是"Palindromes",即回文串。回文串是指一个字符串无论从前读到后还是从后读到前都是相同的,...

    Uva 1510 - Neon Sign

    ### Uva 1510 - Neon Sign #### 问题背景与描述 在题目“Uva 1510 - Neon Sign”中,我们面对的是一个霓虹灯招牌设计问题。该霓虹灯招牌由一系列位于圆周上的角点组成,并通过发光管连接这些角点。发光管有两种...

    uva705-Slash-Maze-.rar_Slash_uva705

    【标题】"uva705-Slash-Maze-.rar_Slash_uva705" 指向的是一个在UVa Online Judge (UVa OJ) 上提交并通过的编程问题,具体为问题编号705,名为"Slash Maze"。这个压缩包很可能包含了该问题的解决方案源代码。 ...

    UVA100~200---52道题accept代码,均顺利accept过

    这些文件名代表的是在UVA(University of Virginia)在线判题系统上解决的编程题目,主要是C++语言编写的解决方案。UVA是一个知名的在线编程竞赛平台,它提供了大量的算法问题供程序员挑战,有助于提高编程技能和...

    开源项目-codingsince1985-UVa#uva-online-judge-solutions-in-golang.zip

    开源项目-codingsince1985-UVa#uva-online-judge-solutions-in-golang.zip,两年来每天都在解决一个uva在线裁判问题,算起来…

    UVA133-TheDoleQueue.zip_site:www.pudn.com_uva133

    《UVA133 - 救济金发放问题:The Dole Queue》 在计算机科学领域,算法是解决问题的关键工具,特别是在处理复杂数据结构和优化问题时。UVA(University of Virginia)在线判题系统提供了丰富的算法题目供程序员挑战...

    Algorithm-UVA-Solutions-in-Python.zip

    "Algorithm-UVA-Solutions-in-Python.zip"这个压缩包文件正是针对UVA竞赛中问题的Python 3解决方案集合。 Python作为一门易学且功能强大的编程语言,因其简洁的语法和丰富的库支持,成为了许多算法爱好者和开发者的...

    uva532-Dungeon-Master.rar_dungeon

    《UVA532 Dungeon Master:解密游戏编程的深度探索》 在计算机科学与编程领域,UVA(University of Virginia)在线判题系统是一个深受程序员喜爱的平台,它提供了丰富的算法题目供学习者挑战。其中,编号为532的...

    tpcw-nyu-uva-client 客户端

    "tpcw-nyu-uva-client 客户端"是一个专为TPCW(Transaction Processing Performance Council Workloads)设计的应用程序,由纽约大学(NYU)和弗吉尼亚大学(UVA)共同开发。这个客户端软件主要用于模拟和评估数据库...

Global site tag (gtag.js) - Google Analytics