Maximum Value - CodeForces 484 B 水题
2014-11-06 10:53
393 查看
B. Maximum Value
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given a sequence a consisting of n integers.
Find the maximum possible value of
(integer
remainder of ai divided
by aj), where 1 ≤ i, j ≤ n and ai ≥ aj.
Input
The first line contains integer n — the length of the sequence (1 ≤ n ≤ 2·105).
The second line contains n space-separated integers ai (1 ≤ ai ≤ 106).
Output
Print the answer to the problem.
Sample test(s)
input
output
题意:找出ai%aj的值的最大值。
思路:排序后从小往大找,假设处理的是a,那么就找比a*2-1,a*3-1,a*4-1...小的最大值。
AC代码如下:
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given a sequence a consisting of n integers.
Find the maximum possible value of
(integer
remainder of ai divided
by aj), where 1 ≤ i, j ≤ n and ai ≥ aj.
Input
The first line contains integer n — the length of the sequence (1 ≤ n ≤ 2·105).
The second line contains n space-separated integers ai (1 ≤ ai ≤ 106).
Output
Print the answer to the problem.
Sample test(s)
input
3 3 4 5
output
2
题意:找出ai%aj的值的最大值。
思路:排序后从小往大找,假设处理的是a,那么就找比a*2-1,a*3-1,a*4-1...小的最大值。
AC代码如下:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> using namespace std; typedef long long ll; int num[2000110],maxn=1000000; int main() { int T,t,n,m,i,j,k,ans=0; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&k); num[k]=k; } for(i=1;i<=maxn*2+1;i++) if(num[i]!=i) num[i]=num[i-1]; for(i=2;i<=maxn;i++) if(num[i]==i) { for(j=i*2;j<=maxn*2+1;j+=i) { if(num[j-1]>i) ans=max(ans,num[j-1]%i); } } printf("%d\n",ans); }
相关文章推荐
- Bits - CodeForces 484 A 水题
- 51NOD 1421 最大MOD值&&Codeforces 484 B. Maximum Value(筛法 + 二分)
- CodeForces 484B 数学 Maximum Value
- CodeForces--621A--Wet Shark and Odd and Even(数学水题)
- codeforces水题100道 第五题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas (math)
- codeforces水题100道 第十五题 Codeforces Round #262 (Div. 2) A. Vasya and Socks (brute force)
- codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)
- codeforces 266A Stones on the Table(模拟水题)
- 【打CF,学算法——一星级】CodeForces 318A (水题)
- Codeforces 868 B Race Against Time(水题)
- CodeForces 352B 水题
- Codeforces--400A--Inna and Choose Options(模拟水题)
- CodeForces 705B Spider Man (水题)
- CodeForces 487A(水题)
- Codeforces 460A Vasya and Socks(水题)
- Codeforces 659A Round House【水题,细节】
- Codeforces 450A Jzzhu and Children(水题)
- codeforces 558B B. Amr and The Large Array(水题)
- codeforces 709A A. Juicer(水题)
- CodeForces-2015 HIAST Collegiate Programming Contest-Gym-100952A.水题 100952B.水题 100952C.回文字符串 100952D.杨辉三角处理组合数 其他题目待续。。。