【BZOJ4724】[POI2017]Podzielno 数学+二分
【BZOJ4724】[POI2017]Podzielno
Description
Input
Output
Sample Input
1 1 1
0
1
2
Sample Output
2
-1
题解:因为B与B-1互质,所以X是B-1的倍数当且仅当X在B进制下的每一位加起来是B-1的倍数。(在循环之美那题里用到了这个结论,不过我只是看了看~)
然后我们肯定是先全都选,然后看总和%B是多少,然后看最少删掉几个数。一开始还想了想怎么删,后来发现a[i]>=1。。。就直接把那个数删了就行。
然后剩下的数,一定是从大到小一个一个排下来。特判:如果总和%B=0,则不用删!
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
int n,m;
ll v[1000010];
inline ll rd()
{
ll ret=0,f=1; char gc=getchar();
while(gc<'0'||gc>'9') {if(gc=='-') f=-f; gc=getchar();}
while(gc>='0'&&gc<='9') ret=ret*10+gc-'0',gc=getchar();
return ret*f;
}
int main()
{
n=rd(),m=rd();
int i,l,r,mid;
for(i=0;i<n;i++) v[i]=rd(),v[n]=(v[n]+i*v[i])%(n-1);
if(v[n]) v[v[n]]--;
for(i=1;i<n;i++) v[i]+=v[i-1];
for(i=1;i<=m;i++)
{
ll a=rd();
l=0,r=n;
while(l<r)
{
mid=(l+r)>>1;
if(v[mid]>a) r=mid;
else l=mid+1;
}
printf("%d\n",r==n?-1:r);
}
return 0;
}//9 11 1 1 1 1 1 1 1 1 1 0 1 2 3 4 5 6 7 8 9 10
【BZOJ4724】[POI2017]Podzielno 数学+二分的更多相关文章
- BZOJ4724 [POI2017]Podzielno
4724: [POI2017]Podzielno Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 77 Solved: 37[Submit][Stat ...
- bzoj 4724 [POI2017]Podzielno 二分+模拟
[POI2017]Podzielno Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 364 Solved: 160[Submit][Status][ ...
- 【bzoj4724】[POI2017]Podzielno 二分
题目描述 B进制数,每个数字i(i=0,1,...,B-1)有a[i]个.你要用这些数字组成一个最大的B进制数X(不能有前导零,不需要用完所有数字),使得X是B-1的倍数.q次询问,每次询问X在B进制 ...
- HDU 6216 A Cubic number and A Cubic Number(数学/二分查找)
题意: 给定一个素数p(p <= 1e12),问是否存在一对立方差等于p. 分析: 根据平方差公式: 因为p是一个素数, 所以只能拆分成 1*p, 所以 a-b = 1. 然后代入a = b + ...
- BZOJ 4724: [POI2017]Podzielno
Description 由\([0,B-1]\)的数字构造一个 \(B\) 进制数字,使得他是 \(B-1\) 的倍数. Sol 贪心+二分. 首先 \(X\) 是 \(B-1\) 的倍数,那么有 \ ...
- UVA 10668 - Expanding Rods(数学+二分)
UVA 10668 - Expanding Rods 题目链接 题意:给定一个铁棒,如图中加热会变成一段圆弧,长度为L′=(1+nc)l,问这时和原来位置的高度之差 思路:画一下图能够非常easy推出 ...
- Success Rate CodeForces - 807C (数学+二分)
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces ...
- CF 483B. Friends and Presents 数学 (二分) 难度:1
B. Friends and Presents time limit per test 1 second memory limit per test 256 megabytes input stand ...
- HDU 5646 DZY Loves Partition 数学 二分
DZY Loves Partition 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5646 Description DZY loves parti ...
随机推荐
- 笛卡尔树 POJ ——1785 Binary Search Heap Construction
相应POJ 题目:点击打开链接 Binary Search Heap Construction Time Limit: 2000MS Memory Limit: 30000K Total Subm ...
- Python绘制分段函数
1.绘制分段函数:y=4sin(4πt)-sgn(t-0.3)-sgn(0.72-t) import numpy as npimport matplotlib.pyplot as plt#绘制分段函数 ...
- 转: Your build settings specify a provisioning profile with the UUID, no provisioning profile was found
http://blog.csdn.net/rbyyyblog/article/details/12220875 在Archive项目时,出现了“Your build settings specify ...
- SQL中的ISNULL函数介绍
SQL中有多种多样的函数,下面将为您介绍SQL中的ISNULL函数,包括其语法.注释.返回类型等,供您参考,希望对您学习SQL能够有所帮助. ISNULL 使用指定的替换值替换 NULL. 语法ISN ...
- W25Q128页数和扇区数
int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_size){ *block_size = 4 ...
- svn的外网设置访问方法
一.花生壳 1. 设置静态ip 选择 DHCP服务器 -> 静态地址分配,为内网内的机器分配静态ip 2.设置端口转发 选择 转发规则 -> 虚拟服务器,将外网对443端口的访问转发到安装 ...
- UML序列图
先准备好之前的类图,然后在最开始的地方新添加一个版块“交互设计” Add Diagram --> Sequence Diagram Add --> Actor建立一个user 然后就可以拖 ...
- eclipse + MinGW调试程序printf输出被buffer的问题
比如说一个 1. int x = 1;2. printf("xxx")3. int y = 2;调试的时候,运行第二行,但是控制台没有输出.必须调试到整个程序都结束的时候才会把所有 ...
- 可以开发着玩一下的web项目
博客项目:发布博客,写博客 车辆.车队管理系统 教师评价系统 仓储管理系统 进销存管理系统 客户管理系统 结算系统 医院病历管理系统
- Leetcode392. Is Subsequence
Description Given a string s and a string t, check if s is subsequence of t. You may assume that the ...