码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 484B Maximum Value

时间:2015-04-05 23:28:19      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <vector>
 6 #define sc(x)  scanf("%d", &x)
 7 #define sc2(x,y)    scanf("%d%d", &x, &y)
 8 #define pf(x)    printf("%d\n",x)
 9 #define PF(x)    printf("%d ",x)
10 #define FOR(i,b,e)    for(int i=b;i<=e;i++)
11 #define FOR1(i,b,e)    for(int i=b;i>=e;i--)
12 #define CL(x,y)      memset(x,y,sizeof(x))
13 using namespace std;
14 const int MAX = 1000000;
15 vector <int> v;
16 int n;
17 long long used[MAX];
18 int main()
19 {
20     int tmp, ans;
21     while(~sc(n))
22     {
23         ans = 0;
24         CL(used, 0);
25         FOR(i,0,n-1)
26         {
27             sc(tmp);
28             used[tmp] = 1;
29             v.push_back(tmp);
30         }
31         sort(v.begin(), v.end());
32         FOR(i,0,n-2)
33         {
34             if(v[i] == 0 || v[i] == v[i+1])
35                 continue;
36             FOR(j,i+1,n-1)
37             {
38                 if(used[v[j]])
39                     ans = ans > (v[j] % v[i]) ? ans : (v[j] % v[i]);
40                 used[v[j]] = 0;
41             }
42         }
43         pf(ans);
44     }
45     return 0;
46 }
View Code

以上代码超时,不可以

 

必须真正有二分的思想解决

 

CodeForces 484B Maximum Value

标签:

原文地址:http://www.cnblogs.com/tyx0604/p/4394864.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!