GDUT_排位賽題解報告_第2場_H. I Would Walk 500 Miles

題目:

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;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章