ZOJ 4025 King of Karaoke

本文介绍了一种通过调整整数序列实现歌曲表演分数最大化的算法。针对两个长度相等的整数序列,通过选择合适的调整值使得序列尽可能匹配,以此来提高计分。文章提供了一个具体的C语言实现案例。

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

题目
It’s Karaoke time! DreamGrid is performing the song Powder Snow in the game King of Karaoke. The song performed by DreamGrid can be considered as an integer sequence D1, D2,……,Dn, and the standard version of the song can be considered as another integer sequence S1,S2,……,Sn. The score is the number of integers i satisfying 1 ≤ i ≤ n and Si = Di.

As a good tuner, DreamGrid can choose an integer (can be positive, 0, or negative) as his tune and add to every element in . Can you help him maximize his score by choosing a proper tune? 
Input
There are multiple test cases. The first line of the input contains an integer T (about 100), indicating the number of test cases. For each test case:

The first line contains one integer n (1 ≤ n ≤ 105), indicating the length of the sequences D and S.

The second line contains n integers D1,D2,……,Dn (-105 ≤ Di ≤ 105), indicating the song performed by DreamGrid.

The third line contains n integers S1,S2,……,Sn (-105 ≤ Si ≤ 105), indicating the standard version of the song.

It’s guaranteed that at most 5 test cases have n > 100. 
Output
For each test case output one line containing one integer, indicating the maximum possible score. 
Sample Input


1 2 3 4 
2 3 4 6 

-5 -4 -3 -2 -1 
5 4 3 2 1 
Sample Output

1

就是看两组数的差值想减,输出相同的数出现的最多次数,可能有负的,如果有负的可以转为正的.

看代码

# include <stdio.h>
# include <string.h>

int main(void)
{
	int t, n, a[100001], b[100001], c[300010];
	int i, j, min, m, sum, q, w, k;
	scanf("%d", &t);
	while (t --)
	{
		min = -1;
		memset(c, 0, sizeof(c)); //记得初始化
		scanf("%d", &n);
		for (i = 1; i <= n; i ++)
			scanf("%d", &a[i]);
		for (i = 1; i <= n; i ++)
		{
			scanf("%d", &b[i]);
			if (b[i]-a[i] < 0)
				c[-(b[i]-a[i]-100000)] ++;// 小于0的转化为1000001  比如-1为1000001 -2为10000002
			else 
			c[b[i]-a[i]] ++ ;
		}
		for (i = 0; i < 200100; i ++)
		{
			if (c[i] > min)
				min = c[i];//遍历一遍即可
		}
		
		printf("%d\n", min);
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值