【codechef】Lighthouses

https://www.codechef.com/problems/LIGHTHSE

好好的一道分类讨论题被我想复杂了。。。。。。。。。。。。。

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
typedef struct {
  int x;
  int y;
  int i;
} coord;

int main(void)
{
  int t;
  scanf("%d",&t);
  while (t--) {
      int n;
      scanf("%d",&n);
      int i;
      coord c;
      coord wn, ws, en, es, nw, ne, sw, se;
      scanf("%d %d",&c.x,&c.y); c.i = 1;
      wn = ws = en = es = nw = ne = sw = se = c;
      for (i = 2; i <= n; i++) {
        scanf("%d %d",&c.x,&c.y); c.i = i;
        if (c.x <= wn.x) {
          if (c.x == wn.x) {
            if (c.y > wn.y) wn = c;
            else if (c.y < ws.y) ws = c;
          } else
            wn = ws = c;
        }
        if (c.x >= en.x) {
          if (c.x == en.x) {
            if (c.y > en.y) en = c;
            else if (c.y < es.y) es = c;
          } else
            en = es = c;
        }
        if (c.y >= nw.y) {
          if (c.y == nw.y) {
            if (c.x > ne.x) ne = c;
            else if (c.x < nw.x) nw = c;
          } else
            nw = ne = c;
        }
        if (c.y <= sw.y) {
          if (c.y == sw.y) {
            if (c.x > se.x) se = c;
            else if (c.x < sw.x) sw = c;
          } else
            sw = se = c;
        }
      } // for
      
      // check for one lighthouse solution
      if (wn.i == nw.i) {
        printf("1\n%d SE\n",wn.i);
        continue;
      }
      if (ws.i == sw.i) {
        printf("1\n%d NE\n",ws.i);
        continue;
      }
      if (en.i == ne.i) {
        printf("1\n%d SW\n",en.i);
        continue;
      }
      if (es.i == se.i) {
        printf("1\n%d NW\n",es.i);
        continue;
      }
      // two lighthouse solution
      if (wn.y > en.y) printf("2\n%d SE\n%d NW\n",wn.i,en.i);
      else printf("2\n%d NE\n%d SW\n",wn.i,en.i);
    }
  return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值