zoukankan      html  css  js  c++  java
  • uva10167 Birthday Cake

    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 mustn't in
    [500;500]. Cherries are not allowed lying on the beeline. For each dataset there is at least one solution.
    Input
    The input le contains several scenarios. Each of them consists of 2 parts:
    The rst 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 le
    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

    题目大意如下:平面直角坐标系中有一个以(0,0)为圆心,半径为100个单位长度的圆,圆内有一些点,求一条直线正好把所有点分成数量相等的两半,且没有点在直线上。

    思路:枚举,外加一点初中知识。

    来源:virtual judge

    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<iostream>
    using namespace std;
    int n,chy[101][2];
    bool judge(int A,int B)
    {
    	int cnt[2]={0,0};
    	for(int i=1;i<=(n<<1);i++){
    		int tmp=A*chy[i][0]+B*chy[i][1];
    		if(!tmp)
    			return false;
    		cnt[tmp<0]++;
    	}
    	return cnt[0]==n&&cnt[1]==n;//保证两边确实都有n个cherries,没有任何一个cherry在直线上;
    }
    void solve()
    {
    	for(int i=-100;i<=100;i++)//圆的半径仅为100个单位长度;
    		for(int j=-100;j<=100;j++){
    			if(!j)continue;
    			if(judge(i,j)){
    				printf("%d %d
    ",i,j);
    				return;
    			}
    		}
    }
    int main()
    {
    	while(scanf("%d",&n)&&n){
    		for(int i=1;i<=(n<<1);i++)
    			scanf("%d%d",&chy[i][0],&chy[i][1]);
    		solve();
    	}
    	return 0;
    }
    /*
    Sample input
    2
    -20 20
    -30 20
    -10 -50
    10 -5
    0
    Sample output
    0 1
    */



  • 相关阅读:
    如何度过每天的最初十分钟
    微软正在拿命做一场豪赌
    .htaccess用法与设置超详细讲解+大全
    互联网+情趣用品:羞答答的玫瑰静悄悄地开
    男人雄辩 女人聊天
    苹果手表会一直美下去
    移动应用大行其道:你的企业准备好了吗?
    微商的下一步会怎么走?
    阿里京东腾讯58的O2O格局,创业者的夹缝生存之道
    苹果首席设计师艾维:Apple Watch不是奢侈品
  • 原文地址:https://www.cnblogs.com/keshuqi/p/5957727.html
Copyright © 2011-2022 走看看