【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 ...
随机推荐
- SAP MM模块 经常使用函数
1. MM_CURRENT_PRICE_DOCUMENT 2. ME_READ_HISTORY 获取採购行项目的历史记录 CALL FUNCTION 'ME_READ_HISTORY' ...
- 使用Nginx+uWSGI+Django方法部署Django程序(上)
Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比较常见的一种方式. 在这种方式中,我们的通常做法是,将nginx作为服务器最前端,它将接收WEB的所有请求,统一管理请求.ng ...
- grid 布局 设置行列间距
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...
- SpringBoot Tips
读取资源文件 @RestController @EnableAutoConfiguration public class ResourcesController { @Autowired privat ...
- Spring 配置dataSource和sessionFactory
记得导入dbcp和pool的jar包. <?xml version="1.0" encoding="UTF-8"?> <beans xml ...
- tcp/ip ---数据链路层
- "《 Serial Drivers 》by Alessandro Rubini" 学习笔记
Introduction to "serial device driver" (My study note) 膜拜大神的作品. Standing on the should ...
- 203. Remove Linked List Elements【easy】
203. Remove Linked List Elements[easy] Remove all elements from a linked list of integers that have ...
- 生产环境中 Ngx_lua 使用技巧和应用的范例
生产环境中 Ngx_lua 使用技巧和应用的范例 时间 -- :: 51CTO技术博客 原文 http://rfyiamcool.blog.51cto.com/1030776/1252501 主题 L ...
- c++ about SLL(Static-Link Library) and DLL(Dynamic-Link Library)
First thing first, Wiki: http://en.wikipedia.org/wiki/Dynamic-link_library http://en.wikipedia.org/w ...