Chapaev and Potatoes (URAL 1809 violence)

Source: Internet
Author: User

Chapaev and potatoes
Time Limit: 500MS Memory Limit: 65536KB 64bit IO Format: %i64d &%i64u

Submit Status

Description

Anka and Petka were waiting for Chapaev and eating potatoes. Soon They were full and decided to play the ' Chapaev ' game using the remaining four potatoes. Petka took a 20x20 board, put the potatoes on it, and declared the following rules. No potatoes could lie on the same square, and a player could shoot at a potato and knock it off the board with another Potato If the potatoes were in the same vertical or horizontal line and there were no other potatoes between them. Anka suggested to take some potatoes and put them on unoccupied squares of the board so, each potato could is used to Shoot at exactly one another potato. Help Petka does this by changing the positions of as few potatoes as possible.

Input

The four input lines contain the coordinates x I, y Iof the potatoes. The coordinates is integers in the range from 1 to 20. No. Potatoes is on the same square.

Output

Output the new coordinates of the potatoes. The potatoes must is described in the same order as in the input. If There is several answers, output any of them.

Sample Input

input Output
1 12 24) 44 3
1 22 24) 44 3

Source

problem Author:Dmitry Ivankov
problem Source:NEERC, Eastern Subregional contest


Test instructions: Four potatoes on the 20*20 square, tell the starting position, ask to change the location of certain potatoes so that only one potato per potato with him in the same row or column, the number of changes required to be as small as possible.

Code:

#include <iostream> #include <functional> #include <cstdio> #include <cstring> #include < algorithm> #include <cmath> #include <string> #include <map> #include <stack> #include < vector> #include <set> #include <queue> #pragma comment (linker, "/stack:102400000,102400000") #define Pi  ACOs ( -1.0) #define EPS 1e-6#define lson rt<<1,l,mid#define rson rt<<1|1,mid+1,r#define FRE (i,a,b) for (i = A; I <= b;  i++) #define FREE (i,a,b) for (i = A, I >= b; i--) #define FRL (i,a,b) for (i = A; I < b; i++) #define FRLL (i,a,b) for (i = A i > B; i--) #define MEM (T, v) memset ((t), V, sizeof (t)) #define SF (n) scanf ("%d", &n) #define SFF (A, b) scanf ("%d%d         ", &a, &b) #define SFFF (a,b,c) scanf ("%d%d%d ", &a, &b, &c) #define PF Printf#define DBG PF ("hi\n") typedef long long ll;using namespace std; #define INF 0x3f3f3f3f#define mod 1000000009const int maxn = 1005;co NST int MAXN = 2005;const int MAXM = 200010;const int N = 1005;struct node{int x, y;}    Node[5];bool vis[25][25];int a[5];bool flag;bool isOK () {memset (a,0,sizeof (a));            for (int i=0;i<4;i++) {for (int j=0;j<4;j++) {if (i==j) continue; if (node[i].x==node[j].x| |        NODE[I].Y==NODE[J].Y) a[i]++;    }} for (int i=0;i<4;i++) if (a[i]!=1) return false; return true;}    void dfs (int step,int sum) {if (flag) return;            if (step==sum) {if (isOK ()) {flag=true;        for (int i=0;i<4;i++) printf ("%d%d\n", node[i].x,node[i].y);    } return;        } for (int k=0;k<4;k++) {int x=node[k].x;        int y=node[k].y; for (int i=1;i<=20;i++) {for (int j=1;j<=20;j++) {if (Vis[i][j]) Conti                Nue                Vis[x][y]=false;                Vis[i][j]=true;               Node[k].x=i;node[k].y=j; DFS (step+1,sum);                Vis[x][y]=true;                Vis[i][j]=false;            Node[k].x=x;node[k].y=y; }}} return;}    int main () {#ifndef Online_judge freopen ("C:/users/lyf/desktop/in.txt", "R", stdin), #endif int i,j;        while (~SCANF ("%d%d", &node[0].x,&node[0].y)) {memset (vis,false,sizeof (VIS));            for (i=1;i<4;i++) {scanf ("%d%d", &node[i].x,&node[i].y);        Vis[node[i].x][node[i].y]=true;        } Flag=false;            for (i=0;i<3;i++) {if (flag) break;        DFS (0,i); }} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Chapaev and Potatoes (URAL 1809 violence)

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.