PKU 2886 反素数+线段树

Who Gets the Most Candies?
Time Limit: 5000MS Memory Limit: 131072K
Total Submissions: 7896 Accepted: 2352
Case Time Limit: 2000MS

Description

N children are sitting in a circle to play a game.

The children are numbered from 1 to N in clockwise order. Each of them has a card with a non-zero integer on it in his/her hand. The game starts from the K-th child, who tells all the others the integer on his card and jumps out of the circle. The integer on his card tells the next child to jump out. Let A denote the integer. If A is positive, the next child will be the A-th child to the left. If A is negative, the next child will be the (A)-th child to the right.

The game lasts until all children have jumped out of the circle. During the game, the p-th child jumping out will get F(p) candies where F(p) is the number of positive integers that perfectly divide p. Who gets the most candies?

Input

There are several test cases in the input. Each test case starts with two integers  N (0 <  N  ≤ 500,000) and K (1 ≤ K ≤ N) on the first line. The next N lines contains the names of the children (consisting of at most 10 letters) and the integers (non-zero with magnitudes within 108) on their cards in increasing order of the children’s numbers, a name and an integer separated by a single space in a line with no leading or trailing spaces.

Output

Output one line for each test case containing the name of the luckiest child and the number of candies he/she gets. If ties occur, always choose the child who jumps out of the circle first.

Sample Input

4 2
Tom 2
Jack 4
Mary -1
Sam 1

Sample Output

Sam 3

Source

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top



题目大意:几个孩子围成一圈,从第K个孩子开始跳出,每个孩子的手里有一张牌,上面写着非零的正整数,从第K个孩子开始,他跳出后,如果手里的牌上的数字是正数,那么从他左边开始越过牌上正整数的人数来得到下一个要跳出的人。如果手上的牌是负数,那么从他的右边开始越过负数的绝对值的人数得到下一个要跳出的人,没一个人跳出之后所得到的糖果数都是 他跳出的序号的约数个数,求得到糖果最多的孩子 以及他得到的糖果数。


先说这个题目要用到的第一个知识点,线段树。先创建一个1---n的线段树,每个区间的附加信息为当前区间的人数,如果序号为p的人要跳出,那么,如果tree[rt<<1]>=p,那么证明要跳出的人的序号在左边的区间,否则,要跳出的人在右边的区间,序号为p-tree[rt<<1]。从根节点一直向下处理,直到编号为p的人跳出即可。每次Update操作的时候,对应的区间的人数都要减掉1,因为每次操作一定会跳出一个,这样在update的函数中把pushup函数的要求也就实现了。。。。


另一个 知识点就是反素数,定义是如果小于等于N的任意数的因子个数都少于N的因子个数,那么N为反素数,即1---N的区间内N的因子数最多 。所以,如果有n个人,那么我们要找的得到最多糖果数就是n以内的最大反素数的因子数。至于得到最多糖果的人是谁,我们在找最大反素数的过程中,对应的那个人便是的到糖果最多的人。


至于求最大反素数以及对应的最大因子数的算法我还在实现中,写好了立刻贴上来


题目的代码如下:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define maxn 555555
#define lson l , m, rt<<1
#define rson m+1, r, rt<<1|1
using namespace std;
int n,k;
int tree[maxn<<2];
const int antiprime[]={1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,
	1260,1680,2520,5040,7560,10080,15120,20160,25200,27720,
	45360,50400,55440,83160,110880,166320,221760,277200,
	332640,498960,554400,665280};
const int factorNum[]={1,2,3,4,6,8,9,10,12,16,18,20,24,30,32,36,40,48,60,64,72,80,84,
	90,96,100,108,120,128,144,160,168,180,192,200,216,224};
