题目传送门

 #include <cstdio>
#include <cstring>
#define lson l, m, rt << 1
#define rson m+1, r, rt << 1 | 1 const int MAX_N = + ;
int sum[MAX_N << ];
struct node
{
char name[];
int val;
}boy[MAX_N<<];
int ans[MAX_N];
int id;
int n, k; void build(int l, int r, int rt)
{
sum[rt] = r - l + ;
if (l == r)
return ;
int m = (l + r) >> ;
build (lson);
build (rson);
} int update(int p, int l, int r, int rt)
{
sum[rt]--;
if (l == r)
{
return l;
}
int m = (l + r) >> ;
if (p <= sum[rt<<])
{
return update (p, lson);
}
else
{
return update (p - sum[rt<<], rson);
}
} void Solve(){ //计算ans
memset(ans,,sizeof(ans));
for(int i=;i<=n;i++){
ans[i]++;
for(int j=*i;j<=n;j+=i)
ans[j]++;
}
int max=ans[];
id=;
for(int i=;i<=n;i++) //找出第几个人跳出获得的糖最多
if(ans[i]>max){
max=ans[i];
id=i;
}
} int main(void) //POJ 2886 Who Gets the Most Candies?
{
//freopen ("inF.txt", "r", stdin); while (~scanf ("%d%d", &n, &k))
{
build (, n, );
for (int i=; i<=n; ++i)
{
scanf ("%s%d", &boy[i].name, &boy[i].val);
//printf ("%s%d\n", boy[i].name, boy[i].val);
}
Solve();
//int maxn = f(n);
int mod = sum[];
boy[].val = ;
int pos = ;
//printf ("%d\n", id);
int m=id;
while (m--)
{
if (boy[pos].val > )
k=((k-+boy[pos].val-)%mod+mod)%mod+;
else
k=((k-+boy[pos].val)%mod+mod)%mod+;
pos = update (k, , n, );
//printf ("%d ", pos);
mod = sum[];
}
printf ("%s %d\n", boy[pos].name, ans[id]);
}
}

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

  1. 线段树单点更新poj 2828

    n个人 他要插入的位置 和权值(这东西就最后输出来的) 倒的插就一定是他自己的位子 一个线段树维护一下就可以了 nlog(n) #include<stdio.h> #include< ...

  2. 线段树(单点更新) POJ 2828 Buy tickets

    题目传送门 /* 结点存储下面有几个空位 每次从根结点往下找找到该插入的位置, 同时更新每个节点的值 */ #include <cstdio> #define lson l, m, rt ...

  3. poj 2892---Tunnel Warfare(线段树单点更新、区间合并)

    题目链接 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensiv ...

  4. POJ 1804 Brainman(5种解法,好题,【暴力】,【归并排序】,【线段树单点更新】,【树状数组】,【平衡树】)

    Brainman Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10575   Accepted: 5489 Descrip ...

  5. POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)

    POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...

  6. POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化)

    POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化) 题意分析 前置技能 线段树求逆序对 离散化 线段树求逆序对已经说过了,具体方法请看这里 离散化 有些数 ...

  7. HDU 1754 I Hate It 线段树单点更新求最大值

    题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...

  8. HDU 1166 敌兵布阵(线段树单点更新)

    敌兵布阵 单点更新和区间更新还是有一些区别的,应该注意! [题目链接]敌兵布阵 [题目类型]线段树单点更新 &题意: 第一行一个整数T,表示有T组数据. 每组数据第一行一个正整数N(N< ...

  9. HDU 1166 敌兵布阵(线段树单点更新,板子题)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

随机推荐

  1. 诺基亚(Microsoft Devices Group)2014暑期实习生笔试题知识点

    总结一下Microsoft Devices Group的软件类笔试题,全部笔试题分两份试卷,逻辑题一份和软件測试题一份,仅仅总结技术题喽~题目全英文,仅仅包括选择题和填空题.选择题居多.分单选和多选. ...

  2. VS 预先生成事件命令

    宏 说明 $(ConfigurationName) 当前项目配置的名称(例如,“Debug|Any CPU”). $(OutDir) 输出文件目录的路径,相对于项目目录.这解析为“输出目录”属性的值. ...

  3. css hack (ie6-ie9+)

    IE6 css hack: 1. *html Selector {} /* Selector 表示 css选择器 下同 */ 2. Selector { _property: value; } /* ...

  4. 利用Python3的dpkt库进行ARP扫描

    背景 正在学习网络协议,用Python写起来方便点,可以快速熟悉协议本身,也给自己补充一些Python库. 偶然看到这篇文章,讲的是Python发ARP包,发现是Python2的,这里改了一下,用Py ...

  5. SDUT OJ 2892 A (字典树问题-输出出现次数最多的字符串的出现次数,60ms卡时间,指针+最后运行完释放内存)

    A Time Limit: 60ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 给出n(1<= n && n <= 2*10^6)个字 ...

  6. SpringBoot发送简单文本邮件

    1.pom.xml添加 spring-boot-starter-mail 依赖 <dependency> <groupId>org.springframework.boot&l ...

  7. JavaScript页面刷新与弹出窗口问题的解决方法

    1. [代码][JavaScript]代码     ​一.无提示刷新网页 大家有没有发现,有些网页,刷新的时候,会弹出一个提示窗口,点“确定”才会刷新.而有的页面不会提示,不弹出提示窗口,直接就刷新了 ...

  8. WPF 之Converter

    WPF  之Converter Leo 在我们做项目的时候,经常会遇见这样的事情: 在数据中我们定义的是true,false 而在现实的时候则可能要求男,女 我们还得能定义成了0,1,2,3,4,5, ...

  9. Oracle的wm_concat函数(转)

    wm_concat函数简单说就是行转列显示. 转自:http://christy-fang.iteye.com/blog/1299850 首先让我们来看看这个神奇的函数wm_concat(列名),该函 ...

  10. windows下关闭指定端口服务,解决tomcat端口占用问题

    http://blog.aizhet.com/Server/640.html 在windows下做java EE的开发时:搭建 Eclipse+tomcat的java web开发环境:在应用之中经常遇 ...