Codeforces Round #726 (Div. 2) B. Bad Boy(贪心)
Posted issue是fw
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #726 (Div. 2) B. Bad Boy(贪心)相关的知识,希望对你有一定的参考价值。
容易想到两个位置选在角上是最优的
设两个点分别为 p 1 , p 2 p_1,p_2 p1,p2,原点为 p 3 p_3 p3
此时距离为 d i s ( p 3 , p 1 ) + d i s ( p 1 , p 2 ) + d i s ( p 2 , p 3 ) dis(p_3,p_1)+dis(p_1,p_2)+dis(p_2,p_3) dis(p3,p1)+dis(p1,p2)+dis(p2,p3)
又因为 d i s ( p 3 , p 1 ) + d i s ( p 2 + p 3 ) = d i s ( p 1 , p 2 ) dis(p_3,p_1)+dis(p_2+p_3)=dis(p_1,p_2) dis(p3,p1)+dis(p2+p3)=dis(p1,p2)
所以距离为 2 ∗ d i s ( p 1 , p 2 ) 2*dis(p_1,p_2) 2∗dis(p1,p2)
只需要使 d i s ( p 1 , p 2 ) dis(p_1,p_2) dis(p1,p2)最远即可
这样的话,一定是选对角比较好
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9+7;
const int maxn = 3e5+10;
int n,m,x,y;
signed main()
{
int t; cin >> t;
while( t-- )
{
scanf("%d%d%d%d",&n,&m,&x,&y);
cout << 1 << " " << m << " " << n << " " << 1 << endl;
}
return 0;
}
这是比赛时的傻逼代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9+7;
const int maxn = 3e5+10;
int fac[maxn];
int quick(int x,int n)
{
int ans = 1;
for( ; n ; n>>=1,x=1ll*x*x%mod )
if( n&1 ) ans = 1ll*ans*x%mod;
return ans;
}
int C(int n,int m)
{
if( m>n ) return 0;
return 1ll*fac[n]*quick( 1ll*fac[m]*fac[n-m]%mod,mod-2 )%mod;
}
typedef pair<int,int>p;
int n,m,x,y,t,a[maxn][5];
int get(int id)
{
int dis1 = abs( a[id][1]-x )+abs( a[id][2]-y )+abs( a[id][3]-x )+abs( a[id][4]-y );
int dis2 = abs( a[id][1]-a[id][3] )+abs( a[id][2]-a[id][4] );
return dis1+dis2;
}
signed main()
{
fac[0] = 1;
for(int i=1;i<=100000;i++) fac[i] = 1ll*fac[i-1]*i%mod;
int t; cin >> t;
while( t-- )
{
scanf("%d%d%d%d",&n,&m,&x,&y);
a[1][1] = 1, a[1][2] = 1, a[1][3] = n, a[1][4] = m;
a[2][1] = 1, a[2][2] = 1, a[2][3] = 1, a[2][4] = m;
a[3][1] = n, a[3][2] = 1, a[3][3] = 1, a[3][4] = m;
a[4][1] = n, a[4][2] = 1, a[4][3] = n, a[4][4] = m;
a[5][1] = 1, a[5][2] = 1, a[5][3] = n, a[5][4] = 1;
a[6][1] = 1, a[6][2] = m, a[6][3] = n, a[6][4] = m;
int id = 1, ans = get( 1 );
for(int i=2;i<=6;i++)
{
if( get(i)>ans ) ans = get(i), id = i;
}
for(int i=1;i<=4;i++) cout << a[id][i] << " ";
cout << endl;
}
return 0;
}
以上是关于Codeforces Round #726 (Div. 2) B. Bad Boy(贪心)的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #726 (Div. 2) 6-18
Codeforces Round #726 (Div. 2) D题解
Codeforces Round #726 (Div. 2)(补题)
Codeforces Round #726 (Div. 2) A. Arithmetic Array