UVA10167 Birthday Cake【暴力】

2024-04-08 19:38
文章标签 暴力 birthday cake uva10167

本文主要是介绍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 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

问题链接:UVA10167 Birthday Cake
问题简述
    给定2N 个点,求A和B为多少时,直线Ax+By=0 把点分成相等的两部分。
问题分析
    本题可以用暴力法来解决。把点带入直线方程Ax+By=0,那么大于0的是一边,小于0的是另外一边,枚举A和B,统计一下就可以。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++程序如下:

/* UVA10167 Birthday Cake */#include <iostream>using namespace std;const int LEFT = -500, RIGHT = 500;
const int N = 50;
int x[N * 2], y[N * 2];int main()
{int n;while(~scanf("%d", &n) && n) {n *= 2;for(int i = 0; i < n; i++)scanf("%d%d", &x[i], &y[i]);bool flag = true;for(int a = LEFT; a <= RIGHT && flag; a++)for(int b = LEFT; b <= RIGHT ; b++) {if(a==0 && b==0 ) continue;int i, cnt = 0;     // 统计满足AX+BY>0的点数目for(i = 0; i < n; i++) {if(a * x[i] + b * y[i] > 0) ++cnt;else if(a * x[i] + b * y[i] == 0) break;}if( i < n) continue;if(cnt == n / 2) {printf("%d %d\n", a, b);flag = false;break;}}}return 0;
}

这篇关于UVA10167 Birthday Cake【暴力】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/886333

相关文章

CF629D Babaei and Birthday Cake

题意:给出N个半径,和高的圆柱,要求后面的体积比前面大的可以堆在前一个的上面,求最大的体积和。 dp[i]=max(dp[j])+v[i](j<i&&v[i]>v[j]); 离散化,线段树维护区间最大值 import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import

计蒜客 Half-consecutive Numbers 暴力打表找规律

The numbers 11, 33, 66, 1010, 1515, 2121, 2828, 3636, 4545 and t_i=\frac{1}{2}i(i+1)t​i​​=​2​​1​​i(i+1), are called half-consecutive. For given NN, find the smallest rr which is no smaller than NN

10125-Sumsets【暴力】

利用n^2的时间枚举所有a[i] + a[j] 利用n^2的时间枚举所有a[i] - a[j] 之后利用n^2时间一个一个找a[i] - a[j]的值是否存在于a[i] + a[j]中 找的时候需要二分查找 另外一点就是注意long long的范围以及四个数是集合内不同的四个元素 15222638 10125 Sumsets Accepted C++ 0.449 2015-03-

10730-Antiarithmetic?【暴力枚举】

水题 求一个序列是否存在3个数按顺序构成等差数列 直接枚举等差数列的差值 时间复杂度降到 n * n / 3 开pos数组记录每个值得为之 楷vis数组记录目前i是否出现过 强行AC 15221397 10730 Antiarithmetic? Accepted C++ 0.035 2015-03-26 12:09:56 #include<cstdio>#include

HLJUOJ1125(暴力三点一线)

两点确定一条直线 Time Limit: 1 Sec   Memory Limit: 128 MB Submit: 19   Solved: 11 [ Submit][ Status][ Web Board] Description  给一个15000 * 15000 的区域, 坐标都是整数. 其中有N个点,N <= 770.问总共有多少个3点共线的组合.并按升序(点的ID)输出

HLJUOJ1117(暴力模拟)

八数码 Time Limit: 1 Sec   Memory Limit: 128 MB Submit: 109   Solved: 19 [ Submit][ Status][ Web Board] Description 给定一个8数码的初始状态,然后给出一系列对8数码的操作,求其最终状态. Input 第一行t,代表样例个数。 每组数据前三行各三个数,代表八数

CF Bayan 2015 Contest Warm Up B.(dfs+暴力)

B. Strongly Connected City time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output 题目链接: http://codeforces.com/contest/475/probl

UVA10010(八方向暴力枚举)

Where's Waldorf? Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu 题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18656 Description Where's Waldo

CF #278 (Div. 2) B.(暴力枚举+推导公式+数学构造)

B. Candy Boxes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output 题目链接: http://codeforces.com/contest/488/problem/B There

CF#278 (Div. 2) A.(暴力枚举)

A. Giga Tower time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output 题目链接: http://codeforces.com/contest/488/problem/A Giga To