UvaOJ 10167

暴力搜索

 1 #include<cstdio>
 2
 3 struct node
 4 {
 5     int x;
 6     int y;
 7 }s[10000];
 8 int main()
 9 {
10     //freopen("input.txt","r",stdin);
11     int a,b,n,num;
12     int i;
13     bool flag;
14     while(scanf("%d",&n) && n)
15     {
16         for(i = 0; i < 2 * n; i++)
17             scanf("%d%d",&s[i].x,&s[i].y);
18         flag = 0;
19         for(a = -500 ; a <= 500; a++)
20         {
21             for(b = -500; b <= 500; b++)
22             {
23                 num = 0;
24                 if(a == 0 && b == 0) continue;
25                 for(i = 0; i < 2 * n; i++)
26                 {
27                     if(a * s[i].x + b * s[i].y > 0) num++;
28                     if(a * s[i].x + b * s[i].y == 0) break;
29                 }
30                 if(i == 2 * n && num == n)
31                 {
32                     flag = 1;
33                     break;
34                 }
35             }
36             if(flag) break;
37         }
38         printf("%d %d\n",a,b);
39     }
40
41     return 0;
42 }

UvaOJ 10167

时间: 2024-10-12 04:41:57

UvaOJ 10167的相关文章

(Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinejudge.org 西班牙Valladolid大学的程序在线评测系统,是历史最悠久.最著名的OJ. 二.<算法竞赛入门经典> 刘汝佳  (UVaOJ  351道题)  以下部分内容摘自:http://sdkdacm.5d6d.com/thread-6-1-1.html “AOAPC I”是刘汝佳(大

UVAoj 348 - Optimal Array Multiplication Sequence

1 /* 2 题意:矩阵相乘的最少的步数 3 dp[i][j]=min(dp[i][j], dp[i][k]+dp[k+1][j]+num[i-1]*num[k]*num[j]); 4 表示的是第i个矩阵到第j个矩阵相乘的最少步数 5 sign[i][j]表示的是第i个矩阵到第j个矩阵相乘的最少步数是由第i个矩阵到第sign[i][j]个矩阵相乘最少步数 6 和第sign[i][j]+1个矩阵到第j个矩阵相乘最少步数的得到的最小值! 7 */ 8 #include<iostream> 9 #i

[UVA] 10167 - Birthday Cake

 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

Uvaoj 10048 - Audiophobia(Floyd算法变形)

1 /* 2 题目大意: 3 从一个点到达另一个点有多条路径,求这多条路经中最大噪音值的最小值! . 4 5 思路:最多有100个点,然后又是多次查询,想都不用想,Floyd算法走起! 6 */ 7 #include<iostream> 8 #include<cstring> 9 #include<cstdio> 10 #define INF 0x3f3f3f3f 11 using namespace std; 12 13 int map[105][105]; 14 1

uvaoj 10397 - Connect the Campus【最小生成树】

uvaoj 10397 - Connect the Campus Many new buildings are under construction on the campus of the University of Waterloo. The university has hired bricklayers, electricians, plumbers, and a computer programmer. A computer programmer? Yes, you have been

UVaOJ 694 - The Collatz Sequence

题目很简单,但是一开始却得到了Time Limit的结果,让人感到很诧异.仔细阅读发现,题目中有一个说明: Neither of these, A or L, is larger than 2,147,483,647 (the largest value that can be stored in a 32-bit signed integer). 所以应该是A溢出造成了程序“死循环”,最终导致超时. -----------------------------------------------

【原创】UVAOJ水题10025解题报告

首先是原题,转自UVAOJ  The ? 1 ? 2 ? ... ? n = k problem  The problem Given the following formula, one can set operators '+' or '-' instead of each '?', in order to obtain a given k? 1 ? 2 ? ... ? n = k For example: to obtain k = 12 , the expression to be us

uva 10167 Birthday Cake(暴力/枚举)

uva 10167 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

UvaOJ 10010 Where&#39;s Waldorf?

Given a m by n grid of letters, ( ), and a list of words, find the location in the grid at which the word can be found. A word matches a straight, uninterrupted line of letters in the grid. A word can match the letters in the grid regardless of case