Written by razrlele
13:58 August 16, 2014
昨天刚回学校, 晚上就和孟海一起打了一场, 结果得了个鸭蛋, 身残志坚, 我还能再战.
首先贴一个错误代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
/************************************************************************* > File Name: 20140815261A.cpp > Author: razrLeLe > Personal homepage: https://razrLeLe.com > Created Time: Fri 15 Aug 2014 11:36:27 PM CST ************************************************************************/ #include<iostream> using namespace std; #include<cstdio> #include<cmath> int done(int a, int b, int c, int d) { if(a >= -1000 && a <= 1000 && b >= -1000 && b <= 1000 && c >= -1000 && c <= 1000 && d >= -1000 && d <= 1000 ) { cout << a <<" " << b << " " << c << " " << d << endl; return 1; } return 0; } int main() { int x1, y1, x2, y2, x3, y3, x4, y4; cin >> x1 >> y1 >> x2 >> y2; if(x1 == x2 && y1 != y2) { x3 = x1+abs(y1-y2); y3 = y1; x4 = x3; y4 = y2; if(done(x3, y3, x4, y4)) return 0; x3 = x1-abs(y1-y2); y3 = y1; x4 = x3; y4 = y2; if(done(x3, y3, x4, y4)) return 0; } else if(y1 == y2 && x1 != x2) { x3 = x1; y3 = y1+abs(x1-x2); x4 = x2; y4 = y3; if(done(x3, y3, x4, y4)) return 0; x3 = x1; y3 = y1-abs(x1-x2); x4 = x2; y4 = y3; if(done(x3, y3, x4, y4)) return 0; } else { x3 = x1; y3 = y2; x4 = x2; y4 = y1; if((pow(x1-x3,2) + pow(y1-y3,2) + pow(x2-x3, 2) + pow(y2-y3, 2)) == (pow(x1-x2, 2) + pow(y1-y2,2)) && (pow(x1-x3,2) + pow(y1-y3,2)) == (pow(x2-x3, 2) + pow(y2-y3, 2)) && done(x3, y3, x4, y4)) return 0; } cout << -1 << endl; return 0; } |
Verdict: Wrong answer on pretest 4
测试数据是
-100 -100 100 100
感觉这个地方应该是自己在在最后一个情况即给出的两点是对角线的时候判断条件有问题, 其实只要任意相邻两边相等即可(因为本来就是矩形).
所以把判断条件改一下即可
1 2 |
if((pow(x1-x3,2) + pow(y1-y3,2)) == (pow(x2-x3, 2) + pow(y2-y3, 2)) && done(x3, y3, x4, y4)) return 0; |