本文主要是介绍codeforces MemSQL Start[c]UP 2.0 - Round 1 B. 4-point polyline,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
其实这是一道很简单的题...
给出(n, m),可以得到一个矩形
让你依次连接矩形内的4个点使它们的长度和最长,而这三条线段可以相交、交叉
遇到这种情况,首先要想到对角线...
出去n==0 m==0的特判可以分4种情况:
这么一来列出4种情况总长度,取最大值对应的即可
代码如下:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAXN 10010
#define LL long long
using namespace std;int x[MAXN], y[MAXN];int main(void) {int m, n, i;double ans1, ans2, ans3, ans4, ans;while(cin >> n >> m) {if(n == 0) {x[0] = 0; y[0] = 1;x[1] = 0; y[1] = m;x[2] = 0; y[2] = 0;x[3] = 0; y[3] = m-1;} else if(m == 0) {x[0] = 1; y[0] = 0;x[1] = n; y[1] = 0;x[2] = 0; y[2] = 0;x[3] = n-1; y[3] = 0;} else {ans1 = 2.0*sqrt((n-1.0)*(n-1.0)*1.0+m*m*1.0)+sqrt(n*n*1.0+m*m*1.0);ans2 = n*1.0 + 2.0*sqrt(n*n*1.0+m*m*1.0);ans3 = m*1.0 + 2.0*sqrt(n*n*1.0+m*m*1.0);ans4 = 2.0*sqrt(n*n*1.0+(m-1.0)*(m-1.0)*1.0)+sqrt(n*n*1.0+m*m*1.0);cout << ans1 << endl;cout << ans2 << endl;cout << ans3 << endl;cout << ans4 << endl;ans = max(ans1, ans2);ans = max(ans, ans3);ans = max(ans, ans4);if(ans == ans3){x[0] = n; y[0] = m;x[1] = 0; y[1] = 0;x[2] = 0; y[2] = m;x[3] = n; y[3] = 0;} else if(ans == ans2){x[0] = n; y[0] = m;x[1] = 0; y[1] = 0;x[2] = n; y[2] = 0;x[3] = 0; y[3] = m;} else if(ans == ans1){x[0] = n-1; y[0] = 0;x[1] = 0; y[1] = m;x[2] = n; y[2] = 0;x[3] = 1; y[3] = m;} else if(ans == ans4) {x[0] = 0; y[0] = 1;x[1] = n; y[1] = m;x[2] = 0; y[2] = 0;x[3] = n; y[3] = m-1;}}for(i=0; i<4; ++i)printf("%d %d\n", x[i], y[i]);}return 0;
}
这篇关于codeforces MemSQL Start[c]UP 2.0 - Round 1 B. 4-point polyline的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!