zoukankan      html  css  js  c++  java
  • Uva 10167

     

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

     

    随机:

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<string>
    #include<algorithm>
    using namespace std;
    const int N=100;
    int x[N];
    int y[N];
    
    int n;
    
    void solve()
    {
            while(1)
            {
                    int A,B;
                    A=rand()%1001-500;
                    B=rand()%1001-500;
    
                    int small=0;
                    int big=0;
                    for(int i=0;i<2*n;i++)
                    {
                            int v=A*x[i]+B*y[i];
                            if(v>0)
                                    big++;
                            else if(v<0)
                                    small++;
                            else
                                    break;
                    }
                    //printf("%d %d
    ", small, big);
                    if(small==n && big==n)
                    {
                            cout<<A<<" "<<B<<endl;
                            return;
                    }
    
            }
    }
    
    int main()
    {
            srand(time(0));
            while(cin>>n&&n)
            {
                    for(int i=0;i<2*n;i++)
                    {
                            cin>>x[i]>>y[i];
                    }
                    solve();
            }
    
        return 0;
    }

     

    暴力:

    void solve()
    {
            for(int A=-500;A<=500;A++)
            {
                    for(int B=-500;B<=500;B++)
                    {
                            int small=0;
                            int big=0;
                            for(int i=0;i<2*n;i++)
                            {
                                    int v=A*x[i]+B*y[i];
                                    if(v>0)
                                            big++;
                                    else if(v<0)
                                            small++;
                                    else
                                            break;
                            }
                            //printf("%d %d
    ", small, big);
                            if(small==n && big==n)
                            {
                                    cout<<A<<" "<<B<<endl;
                                    return;
                            }
                    }
            }
    }
  • 相关阅读:
    c语言结构体数组引用
    c语言结构体数组定义的三种方式
    如何为SAP WebIDE开发扩展(Extension),并部署到SAP云平台上
    SAP SRM ABAP Webdynpro和CFCA usb key集成的一个原型开发
    使用SAP API portal进行SAP SuccessFactors的API测试
    SAP UI5应用里的页面路由处理
    在SAP WebIDE Database Explorer里操作hdi实例
    如何使用SAP事务码SAT进行UI应用的性能分析
    使用SAP WebIDE进行SAP Cloud Platform Business Application开发
    SAP CRM WebClient UI ON_NEW_FOCUS的用途
  • 原文地址:https://www.cnblogs.com/cute/p/3688386.html
Copyright © 2011-2022 走看看