日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

poj 2886 Who Gets the Most Candies?(线段树)

發布時間:2023/12/9 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 poj 2886 Who Gets the Most Candies?(线段树) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接:poj 2886 Who Gets the Most Candies?

題目大意:N個人圍成一圈玩約瑟夫環游戲,不同的是。步長不固定,由前一個出局的人決定。給定K表示起始的人。

第i個淘汰的人將獲得g(i)個糖果,問說誰獲得的糖果最多。

g(x)為x的因子個數。

解題思路:起始g(x)是成階段的,所以打表處理處g(x)遞增值,對于每一個N,一開始找到小于等于N的最大x,那么第x個淘汰的人即為獲得糖果數最多的家伙。剩下的就用線段樹模擬游戲過程。

#include <cstdio> #include <cstring> #include <algorithm>using namespace std; const int maxn = 500005;#define lson(x) ((x)<<1) #define rson(x) (((x)<<1)+1)struct Node {int l, r, s;void set (int l, int r, int s) {this->l = l;this->r = r;this->s = s;} }nd[maxn * 4];const int antipri[36] = {1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,1260,1680,2520,5040,7560,10080,15120,20160,25200,27720,45360,50400,55440,83160,110880,166320,221760,277200,332640,498960,500001}; const int fact[36] = {1,2,3,4,6,8,9,10,12,16,18,20,24,30,32,36,40,48,60,64,72,80,84,90,96,100,108,120,128,144,160,168,180,192,200};int N, B, v[maxn]; char name[maxn][20];void build (int u, int l, int r) {nd[u].set(l, r, r - l + 1);if (l == r) return ;int mid = (l + r) / 2;build(lson(u), l, mid);build(rson(u), mid + 1, r); }int query(int u, int x) {nd[u].s--;if (nd[u].l == nd[u].r)return nd[u].l;if (nd[lson(u)].s >= x)return query(lson(u), x);elsereturn query(rson(u), x - nd[lson(u)].s); }int bsearch (int x) {int l = 0, r = 35;for (int i = 0; i < 20; i++) {int mid = (l + r) / 2;if (antipri[mid] > x)r = mid;elsel = mid;}return l; }int main () {while (scanf("%d%d", &N, &B) == 2) {for (int i = 1; i <= N; i++)scanf("%s%d", name[i], &v[i]);build(1, 1, N);v[0] = 0;int E = bsearch(N), k = 0;for (int i = N; i; i--) {B = ((B + v[k] - (v[k] > 0 ? 2 : 1)) % i + i) % i + 1;k = query(1, B);if (N - i + 1 == antipri[E]) {printf("%s %d\n", name[k], fact[E]);break;}}}return 0; }

轉載于:https://www.cnblogs.com/zfyouxi/p/5159854.html

總結

以上是生活随笔為你收集整理的poj 2886 Who Gets the Most Candies?(线段树)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。