来源:codeforces 2020 GDUT Rating Contest II (Div. 2) CF链接
题目:
Farmer John wants to divide his N cows (N≤7500), conveniently numbered 1…N, into K non-empty groups (2≤K≤N) such that no two cows from two different groups can interact with each other without walking some number of miles. Cow x and Cow y (where 1≤x<y≤N) are willing to walk (2019201913x+2019201949y) mod 2019201997 miles to see each other.
Given a division of the N cows into K non-empty groups, let M be the minimum of the number of miles any two cows in two different groups are willing to walk to see each other. To test the cows’ devotion to each other, Farmer John wants to optimally divide the N cows into K groups such that M is as large as possible.
Input
The input is just one line, containing N and K, separated by a space.
Output
Print out M in an optimal solution.
Example
input
3 2
output
2019201769
题意:将n头牛分成k组,使得用指定方法计算出的任意两头不同组的奶牛的最小距离最大。距离计算方法为d=(2019201913x+2019201949y) mod 2019201997,x、y为两头奶牛的坐标(理解为在数轴上)
思路:一开始直接把1和n带入x和y,结果居然能过7个点,然后发现这个距离出现在最后一头牛和倒数第二组的最后一头牛,于是把前k-1头牛分为k-1组,剩下的为第k组,就得到答案。
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
#define INF 0x3f3f3f3f
#define mod 2019201997
using namespace std;
int n,k;
int main()
{
cin>>n>>k;
long long ans=(1ll*2019201913*(k-1)+1ll*2019201949*n)%2019201997;
cout<<ans;
return 0;
}