zoukankan      html  css  js  c++  java
  • [HDOJ5461]Largest Point

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5461

    比赛的时候没敢多想,直接把八个情况全部枚举出来。

      1 #include <cstdio>
      2 #include <cstring>
      3 #include <algorithm>
      4 #include <cmath>
      5 using namespace std;
      6 
      7 typedef long long LL;
      8 const int INF = 0x3f3f3f3f;
      9 const int maxn = 5000000+100;
     10 
     11 int t[maxn];
     12 int n;
     13 int a,b;
     14 
     15 int main() {
     16     int T;
     17     scanf("%d",&T);
     18     for(int tt = 1;tt <= T;++tt) {
     19         scanf("%d %d %d",&n,&a,&b);
     20         for(int i = 1;i <= n;++i) {
     21             scanf("%d",&t[i]);
     22         }
     23         int maxx1 = 0,maxx2 = 0;
     24         int mn1 = INF,mn2 = INF;
     25         int mm1 = -INF,mm2 = -INF;
     26         int nn1 = INF,nn2 = INF;
     27         for(int i = 1;i <= n;++i) {
     28             if(t[i] > mm1) {
     29                 mm2 = mm1;
     30                 mm1 = t[i];
     31             }
     32             else if(t[i] > mm2)
     33                 mm2 = t[i];
     34 
     35             if(t[i] < nn1) {
     36                 nn2 = nn1;
     37                 nn1 = t[i];
     38             }
     39             else if(t[i] < nn2)
     40                 nn2 = t[i];
     41             if(abs(t[i]) > abs(maxx1)) {
     42                 maxx2 = maxx1;
     43                 maxx1 = t[i];
     44             }
     45             else if(abs(t[i]) > abs(maxx2))
     46                 maxx2 = t[i];
     47 
     48             if(abs(t[i]) < abs(mn1)) {
     49                 mn2 = mn1;
     50                 mn1 = t[i];
     51             }
     52             else if(abs(t[i]) < abs(mn2))
     53                 mn2 = t[i];
     54 
     55         }
     56         LL res1,res2;
     57         if(a >= 0) {
     58             res1 = (LL)a*maxx1*maxx1;
     59             if(b >= 0) {
     60                 if(mm1 != maxx1) res1 += (LL)b*mm1;
     61                 else res1+= (LL)b*mm2;
     62             }
     63             else {
     64                 if(nn1 != maxx1) res1 += (LL)b*nn1;
     65                 else res1 += (LL)b*nn2;
     66             }
     67         }
     68         else {
     69             res1 = (LL)a*mn1*mn1;
     70             if(b >= 0) {
     71                 if(mm1 != mn1) res1 += (LL)b*mm1;
     72                 else res1 += (LL)b*mm2;
     73             }
     74             else {
     75                 if(nn1 != mn1) res1 += (LL)b*nn1;
     76                 else res1 += (LL)b*nn2;
     77             }
     78         }
     79         if(b >= 0) {
     80             res2 = (LL)b*mm1;
     81             if(a >= 0) {
     82                 if(maxx1 != mm1) res2 += (LL)a*maxx1*maxx1;
     83                 else res2 += (LL)a*maxx2*maxx2;
     84             }
     85             else {
     86                 if(mn1 != mm1) res2 += (LL)a*mn1*mn1;
     87                 else res2 += (LL)a*mn2*mn2;
     88             }
     89         }
     90         else {
     91             res2 = (LL)b*nn1;
     92             if(a >= 0) {
     93                 if(maxx1 != nn1) res2 += (LL)a*maxx1*maxx1;
     94                 else res2 += (LL)a*maxx2*maxx2;
     95             }
     96             else {
     97                 if(mn1 != nn1) res2 += (LL)a*mn1*mn1;
     98                 else res2 += (LL)a*mn2*mn2;
     99             }
    100         }
    101 
    102         printf("Case #%d: %I64d
    ", tt, max(res1,res2));
    103     }
    104     return 0;
    105 }
  • 相关阅读:
    Learning to Compare: Relation Network for Few-Shot Learning 论文笔记
    修改python import模块中的变量
    roslaunch保存的log文件没有打印的ERROR信息
    python json demo
    vscode 1.32.x按下鼠标左键无法拖曳选择,而旧一点的版本1.30.2可以
    java-ee--------jdbc
    集合
    关键字
    java面向对象
    数组
  • 原文地址:https://www.cnblogs.com/kirai/p/4822022.html
Copyright © 2011-2022 走看看