Hrbust2016年校团队赛E题
2016-12-10 20:29
309 查看
Mod
Time Limit: 1000 MS Memory Limit: 100000 K
Total Submit: 28(5 users) Total Accepted: 8(4 users) Rating: Special Judge: No
Description
Kim刚刚学会C语言中的取模运算(mod)。他想要研究一下一个数字A模上一系列数后的结果是多少。帮他写个程序验证一下。
Input
第一行一个整数T代表数据组数。
接下来T组数据,第一行一个整数n,接下来n个数字ai
接下来一行一个整数m,接下来m个数字bi。
Output
对于每个bi,输出bi%a1%a2%…%an 。
Sample Input
1
4
10 9 5 7
5
14 8 27 11 25
Sample Output
4
3
2
1
0
Hint
在C语言中,A mod B 是 a%b
样例解释:
14%10%9%5%7=4
8%10%9%5%7=3
…
数据范围:
1<=n<=100000
1<=m<=100000
1<=ai<=1000000000
0<=bi<=1000000000
Source
“科林明伦杯”哈尔滨理工大学第六届程序设计团队赛
题解:线段树维护即可,跟HDU5875做法相同,不再说明。
代码:
Time Limit: 1000 MS Memory Limit: 100000 K
Total Submit: 28(5 users) Total Accepted: 8(4 users) Rating: Special Judge: No
Description
Kim刚刚学会C语言中的取模运算(mod)。他想要研究一下一个数字A模上一系列数后的结果是多少。帮他写个程序验证一下。
Input
第一行一个整数T代表数据组数。
接下来T组数据,第一行一个整数n,接下来n个数字ai
接下来一行一个整数m,接下来m个数字bi。
Output
对于每个bi,输出bi%a1%a2%…%an 。
Sample Input
1
4
10 9 5 7
5
14 8 27 11 25
Sample Output
4
3
2
1
0
Hint
在C语言中,A mod B 是 a%b
样例解释:
14%10%9%5%7=4
8%10%9%5%7=3
…
数据范围:
1<=n<=100000
1<=m<=100000
1<=ai<=1000000000
0<=bi<=1000000000
Source
“科林明伦杯”哈尔滨理工大学第六届程序设计团队赛
题解:线段树维护即可,跟HDU5875做法相同,不再说明。
代码:
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #include <vector> #include <cmath> #include <set> #include <map> #include <algorithm> #define LL long long #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 using namespace std; const int N=100002; LL sum[N<<2]; LL a ; int x,y,n,m,t; LL ans; void pushup(int rt) { sum[rt]=min(sum[rt<<1],sum[rt<<1|1]); } void build(int l,int r,int rt) { if(l==r) { scanf("%d",&sum[rt]); a[l]=sum[rt]; } else { int mid=(r+l)>>1; build(lson); build(rson); pushup(rt); } } int query(int l,int r,int ll,int rr,int rt,int k) { if(sum[rt]>k) return rr+1; if(ll<=l&&rr>=r) { if(l==r) { return l; } int mid=(r+l)>>1; if(sum[rt<<1]<=k) return query(l,mid,ll,rr,rt<<1,k); else return query(mid+1,r,ll,rr,rt<<1|1,k); } else { int mid=(r+l)>>1,res; if(ll<=mid) { res=query(l,mid,ll,rr,rt<<1,k); if(res<=rr) return res; } if(rr>mid) { res=query(mid+1,r,ll,rr,rt<<1|1,k); if(res<=rr) return res; } } return rr+1; } int main() { scanf("%d",&t); while(t--) { scanf("%d",&n); build(1,n,1); scanf("%d",&m); while(m--) { scanf("%lld",&ans); x=1; while(1) { int q=query(1,n,x,n,1,ans); if(q<=n) ans%=a[q]; else break; x=q+1; } printf("%lld\n",ans); } } }
相关文章推荐
- windows下常用网络命令
- PAT 1123. Is It a Complete AVL Tree (30)
- Java虚拟机(一)
- HMM 隐马尔可夫模型 代码实现
- 用Model-View-ViewModel构建iOS App(转)
- 时间复杂度
- codeforces 358
- 日期类模板 , 该日期是第几天,第几天的日期,两个日期的差 ,一个日期的n天之后的日期...
- 时间格式类
- 集合List,ArrayList,Collection第15天
- navicat for mysql ,从远程数据库中到数据到本地数据库(笨办法)
- JAVA WEB 学习笔记 Idea下常用配置-Hello Servlet。
- 数据结构实验之查找三:树的种类统计
- 第十五周oj训练——判断字符串是否为回文(2802)
- 媒体查询
- 513前端学习资料----dojo入门(1)
- 这是个类和对象
- 在Mac上使用vim的几个命令
- python标准库
- ChatRichTextBox : RichTextBox