题目:
H. I Would Walk 500 Miles
time limit per test1 second
memory limit per test512 megabytes
inputstandard input
outputstandard output
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
inputCopy
3 2
outputCopy
2019201769
这个东西一看,就是有点奇怪,怎么都想不到思路,然后笔纸一划,茅塞顿开。
这个东西有点像小学奥数,如果让998x%1000+999y%1000最大,而且xy都小于500,怎么办呢,当然是x、y越大,这个值越小啦,因为x每增加一次,最后的值都会减2,x=1,得出的998,为2,得出就是996,所以x、y值越大,这些值会越小的。
为什么说小于500,实际上是x小于500,y小于1000,因为x一旦成为501,那么500*(1000-998)已经等于1000了,所以501又会等于1,同理502又是2。y也是这个道理,我们看这个题目显然没有超过对应的数,便可以大胆的说:x,y越小,值越大,那么问题就迎刃而解了:
分组也很简单,就是贪心一下,我们容易得出答案就是一个式子:(X*(k-1)+Y*n)%p
代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <climits>
#include <queue>
#include <stack>
#include <map>
//鬼畜头文件
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
typedef unsigned long long ULL;
typedef long long LL;
const LL X = 2019201913, Y = 2019201949, p = 2019201997;
//鬼畜define
LL n,k;
int main()
{
scanf("%lld%lld", &n, &k);
printf("%lld\n",(X*(k-1)+Y*n)%p);
return 0;
}