hdu 5565 Clarke and baton 二分
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 二分的更多相关文章
- HDU 5565:Clarke and baton
Clarke and baton Accepts: 14 Submissions: 79 Time Limit: 12000/6000 MS (Java/Others) Memory Limi ...
- hdu 3433 A Task Process 二分+dp
A Task Process Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 5628 Clarke and math——卷积,dp,组合
HDU 5628 Clarke and math 本文属于一个总结了一堆做法的玩意...... 题目 简单的一个式子:给定$n,k,f(i)$,求 然后数据范围不重要,重要的是如何优化这个做法. 这个 ...
- HDU 3622 Bomb Game(二分+2-SAT)
Bomb Game Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 1007 Quoit Design(二分+浮点数精度控制)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU 2063 过山车(二分匹配入门)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 二分匹配最大匹配数简单题,匈牙利算法.学习二分匹配传送门:http://blog.csdn.ne ...
- 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 ...
- hdu 5465 Clarke and puzzle 二维线段树
Clarke and puzzle Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 5464 Clarke and problem dp
Clarke and problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php ...
随机推荐
- MSSQL 2005数据库与SP4补丁安装
Sql Server 2005 正确安装之前的win7配置: http://wenku.baidu.com/link?url=6T3jzVnu2XY_sfqfe9ZqQ_6dUOdrZwHc83baW ...
- mbr grub的区别
mbr是磁盘的物理扇区,不是程序名: 因为BIOS很小,功能有限,为了完成加载操作系统的功能,就产生了mbr: bios检测到一个硬盘后,将硬盘的0柱面.0磁头.1扇区的内容经过简单判断后, 至内存中 ...
- mysql explain中key_len的计算
ken_len表示索引使用的字节数,根据这个值,就可以判断索引使用情况,特别是在组合索引的时候,判断是否所有的索引字段都被查询用到. key_len显示了条件检索子句需要的索引长度,但 ORDER B ...
- 搞明白这八个问题,Linux系统就好学多了。
正在犹豫入坑Linux学习的同学或者已经入坑的同学,经常会问到这样八个问题.今天,这些问题我都会一一解答,希望我的看法能帮助各位同学.常言道“好的开始是成功的一半”,如果你明白了以下八个问题,就能有一 ...
- Mysql 多表联合查询效率分析及优化
1. 多表连接类型 1. 笛卡尔积(交叉连接) 在MySQL中可以为CROSS JOIN或者省略CROSS即JOIN,或者使用',' 如: SELECT * FROM table1 CROSS JO ...
- <转>Python 参数知识(变量前加星号的意义)
csdn上的牛人就是多,加油 —————————————————————————— 过量的参数 在运行时知道一个函数有什么参数,通常是不可能的.另一个情况是一个函数能操作很多对象.更有甚者,调用自身的 ...
- stl+模拟 CCF2016 4 路径解析
// stl+模拟 CCF2016 4 路径解析 // 一开始题意理解错了.... #include <iostream> #include <string> #include ...
- android各种适配器的用法(转)
ArrayAdapter_SimpleAdapter_CursorAdapter的区别 数据源不同而已1. String[]: ArrayAdapter2. List<Map<String ...
- Orchard源码分析(1):插件式的支持——模块和主题
在Orchard,模块和主题都是可以插拔式的,在源码处理时,用类型(参考:DefaultExtensionTypes)区分,都没太大的本质区别,以下都称做模块. 插件的支持,实现分以下几步: 搜集模块 ...
- Spark系列(八)Worker工作原理
工作原理图 源代码分析 包名:org.apache.spark.deploy.worker 启动driver入口点:registerWithMaster方法中的case LaunchDriver ...