Codeforces Gym 100623D Problem D. Deposits
2017-03-31 10:44
447 查看
题目传送门:http://codeforces.com/gym/100623/attachments
题解:暴力解决...先把第一组的数数量存起来,然后第二组数开始遍历10^6之内他的整数倍的数,然后把数量加起来,用了个小技巧,就是第二组数里如果找过了直接加,算了一下,总共最多跑10^7次,不会超时
Code:
题解:暴力解决...先把第一组的数数量存起来,然后第二组数开始遍历10^6之内他的整数倍的数,然后把数量加起来,用了个小技巧,就是第二组数里如果找过了直接加,算了一下,总共最多跑10^7次,不会超时
Code:
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; int m,n,b[100005],t,num[1000005]; long long ans,ans1; int main() { freopen("deposits.in","r",stdin); freopen("deposits.out","w",stdout); while(cin>>m) { memset(num,0,sizeof(num)); for(int i=1;i<=m;i++) { scanf("%d",&t); num[t]++; } cin>>n; for(int i=1;i<=n;i++) scanf("%d",&b[i]); sort(b+1,b+n+1); ans=t=ans1=0; for(int i=1;i<=n;i++) { if(b[i]==1) ans+=m; else if(b[i]==t) ans+=ans1; else { ans1=0; for(int j=b[i];j<=1000000;j+=b[i]) { if(num[j]) { ans+=num[j]; ans1+=num[j]; } } t=b[i]; } } cout<<ans<<endl; } return 0; }
相关文章推荐
- Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP
- Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造
- 【模拟】NEERC15 E Easy Problemset (Codeforces GYM 100851)
- 【模拟】NEERC15 E Easy Problemset (2015-2016 ACM-ICPC)(Codeforces GYM 100851)
- Codeforces Gym 100610 Problem E. Explicit Formula 水题
- Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞
- Codeforces Gym 100962 J. Jimi Hendrix
- Codeforces Gym 100199 B Reactor Cooling
- Codeforces Round #400 (Div. 1 + Div. 2, combined)D. The Door Problem【2-sat Tarjan+思维建图】
- CodeForcesGym 100641E Inspectors
- Codeforces Round #253 (Div. 2) D. Andrey and Problem (贪心+数学概率)
- Codeforces Gym 100338I TV Show DFS
- Codeforces GYM 100114 B. Island 水题
- Codeforces Gym 100325A String Decomposition 字符串DP
- Codeforces Gym 100379L Game with a string 博弈+交互题
- Codeforces Gym 101061 B RGB plants(矩阵快速幂)
- Codeforces Problem - 617B Chocolate
- CodeForces Gym 100989E Accepted Passwords
- Codeforces Gym 100500E IBM Chill Zone
- Codeforces Gym 101234D Forest Game