Chapaev and Potatoes (URAL 1809 暴力)
来源:互联网 发布:淘宝联盟淘客贷款 编辑:程序博客网 时间:2024/06/05 18:54
Chapaev and Potatoes
Time Limit: 500MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u
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 20 × 20 board, put the potatoes on it, and declared the following rules. No two potatoes could lie on the same square, and a player could shoot at a potato and knock it off the board with another potato only 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 that each potato could be used to shoot at exactly one another potato. Help Petka do this by changing the positions of as few potatoes as possible.
Input
The four input lines contain the coordinates xi, yi of the potatoes. The coordinates are integers in the range from 1 to 20. No two potatoes are on the same square.
Output
Output the new coordinates of the potatoes. The potatoes must be described in the same order as in the input. If there are several answers, output any of them.
Sample Input
1 12 24 44 3
1 22 24 44 3
Source
Problem Author: Dmitry Ivankov
Problem Source: NEERC 2010, Eastern subregional contest
Problem Source: NEERC 2010, Eastern subregional contest
题意:四个土豆在20*20的方格上,告诉起始位置,要求改变某些土豆的位置使得每个土豆只有一个土豆与他在同一行或同一列,要求改变的次数尽量小。
代码:
#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;const 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]) continue; 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;}
1 0
- Chapaev and Potatoes (URAL 1809 暴力)
- ural 1809 Chapaev and Potatoes
- sgu238:Uncle Vasya and Bags for Potatoes(暴力)
- URAL 1200 - Horns and Hoofs(暴力+剪枝)
- URAL 2019 Pair: normal and paranormal 暴力?
- URAL 1011|Conductors|暴力
- URAL 1083|Factorials!!!|暴力
- SGU 238 Uncle Vasya and Bags for Potatoes 规律+构造
- sgu-238 Uncle Vasya and Bags for Potatoes
- URAL 1010 Discrete Function【简单暴力】
- URAL 1221. Malevich Strikes Back! 枚举 暴力
- Ural 1780 Gray Code (暴力)
- URAL 1221 Malevich Strikes Back! (暴力枚举)
- ural 1889 Airport Announcements (暴力模拟)
- URAL 1089|Verification with a Vocabulary|暴力
- Codeforces441B_Valera and Fruits(暴力)
- Codeforces441C_Valera and Tubes(暴力)
- jrMz and angles 暴力
- ASP.NET MVC5(3)数据从控制器传递给视图
- java基础
- CSR 8670 开启 GAIA 编译 BLUELIB
- 无约束最优化方法学习笔记
- HDU4786 Fibonacci Tree(Kruskal)
- Chapaev and Potatoes (URAL 1809 暴力)
- POJ 1611 The Suspects(并查集)
- 基于SSH实现全选删除功能
- 回归测试和冒烟测试的区别
- HDU 5366 The mook jong (动态规划,详解)
- 20150809
- Windows下pip安装包报错:Microsoft Visual C++ 9.0 is required Unable to find vcvarsall.bat
- ubuntu下lsof工具使用手册--一切皆文件
- 个人