"Codeforces 350C" bombs

Source: Internet
Author: User

"Link" I am the link, point me:)
Test instructions

Exercises


The bombs found on the x-axis and the y-axis can be eliminated with fewer operands.
The other points will find that the operands are the same.
Then remove the points on the X, Y axis first.
Other points.
We prefer to move along the horizontal axis to the same position as it.
Then change the y-coordinate to match the target bomb.
And you'll find out.
If x is the same, the absolute value of y should be sorted in ascending order of the Y coordinate.
Otherwise, there may be a situation where another bomb is encountered during the walk.
Sort a wave + greedy just fine.

Code

#include <bits/stdc++.h> #define REP1 (I,A,B) for (int i = a;i <= b;i++) #define REP2 (I,A,B) for (int i = A;i >= b;i--) using namespace std;const int N = 1e5;struct abc{int x, y;}; int N,CNT;ABC A[n+10];bool CMP1 (ABC a,abc b) {return a.y<b.y;} BOOL CMP2 (ABC A,abc b) {return a.x<b.x;}    BOOL Cmp3 (ABC A,abc b) {if (a.x!=b.x) return a.x<b.x;        else {if (a.y<0 && b.y<0) {return a.y>b.y;    }else return a.y<b.y;    }}int Main () {scanf ("%d", &n);        REP1 (i,1,n) {scanf ("%d%d", &a[i].x,&a[i].y);    if (a[i].x==0 | | a[i].y==0) cnt++;    } printf ("%d\n", cnt*4+ (n-cnt) *6);    Sort from bottom to top.    Sort (A+1,A+1+N,CMP1);                REP1 (I,1,n) if (a[i].x==0) {if (a[i].y>0) {printf ("1%d u\n", a[i].y);                Puts ("2");                printf ("1%d d\n", a[i].y);            Puts ("3"); }} REP2 (i,n,1) if (a[i].x==0) {if (a[i].y<0) {               printf ("1%d d\n",-a[i].y);                Puts ("2");                printf ("1%d u\n",-a[i].y);            Puts ("3");    }}//Sort (A+1,A+1+N,CMP2) from left to right;                REP1 (I,1,n) if (a[i].y==0) {if (a[i].x>0) {printf ("1%d r\n", a[i].x);                Puts ("2");                printf ("1%d l\n", a[i].x);            Puts ("3");                }} REP2 (i,n,1) if (a[i].y==0) {if (a[i].x<0) {printf ("1%d l\n",-a[i].x);                Puts ("2");                printf ("1%d r\n",-a[i].x);            Puts ("3");    }} sort (A+1,a+1+n,cmp3); REP1 (I,1,n) if (a[i].x!=0 && a[i].y!=0) {printf ("1%d", ABS (a[i].x)), if (a[i].x<0) puts ("L");            Else puts ("R");            printf ("1%d", ABS (A[I].Y)), if (a[i].y<0) puts ("D"), Else puts ("U");            Puts ("2"); printf ("1%d", ABS (A[I].Y)), if (a[i].y<0) puts ("U"), Else puts ("D");            printf ("1%d", ABS (a[i].x)), if (a[i].x<0) puts ("R"), Else puts ("L");        Puts ("3"); } return 0;}

"Codeforces 350C" bombs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.