标签:
注意只有一个素因子的情况。
1 #include <cstdio> 2 #include <algorithm> 3 #include <cstring> 4 5 using namespace std; 6 7 typedef long long ll; 8 const int INF = 0x3f3f3f3f; 9 const int maxn = 4e3+10; 10 struct cake 11 { 12 int w,l; 13 cake(){} 14 bool operator < (const cake &b) const 15 { 16 return l > b.l; 17 } 18 }ck[maxn]; 19 20 int N,len[maxn]; 21 22 int main() 23 { 24 scanf("%d",&N); 25 26 for(int i=0;i<N;i++) 27 { 28 scanf("%d%d",&ck[i].w,&ck[i].l); 29 if(ck[i].w > ck[i].l) swap(ck[i].w,ck[i].l); 30 } 31 32 sort(ck,ck+N); 33 34 int m; 35 int answ,ansl; 36 ll ans = -INF; 37 38 for(int i=0;i<N;i++) 39 { 40 m = 0; 41 for(int j=0;j<N;j++) 42 { 43 if(ck[j].w >= ck[i].w) 44 { 45 len[m++] = ck[j].l; 46 } 47 } 48 for(int j=0;j<m;j++) 49 { 50 ll res = (ll)ck[i].w*len[j]*(j+1); 51 if(res > ans) 52 { 53 ans = res; 54 answ = ck[i].w; 55 ansl = len[j]; 56 } 57 } 58 } 59 printf("%I64d\n%d %d\n",ans,answ,ansl); 60 61 }
HDU 4344-Mark the Rope-大数素因子分解
标签:
原文地址:http://www.cnblogs.com/helica/p/5229319.html