Clarke and baton

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5565

Description

Clarke is a patient with multiple personality disorder. One day, Clarke split into n guys, named 1 to n.
They will play a game called Lose Weight. Each of Clarkes has a weight a[i]. They have a baton which is always in the hand of who has the largest weight(if there are more than 2 guys have the same weight, choose the one who has the smaller order). The one who holds the baton needs to lose weight. i.e. a[i] decreased by 1, where i is the guy who holds the baton.
Now, Clarkes know the baton will be passed q times. They want to know each one's weight after finishing this game.

Input

The first line contains an integer T(1≤T≤10), the number of the test cases.
Each test case contains three integers n,q,seed(1≤n,q≤10000000,∑n≤20000000,1≤seed≤109+6), seed denotes the random seed.
a[i] generated by the following code.

long long seed;
int rand(int l, int r) {
static long long mo=1e9+7, g=78125;
return l+((seed*=g)%=mo)%(r-l+1);
}

int sum=rand(q, 10000000);
for(int i=1; i<=n; i++) {
a[i]=rand(0, sum/(n-i+1));
sum-=a[i];
}
a[rand(1, n)]+=sum;

Output

Each test case print a line with a number which is (b[1]+1)xor(b[2]+2)xor...xor(b[n]+n), where b[i] is the ith Clarke's weight after finishing the game.

Sample Input

1
3 2 1

Sample Output

20303

HINT

题意

给你1e7个数,每次可以使最大的数减一,可以减Q次

然后问你最后每个数亦或起来的答案是多少

题解:

二分答案,二分最后剩下来的最大的数是多少

然后我们注意一下,有可能Q次并没有减完,那么我们就让前面的去减一就好了

复杂度nlogn

代码

#include<iostream>
#include<stdio.h>
using namespace std;
long long seed;
long long a[];
int n,q;
int rand(int l, int r) {
static long long mo=1e9+, g=;
return l+((seed*=g)%=mo)%(r-l+);
}
int check(int x)
{
long long k = ;
for(int i=;i<=n;i++)
{
if(a[i]<x)continue;
k+=a[i]-x;
}
if(k>q)return ;
return ;
}
int main()
{
int t;scanf("%d",&t);
for(int cas=;cas<=t;cas++)
{ scanf("%d%d%I64d",&n,&q,&seed);
int sum=rand(q, );
for(int i=; i<=n; i++) {
a[i]=rand(, sum/(n-i+));
sum-=a[i];
}
a[rand(, n)]+=sum;
//for(int i=1;i<=n;i++)
// scanf("%d",&a[i]);
long long l = -10000000000LL,r = 1000000000000LL;
while(l<=r)
{
long long mid = (l+r)>>;
if(check(mid))r=mid-;
else l=mid+;
}
long long ans = ;
for(int i=;i<=n;i++)
{
if(a[i]<=l)continue;
q-=(a[i]-l);
}
for(int i=;i<=n;i++)
{
if(a[i]<l)
{
ans^=(a[i]+i);
}
else
{
if(q==)
{
ans^=(l+i);
}
else
{
ans^=(l-+i);
q--;
}
}
}
printf("%I64d\n",ans);
}
}

hdu 5565 Clarke and baton 二分的更多相关文章

  1. HDU 5565:Clarke and baton

    Clarke and baton  Accepts: 14  Submissions: 79  Time Limit: 12000/6000 MS (Java/Others)  Memory Limi ...

  2. hdu 3433 A Task Process 二分+dp

    A Task Process Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  3. HDU 5628 Clarke and math——卷积,dp,组合

    HDU 5628 Clarke and math 本文属于一个总结了一堆做法的玩意...... 题目 简单的一个式子:给定$n,k,f(i)$,求 然后数据范围不重要,重要的是如何优化这个做法. 这个 ...

  4. HDU 3622 Bomb Game(二分+2-SAT)

    Bomb Game Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. HDU 1007 Quoit Design(二分+浮点数精度控制)

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  6. HDU 2063 过山车(二分匹配入门)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 二分匹配最大匹配数简单题,匈牙利算法.学习二分匹配传送门:http://blog.csdn.ne ...

  7. hdu 5563 Clarke and five-pointed star 水题

    Clarke and five-pointed star Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/show ...

  8. hdu 5465 Clarke and puzzle 二维线段树

    Clarke and puzzle Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  9. hdu 5464 Clarke and problem dp

    Clarke and problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php ...

随机推荐

  1. delphi 编译的时候 把Warning去除的方法

    delphi  编译的时候  把Warning去除的方法 在 添加 {$WARNINGS OFF}

  2. js时间日期转时间戳

    var contractstarttimea='2016-01-01'; var contractendtimea='2016-05-01'; var contractstart = Date.par ...

  3. hdu 3518(后缀数组)

    题意:容易理解... 分析:这是我做的后缀数组第一题,做这个题只需要知道后缀数组中height数组代表的是什么就差不多会做了,height[i]表示排名第i的后缀与排名第i-1的后缀的最长公共前缀,然 ...

  4. Eclipse “Invalid Project Description” when creating new project from existing source

    1) File>Import>General>Existing Project into Workspace2) File>Import>Android>Exist ...

  5. Hadoop序列化

      遗留问题: Hadoop序列化可以复用对象,是在哪里复用的? 介绍Hadoop序列化机制 Hadoop序列化机制详解 Hadoop序列化的核心 Hadoop序列化的比较接口 ObjectWrita ...

  6. [Tommas] 一种有效的测试策略(转)

    在最近的一个大型项目中,我们在早期就定下了一个目标:不会在软件中使用大量QA人员专注于手工测试.通过手工测试发现bug极其耗时且成本高昂,这促使团队尝试尽可能的将质量内嵌到产品内部.但这并不意味着手工 ...

  7. 在xcode上搭建OpenGL3.x运行环境

    最近开始学习OpenGL,网上的教程太散乱,于是打算照着红宝书<OpenGL编程指南(第七版)>来学习. 于是在Mac上搭建一下Demo环境.比较方便的是,OS X上已经装了OpenGL ...

  8. ORA-15124 数据库启动阶段报错

    重新进行启动数据库的时候报错: SQL> startup nomount; ORA-15124: ASM file name '+KEL/ipap/controlfile/control02.c ...

  9. A题进行时--浙大PAT 1011-1020

    #include<stdio.h> #include<string.h> int main(){ ]; ]; ]; ]; ]; int i; float sum; memset ...

  10. 如何在安裝SELinux的环境执行Quartus II

    (原創) 如何在安裝SELinux的環境執行Quartus II? (SOC) (Quartus II) (Linux) (RedHat) Abstract一般人安裝Linux時,也會同時安裝SELi ...