POJ 3119 Friends or Enemies?

先预处理得到各个编号的点的位置再判断 点在二元一次方程的上方还是下方

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <malloc.h>
#include <ctype.h>
#include <math.h>
#include <string>
#include<iostream>
#include <algorithm>
using namespace std;
#define MAXN 11111
#include <queue>
#include <vector>
struct node
{
    int x, y;
}q[66666];
void work(int a,int b)
{
    int ans=0;
    int x=130,y=130,lon=1;
    while(ans<=65555)
    {
        for(int i=0; i<lon; i++)//zuo
        {
            if((x-130)*a+b==y-130)
            {
                x--;
                continue;
            }
            q[ans].x=x--;
            q[ans++].y=y;
            //          printf("%d\n",cost[y][x+1]);
        }
        for(int i=0; i<lon; i++)//shang
        {
            if((x-130)*a+b==y-130)
            {
                y++;
                continue;
            }
            q[ans].x=x;
            q[ans++].y=y++;
            //          printf("%d\n",cost[y-1][x]);
        }
        lon++;
        for(int i=0; i<lon; i++)//you
        {
            if((x-130)*a+b==y-130)
            {
                x++;
                continue;
            }
            q[ans].x=x++;
            q[ans++].y=y;
            //      printf("%d\n",cost[y][x-1]);
        }
        for(int i=0; i<lon; i++)//xia
        {
            if((x-130)*a+b==y-130)
            {
                y--;
                continue;
            }
            q[ans].x=x;
            q[ans++].y=y--;
            //     printf("%d\n",cost[y+1][x]);
        }
        lon++;
    }
}
int main()
{
    int a,b,k,t,cas=1;
  //  freopen("in.txt","r",stdin);
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&a,&b);
        work(a,b);
        for(int i=0;i<=65555;i++)
            q[i].x-=130,q[i].y-=130;
        scanf("%d",&k);
        printf("Caso %d\n",cas++);
        for(int i=0; i<k; i++)
        {
            int sum1=0,c,d;
            scanf("%d%d",&c,&d);
            if(q[c].x*a+b>q[c].y&&q[d].x*a+b>q[d].y)
                sum1=1;
            else if(q[c].x*a+b<q[c].y&&q[d].x*a+b<q[d].y)
                sum1=1;
            else sum1=0;
            if(sum1)
                printf("Mesmo lado da fronteira\n");
            else printf("Lados opostos da fronteira\n");
        }

    }
    return 0;
}

POJ 3119 Friends or Enemies?,布布扣,bubuko.com

时间: 2024-08-06 16:05:19

POJ 3119 Friends or Enemies?的相关文章

poj 3117 Friends or Enemies?(模拟)

题目链接:http://poj.org/problem?id=3119 Friends or Enemies? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 431   Accepted: 177 Description A determined army on a certain border decided to enumerate the coordinates in its patrol in a way to

POJ 2312 Battle City(优先队列+BFS)

题目链接:http://poj.org/problem?id=2312 Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7085   Accepted: 2390 Description Many of us had played the game "Battle city" in our childhood, and some people (like me) even often pl

poj 2312 Battle City

题目连接 http://poj.org/problem?id=1840 Battle City Description Many of us had played the game "Battle city" in our childhood, and some people (like me) even often play it on computer now. What we are discussing is a simple edition of this game. Giv

POJ 题目2312 Battle City(BFS)

Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7208   Accepted: 2427 Description Many of us had played the game "Battle city" in our childhood, and some people (like me) even often play it on computer now. What we are d

poj 2438 Children&#39;s Dining

http://poj.org/problem?id=2438 题意: 有2*N个人要坐在一张圆桌上吃饭,有的人之间存在敌对关系,安排一个座位次序,使得敌对的人不相邻. 假设每个人最多有N-1个敌人.如果没有输出"No solution!". 如果i和j可以相邻,之间连一条边 每个人最多有N-1个敌人,所以每个人至少会连出去N+1条边 根据狄拉克定理,图一定是哈密顿图 所以本题不存在无解的情况 然后输出一条哈密顿回路就好了 有关哈密顿图与哈密顿回路的问题 参见文章 http://www.

POJ - 3186 Treats for the Cows (区间DP)

题目链接:http://poj.org/problem?id=3186 题意:给定一组序列,取n次,每次可以取序列最前面的数或最后面的数,第n次出来就乘n,然后求和的最大值. 题解:用dp[i][j]表示i~j区间和的最大值,然后根据这个状态可以从删前和删后转移过来,推出状态转移方程: dp[i][j]=max(dp[i+1][j]+value[i]*k,dp[i][j-1]+value[j]*k) 1 #include <iostream> 2 #include <algorithm&

POJ 2533 - Longest Ordered Subsequence(最长上升子序列) 题解

此文为博主原创题解,转载时请通知博主,并把原文链接放在正文醒目位置. 题目链接:http://poj.org/problem?id=2533 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1, ai2, ..., aiK)

POJ——T2271 Guardian of Decency

http://poj.org/problem?id=2771 Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5932   Accepted: 2463 Description Frank N. Stein is a very conservative high-school teacher. He wants to take some of his students on an excursion, but he is

POJ——T2446 Chessboard

http://poj.org/problem?id=2446 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18560   Accepted: 5857 Description Alice and Bob often play games on chessboard. One day, Alice draws a board with size M * N. She wants Bob to use a lot of c