按顺时针给出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. PAT L2-020 功夫传人

    https://pintia.cn/problem-sets/994805046380707840/problems/994805059118809088 一门武功能否传承久远并被发扬光大,是要看缘分 ...

  2. HTTPS的SSL证书配置

    SSL证书 TOMCAT7.0部署_百度经验https://jingyan.baidu.com/article/7082dc1c65066be40a89bda8.html SSL证书安装指引 - 青春 ...

  3. redis 运维手册

    redis cli命令 - milkty - 博客园https://www.cnblogs.com/kongzhongqijing/p/6867960.html Redis多个数据库 - EasonJ ...

  4. 关于PHP的那些坑

    因为PHP是弱类型语言,常常会发生许多意想不到的问题,所以,我们再次一一细数这些我们踏过的坑!!! 1) foreach中自动回将key为数值的转化成整型,造成无法匹配 function transl ...

  5. [转帖]CS、IP和PC寄存器

    https://www.cnblogs.com/zhuge2018/p/8466288.html 之前的理解不对 当然了 现在的理解也不太对.. CS.IP和PC寄存器 CS寄存器和IP寄存器: 首先 ...

  6. 【Java基础】求出1-100之间偶数和

    结果:

  7. 组建自己的局域网(可以将PC机实现为服务器)

    最近想要自己组建一个集群,并且可以通过外网访问,查了好些资料,终于成功了! 设备清单:笔记本1:(4g内存,500g硬盘),笔记本2:(12g内存,120g固态硬盘) (笔记本2上装有5台虚拟机,操作 ...

  8. vue中的跨域问题

    https://segmentfault.com/a/1190000011072725(原文)   使用vue-axios和vue-resource解决vue中调用网易云接口跨域的问题 注(api很重 ...

  9. APP-SERVICE-SDK:setStorageSync:fail;at page/near/pages/shops/shops page lifeCycleMethod onUnload function

    APP-SERVICE-SDK:setStorageSync:fail;at page/near/pages/shops/shops page lifeCycleMethod onUnload fun ...

  10. CentOS7安装Jenkins,使用war方式直接运行或用yum方式安装运行

    jenkins最简单的安装方式呢,就是直接去官网下载jenkins的war包,把war丢到tomcat里运行,直接就能打开了. Jenkins官网:https://jenkins.io/downloa ...