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 ...
随机推荐
- MySQL auto_increment的坑
背景: Innodb引擎使用B_tree结构保存表数据,这样就需要一个唯一键表示每一行记录(比如二级索引记录引用). Innodb表定义中处理主键的逻辑是: 1.如果表定义了主键,就使用主键唯一定位一 ...
- java web 学习三(Tomcat 服务器学习和使用2)
一.打包JavaWeb应用 在Java中,使用"jar"命令来对将JavaWeb应用打包成一个War包,jar命令的用法如下:
- 【LeetCode 169】Majority Element
Given an array of size n, find the majority element. The majority element is the element that appear ...
- MorningSale 介绍
MorningSale是一个WEB端的收集门店销售数据,显示销售数据的简单系统,我相信该系统能够有效的提高销售公司在门店销售数据收集 汇总 分析方面的工作效率. 主要功能介绍如下: 1.查看某个店面 ...
- htmlcss笔记--标签默认值样式重置css reset
1.<a>标签 有默认文字修饰:下划线, 去除:text-decoration:none; text-decoration属性值: none 默认.定义标准的文本. underline 定 ...
- 02《老罗Android开发视频教程》第二集:android系统框架的介绍
- “大数据讲师”、“Hadoop讲师”、“Spark讲师”、“云计算讲师”、“Android讲师”
王家林简介 Spark亚太研究院院长和首席专家,中国目前唯一的移动互联网和云计算大数据集大成者. 在Spark.Hadoop.Android等方面有丰富的源码.实务和性能优化经验.彻底研究了Spark ...
- LeetCode 234 Palindrome Linked List
Given a singly linked list, determine if it is a palindrome. 思路: 回文结构从后向前遍历与从前向后遍历的结果是相同的,可以利用一个栈的结构 ...
- leetcode@ [310] Minimum Height Trees
For a undirected graph with tree characteristics, we can choose any node as the root. The result gra ...
- 转载:mac系统XAMPP配置虚拟主机
安装完xampp后,想添加一个virsualhost,一直报错.查了半天资料,都是乱说,后来看到了一篇国外的文章,终于弄出来了,整理一下. 第一步,配置本地hosts sudo vi /etc/hos ...