按顺时针给出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. Docker -d : Running modprobe bridge nf_nat failed with message: exit status 1

    nf_nat 是做什么用的 - DockOne.iohttp://dockone.io/question/1384 docker-py的配置与使用 - openxxs - 博客园http://www. ...

  2. html5-attr和prop

    ###1.什么是attrbute和property attribute(attr) html标签的预定义属性 checked html标签的自定义属性         a eg: <input ...

  3. React Native之微信分享(iOS Android)

    React Native之微信分享(iOS Android) 在使用React Native开发项目的时候,基本都会使用到微信好友或者微信朋友圈分享功能吧,那么今天我就带大家实现以下RN微信好友以及朋 ...

  4. Oracle调优总结

    Oracle调优总结(经典实践 重要) https://blog.csdn.net/dtjiawenwang88/article/details/74892245 https://www.cnblog ...

  5. python之路--前端CSS

    一.CSS介绍 CSS(Cascading Style Sheet,层叠样式表)定义了如何显示HTML元素,给HTML设置样式,让他更加美观. 当浏览器读到这个样式表, 他就会按照这个样式来对文档进行 ...

  6. java split(regex,limit) 使用记录

    1.split(“,”,0):是切割默认模式等同于split(",")结尾符合分割字符为空不进行进行分割,如图: 2.split(",",-1):limit参数 ...

  7. Vue单文件组件

    前面的话 本文将详细介绍Vue单文件组件 概述 在很多 Vue 项目中,使用 Vue.component 来定义全局组件,紧接着用 new Vue({ el: '#container '}) 在每个页 ...

  8. A Simple Problem with Integers(线段树区间更新模板)

    最基本的线段树的区间更新及查询和 用tag(lazy)数组来“延缓”更新,查询或添加操作必须进行pushdown操作,即把tag从p传到lp和rp并清楚tag[p],既然得往lp和rp递归,那么就可以 ...

  9. codeforces722B

    Verse Pattern CodeForces - 722B You are given a text consisting of n lines. Each line contains some ...

  10. python 项目目录结构

    目录组织方式 关于如何组织一个较好的Python工程目录结构,已经有一些得到了共识的目录结构.在Stackoverflow的这个问题上,能看到大家对Python目录结构的讨论. 这里面说的已经很好了, ...