GDUT_排位赛题解报告_第2场_H. I Would Walk 500 Miles

本文探讨了一种算法问题,即如何将N头牛最优地分成K组,使得任意两组间的最小交互距离最大化。通过分析,得出了一个简洁的数学表达式来解决这个问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目:

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值