code forces Help Vasilisa the Wise 2
来源:互联网 发布:数据库管理器 编辑:程序博客网 时间:2024/05/21 00:21
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 × 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 ≤ r1, r2, c1, c2, d1, d2 ≤ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
3 74 65 5
1 23 4
11 1013 85 16
4 79 1
1 23 45 6
-1
10 1010 1010 10
-1
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.
【题解】
就搞个4重循环找一下就好了,这个题判题特别慢,把人等的以为超时了。。。
【AC代码】
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int r1,r2,c1,c2,d1,d2;int main(){ while(~scanf("%d%d%d%d%d%d",&r1,&r2,&c1,&c2,&d1,&d2)) { int tag=0; for(int i=1;i<=9;++i) { for(int j=1;j<=9;++j) { //printf("1\n"); for(int k=1;k<=9;++k) { for(int l=1;l<=9;++l) { if(i==j||i==k)continue; if(i==l||j==k)continue; if(j==l||k==l)continue; if(i+j==r1&&i+k==c1&&k+l==r2&&j+l==c2&&i+l==d1&&j+k==d2) { printf("%d %d\n",i,j); printf("%d %d\n",k,l); tag = 1; break; } } if(tag) break; } if(tag) break; } if(tag) break; } if(!tag) printf("-1\n"); } return 0;}
- code forces Help Vasilisa the Wise 2
- A. Help Vasilisa the Wise 2
- codeforce 143 A Help Vasilisa the Wise 2
- A. Help Vasilisa the Wise 2 codeforces-problem-143A
- Codeforces 143A Help Vasilisa the Wise 2(暴力)
- Code Forces 2 B The least round way
- code forces 630 L. Cracking the Code
- Help Victoria the Wise(cf 07/22/2011)
- CF—98A—Help Victoria the Wise
- code forces 409A The Great Game
- code forces 2A Winner
- Code Forces 21C Stripe 2
- code forces 3A Shortest path of the king
- Code Forces 581 A. Vasya the Hipster(水~)
- Code Forces 585 A. Gennady the Dentist(模拟)
- Code Forces 592 C. The Big Race(数论)
- Code Forces 601 A. The Two Routes(Floyd)
- Digital Root----code forces
- JavaWeb学习笔记-XML-8
- 171127 Linux tensorboard
- Java与JNI类型转换,方法调用
- # 与 $ 区别以及 sql 预编译
- SVM中的训练算法:序列最小最优化算法SMO的读书笔记
- code forces Help Vasilisa the Wise 2
- LeetCode 分类练习(5)—— 链表相关习题(1)
- 关于storyboard和xib创建控制器
- Jackson学习二之集合类对象与JSON互相转化
- 环形队的基本操作(C语言)
- MyBatis之statementType="STATEMENT"的使用
- 输入输出函数
- 分治法--“自顶向下,逐步求精”的程序设计方法
- Android设置透明、半透明等效果