poj 2886 Who Gets the Most Candies?(线段树和反素数)
题目:http://poj.org/problem?id=2886
题意:N个孩子顺时针坐成一个圆圈且从1到N编号,每个孩子手中有一张标有非零整数的卡片。
第K个孩子先出圈,如果他手中卡片上的数字A大于零,下一个出圈的是他左手边第A个孩子。
否则,下一个出圈的是他右手边第(-A)个孩子。第p个出圈的孩子会得到F(p)个糖果,F(p)为p的因子数。求得到糖果数最多的是哪个孩子及得到多少糖果。
跟上一个 约瑟夫环的题目很像,就是加了一个反素数。
虽然我还是不太理解,但还是无耻的从别人的结题报告上把反素数表copy了下来。。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int maxn = + ;
int val[maxn];
char name[maxn][]; int a[]= {,,,,,,,,,,,,,,,,,,,
,,,,,,,,
,,,,,,,,
}; //反素数表
int b[]= {,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,
}; //反素数对应的值
struct node
{
int l, r, sum;
}tr[maxn<<]; void build(int t, int l, int r)
{
tr[t].l = l; tr[t].r = r;
tr[t].sum = r - l + ;
if(l == r)
return;
int mid = (l+r)>>;
build(*t, l, mid);
build(*t+, mid+, r);
}
int query(int num, int t)
{
tr[t].sum--;
if(tr[t].l == tr[t].r)
return tr[t].l;
if(tr[*t].sum >= num)
return query(num, *t);
else
return query(num-tr[*t].sum, *t+);
}
int main()
{
int n, k, i, p, Max;
int x;
while(~scanf("%d%d", &n, &k))
{
i = ;
Max = ; p = ;
while(a[i] <= n)
i++;
p = a[i-]; Max = b[i-]; //第几个出去的。最大值
build(, , n);
for(i = ; i <= n; i++)
scanf("%s%d",name[i], &val[i]); for(i = ; i < p; i++)
{
n--;
x = query(k, );
if(n == ) break;
if(val[x] > )
k = (k-+val[x]-)%n + ;
else
k = (k-+val[x]%n+n)%n + ;
}
printf("%s %d\n",name[x], Max);
}
return ;
}
poj 2886 Who Gets the Most Candies?(线段树和反素数)的更多相关文章
- POJ 2886 Who Gets the Most Candies? 线段树
题目: http://poj.org/problem?id=2886 左右转的果断晕,题目不难,关键是准确的转啊转.因为题目要求输出约数个数最多的数,所以预处理[1,500000]的约数的个数就行了. ...
- POJ 2886.Who Gets the Most Candies? -线段树(单点更新、类约瑟夫问题)
线段树可真有意思呢续集2... 区间成段的替换和增减,以及区间求和等,其中夹杂着一些神奇的操作,数据离散化,简单hash,区间异或,还需要带着脑子来写题. 有的题目对数据的操作并不是直接按照题面意思进 ...
- POJ 2886 Who Gets the Most Candies?(线段树·约瑟夫环)
题意 n个人顺时针围成一圈玩约瑟夫游戏 每一个人手上有一个数val[i] 開始第k个人出队 若val[k] < 0 下一个出队的为在剩余的人中向右数 -val[k]个人 val[k ...
- POJ 2886 Who Gets the Most Candies? 线段树。。还有方向感
这道题不仅仅是在考察线段树,还他妹的在考察一个人的方向感.... 和线段树有关的那几个函数写了一遍就对了,连改都没改,一直在转圈的问题的出错.... 题意:从第K个同学开始,若K的数字为正 则往右转, ...
- poj 2886 "Who Gets The Most Candies?"(树状数组)
传送门 参考资料: [1]:http://www.hankcs.com/program/algorithm/poj-2886-who-gets-the-most-candies.html 题意: 抢糖 ...
- 线段树(单点更新) POJ 2886 Who Gets the Most Candies?
题目传送门 #include <cstdio> #include <cstring> #define lson l, m, rt << 1 #define rson ...
- POJ 2828 Buy Tickets(排队问题,线段树应用)
POJ 2828 Buy Tickets(排队问题,线段树应用) ACM 题目地址:POJ 2828 Buy Tickets 题意: 排队买票时候插队. 给出一些数对,分别代表某个人的想要插入的位 ...
- POJ 2886 Who Gets the Most Candies? (线段树)
[题目链接] http://poj.org/problem?id=2886 [题目大意] 一些人站成一个圈,每个人手上都有一个数字, 指定从一个人开始淘汰,每次一个人淘汰时,将手心里写着的数字x展示 ...
- (中等) POJ 2886 Who Gets the Most Candies? , 反素数+线段树。
Description N children are sitting in a circle to play a game. The children are numbered from 1 to N ...
随机推荐
- Notes of the scrum meeting(2013/10/27)
软工项目组buaa_smile确定自由项目主题及实现功能的scrum meeting meeting time:1:00~2:00p.m.,October 27th,2013 meeting plac ...
- JS实现刷新iframe的方法
<iframe src="1.htm" name="ifrmname" id="ifrmid"></iframe> ...
- 历时一周,unity3d+xtion打造我的第一个休闲体感小游戏《空降奇兵》
1.游戏介绍 本游戏属于休闲小游戏,主要操作如下: 菜单控制:举起左手或右手,点击左边或者右边的菜单:挥动左手或右手,选择关卡: 操作方式:玩家跳跃,游戏中的伞兵从飞机开始降落:玩家通过控制伞兵的左右 ...
- maven学习心得整理
maven的学习心得 已经接触了maven项目有一段时间了,开始时仅仅会使用,在使用中发现了它的强大和方便,于是决心研究一下: 首先,普及一下maven参数: -D:传入属性参数 -P:使用POM中指 ...
- linux 下载并安装Memcache服务器端
1.下载并安装Memcache服务器端 服务器端主要是安装memcache服务器端. 下载:http://www.danga.com/memcached/dist/memcached-1.2.2.ta ...
- uva 11489
简单博弈 #include <cstdio> #include <cstdlib> #include <cmath> #include <map> #i ...
- Unity3D研究院之IOS全自动打包生成ipa
接着上一篇文章, 自动生成framework,这篇文章我把shell自动化打包ipa整理了一下,希望大家喜欢,嘿嘿.. 建议大家先看一下上一篇文章.http://www.xuanyusong.com/ ...
- centos在yum install报错:Another app is currently holding the yum lock解决方法
centos在yum install报错:Another app is currently holding the yum lock,这个问题可能是很多的新手经常遇到问题,之前也有人问我,包括本人在刚 ...
- 暑假集训单切赛第一场 CF 191A Dynasty Puzzles
题意不说了,看原题吧,思路见代码: #include <iostream> #include <stdio.h> #include <string.h> #incl ...
- POJ2513Colored Sticks
http://poj.org/problem?id=2513 题意 : 一些木棒,两端都涂上颜色,求是否能将木棒首尾相接,连成一条直线,要求不同木棒相接的一边必须是相同颜色的. 思路 : 这个题的话就 ...