首页 技术 正文
技术 2022年11月18日
0 收藏 306 点赞 5,045 浏览 1707 个字

按顺时针给出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
*/
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,023
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,360
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,143
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,774
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,852