typedef struct node
{
	char name[15];
	int value;
}JD;
JD person[maxn];
void build(int l,int r,int rt)
{
	tree[rt]=r-l+1;
	if(l==r)
		return ;
	int m=(l+r)>>1;
	build(lson);
	build(rson);
}
int update(int k,int l,int r,int rt)
{
	tree[rt]--;
	if(l==r)
	{
		return l;
	}
	int m=(l+r)>>1;
	if(k<=tree[rt<<1]) return update(k,lson);
	else
	{
		k-=tree[rt<<1];
		return update(k,rson);
	}
}
int main(void)
{
	int i;
	int n,k,&mod=tree[1];
	while(scanf("%d%d",&n,&k)==2)
	{
		for(i=1;i<=n;i++)	
			scanf("%s%d",person[i].name,&person[i].value);
		build(1,n,1);
		int cnt=0;
		while(cnt<35 && antiprime[cnt]<=n)	cnt++;
		cnt--;
		int pos=0;
		person[pos].value=0;
		for(i=0;i<antiprime[cnt];i++)
		{
			if(person[pos].value>0)	k=((k+person[pos].value-2)%mod+mod)%mod+1;
			else	k=((k+person[pos].value-1)%mod+mod)%mod+1;
			pos=update(k,1,n,1);
		}
		printf("%s %d\n",person[pos].name,factorNum[cnt]);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: PKU VehicleID数据集是由北京大学智能交通与多媒体实验室提供的一个用于车辆识别的图像数据库。该数据集包含了车辆在不同环境、不同拍摄条件下的图像,旨在用于车辆相关研究的数据训练和测试。 PKU VehicleID数据集收集了超过8万辆车的图像,涵盖了2000多个车型和16000多个车例。这些图像是在不同的拍摄条件下捕捉到的,包括不同的光照、天气、角度和距离。这使得该数据集在车辆识别和相关研究领域具有较高的多样性和可用性。 PKU VehicleID数据集不仅提供了车辆图像,还包含了车辆的标注信息,如车辆类型、颜色、品牌等。这些标注信息为研究者提供了更多的可用数据,可以辅助他们进行车辆特征识别、车辆分类等相关研究。 PKU VehicleID数据集可以广泛应用于车辆识别、车辆检测、交通监控等领域的研究和实践中。通过利用该数据集,研究者可以进行车辆模型的建立与识别、车辆行为的分析与预测等工作,从而为智能交通和城市管理提供更好的技术支持和解决方案。 综上所述,PKU VehicleID数据集是一个丰富的车辆图像数据库,它提供了大量的车辆图像和标注信息,为车辆识别和相关研究领域的研究者提供了重要的资源和工具。通过该数据集的应用,我们可以更好地理解和研究车辆特征识别、车辆分类等问,为智能交通和城市管理带来更多的创新和进步。 ### 回答2: PKU VehicleID数据集是由北京大学人工智能与自动化研究所于2016年发布的一个车辆检测和识别的数据集。这个数据集主要包含了来自北京市道路监控系统的车辆图像和相关的车辆属性信息。 PKU VehicleID数据集的特点主要有以下几点。首先,该数据集包含了非常大量的车辆图像,总计约50万张,涵盖了丰富的场景和车型样本。其次,这些图像都是以野外真实道路监控视频截取得到的,具有较高的真实性和复杂性。此外,数据集中的每一辆车都被分配了一个唯一的ID号码,用于标识和跟踪车辆。最后,PKU VehicleID数据集还提供了诸如车辆类型、颜色、品牌等属性信息,方便进行车辆属性识别和分类任务。 PKU VehicleID数据集在车辆检测、跟踪和识别领域有着广泛的应用价值。通过利用这个数据集,可以开展车辆检测算法的研究和性能评估。同时,也可以进行车辆属性识别、车型分类等应用任务的研究。这个数据集的发布对于提升车辆智能监控和交通管理系统的性能具有重要意义。此外,PKU VehicleID数据集还可以为自动驾驶、交通安全和交通流量分析等领域的研究提供有价值的实验数据基础。总之,PKU VehicleID数据集是一个丰富而有用的资源,为车辆相关研究提供了有力的支持。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值