`
从此醉
  • 浏览: 1044455 次
  • 性别: Icon_minigender_1
  • 来自: US
社区版块
存档分类
最新评论

uva 10167 - Birthday Cake

阅读更多

点击打开链接


题目意思:给定一个半径为100的蛋糕,蛋糕上面有许多的樱桃,现在要求一次性平均分蛋糕,并且对应的樱桃的数量要相等。要求这个均分的直线AX+BY = 0的A 和 B的一个解


解题思路:题目规定半径的值,还有A B 的范围,我们知道一条直线能够将点平均分成两半 ,点不会落在直线上,那么我们知道对于点带入直线如果值大于0则点在直线上方,反之在下方。

只要慢足上方的点等于下方的点并且所以点不会落在直线上就可以,三重循环(暴力枚举)。


代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

struct Point{
    int x;
    int y;
};
Point p[110];
int n , cnt1 , cnt2;

void solve(){
    int i , j;
    for(i = -500 ; i <= 500 ; i++){
        for(j = -500 ; j <= 500 ; j++){
            cnt1 = 0; cnt2 = 0;
            for(int k = 0 ; k < 2*n ; k++){
                if((i*p[k].x + j*p[k].y) < 0)
                    cnt1++;
                if((i*p[k].x + j*p[k].y) > 0)
                    cnt2++;
            }
            if(cnt1  == cnt2){
                printf("%d %d\n" , i , j);
                return;
            }
        }
    }
}

int main(){
   int i;
   while(scanf("%d" , &n) &&n){
       for(i = 0 ; i < 2*n ; i++)
           scanf("%d %d" , &p[i].x , &p[i].y);
       solve();
   }
   return 0;
}
 




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics