按顺时针给出n个小孩,n个小孩每个人都有一个纸,然后每个人都有一个val,这个val等于自己的因子数,如果这个val是正的,那就顺时针的第val个孩子出去,如果是负的话,就逆时针的第val个孩子出去,所以可以用线段树维护一个区间内的孩子数,然后找到下一个孩子是这些人里的第k个人,用线段树找到剩下的第k个人的位置,然后把这个地方更新成0,这样模拟过程.

反素数:反素数就是从区间1 - i 内的数的因子数都比 i 的因子数少的数,这题中因为同样的val值时选择出队早的人,其实就是1-n内的最大反素数m,就说明是第m个人的因子数是最大的,然后我只需要模拟前m次就可以了

#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define first fi
#define second se
#define lowbit(x) (x & (-x)) typedef unsigned long long int ull;
typedef long long int ll;
const double pi = 4.0*atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = ;
const int maxm = ;
using namespace std; int n, m, tol, T;
struct Node {
char name[];
int k;
};
Node node[maxn];
int sum[maxn << ];
int RPrime[]= {
,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,, }; int fact[]= {
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,
}; void pushup(int root) {
sum[root] = sum[root << ] + sum[root << | ];
} void build(int left, int right, int root) {
if(left == right) {
sum[root] = ;
return ;
}
int mid = (left +right) >> ;
build(left, mid, root << );
build(mid+, right, root << | );
pushup(root);
} int update(int left, int right, int k, int root) {
if(left == right) {
sum[root]--;
return left;
}
int mid = (left + right) >> ;
int ans;
if(sum[root << ] >= k) ans = update(left, mid, k, root << );
else ans = update(mid+, right, k-sum[root << ], root << | );
pushup(root);
return ans;
} int main() {
int k;
while(~scanf("%d%d", &n, &k)) {
for(int i=; i<=n; i++)
scanf("%s%d", node[i].name, &node[i].k);
build(, n, );
int ansnum;
for(int i=; RPrime[i]<=n; i++) {
m = RPrime[i];
ansnum = fact[i];
}
tol = n;
int pos;
for(int i=; i<=m; i++) {
tol--;
pos = update(, n, k, );
if(tol == ) break;
if(node[pos].k > )
k = ((k + node[pos].k - ) % tol + tol) %tol + ;
else
k = ((k + node[pos].k - ) % tol + tol) % tol + ; }
printf("%s %d\n", node[pos].name, ansnum);
}
return ;
}
/*
7 3
a 3
b 2
c -5
d 4
e 8
f 2
g -6
*/

Who Gets the Most Candies? POJ - 2886 (线段树)的更多相关文章

  1. poj 2886 线段树+反素数

    Who Gets the Most Candies? Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 12744   Acc ...

  2. poj 2886 (线段树+反素数打表) Who Gets the Most Candies?

    http://poj.org/problem?id=2886 一群孩子从编号1到n按顺时针的方向围成一个圆,每个孩子手中卡片上有一个数字,首先是编号为k的孩子出去,如果他手上的数字m是正数,那么从他左 ...

  3. POJ 2886 线段树单点更新

    转载自:http://blog.csdn.net/sdj222555/article/details/6878651 反素数拓展参照:http://blog.csdn.net/ACdreamers/a ...

  4. poj 2886 线段树的更新+反素数

    Who Gets the Most Candies? Time Limit: 5000 MS Memory Limit: 0 KB 64-bit integer IO format: %I64d , ...

  5. (中等) 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 ...

  6. Who Gets the Most Candies? POJ - 2886(线段树单点更新+区间查询+反素数)

    预备知识:反素数解析 思路:有了反素数的解法之后就是线段树的事了. 我们可以用线段树来维护哪些人被淘汰,哪些人没被淘汰,被淘汰的人的位置,没被淘汰的人的位置. 我们可以把所有人表示为一个[1,n]的区 ...

  7. poj 3468(线段树)

    http://poj.org/problem?id=3468 题意:给n个数字,从A1 …………An m次命令,Q是查询,查询a到b的区间和,c是更新,从a到b每个值都增加x.思路:这是一个很明显的线 ...

  8. POJ——3264线段树

    题目: 输入两个数(m,n),m表示牛的头数,n表示查询的个数.查询时输入两个数(x,y),表示查询范围的起始值和终止值,查询结果是,这个区间内牛重量的最大值减去牛重量的最小值,数量级为1000,00 ...

  9. POJ 2828 线段树(想法)

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 15422   Accepted: 7684 Desc ...

随机推荐

  1. 【学习总结】Git学习-参考廖雪峰老师教程六-分支管理

    学习总结之Git学习-总 目录: 一.Git简介 二.安装Git 三.创建版本库 四.时光机穿梭 五.远程仓库 六.分支管理 七.标签管理 八.使用GitHub 九.使用码云 十.自定义Git 期末总 ...

  2. 测试python最大递归层次

    转自:https://www.cnblogs.com/xiongdashuai/p/6243372.html python默认的最大递归层数: 运行环境:Windows 7,x64python环境:p ...

  3. PHP--高级算法--面试

    数据结构和算法(转载) 原文地址:  https://blog.csdn.net/s1070/article/details/51174725 1.使对象可以像数组一样进行foreach循环,要求属性 ...

  4. Git的配置与使用

    Git的配置与使用 一,未配置过git 1.1,安装Git https://git-for-windows.github.io/ 1,2,鼠标右键点击Git Bash Here 1.3,输入命令 cd ...

  5. 缓存session,cookie,sessionStorage,localStorage的区别

    https://www.cnblogs.com/cencenyue/p/7604651.html(copy) 浅谈session,cookie,sessionStorage,localStorage的 ...

  6. linux的一些基本命令

    一.linux的一些基本命令(使用的是CentOS7系统): 1.创建用户组,创建新用户并添加到用户组 添加用户,添加用户组命令: 增加用户:useradd -d /usr/username -m u ...

  7. mac下php开发环境的搭建

    1.phpstorm 在官网:https://www.jetbrains.com/phpstorm/,下载最新版:phpstorm-2016.2.1 在http://15.idea.lanyus.co ...

  8. git修改用户名、邮箱

    在windows使用git命令方法如下(以win7为例):1.msysgit 是 Windows 版的 Git可以百度搜索Git下载.2.安装完成后,开始菜单里找到“Git”->“Git Bas ...

  9. python爬虫之pandas

    一.简介: Python Data Analysis Library 或 pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的.Pandas 纳入了大量库和一些标准的数据模 ...

  10. ArcGIS中使用异步回调函数查询图层Graphic

    在我们的地图的操作中经常会有一些操作是需要通过画多边形或者画线来查找某一块区域内的特定的Graphics比如我们在做的交警的项目中通过框选来查找某一块区域中的摄像机,某一块区域中的警力.警情.警员等相 ...