• 题意:有一长度为\(n\)的序列,求其中任意五个元素乘积的最大值.

  • 题解:先排序,然后乘积能是正数就搞正数,模拟一下就好了.

  • 代码:

    int t;
    ll n;
    ll a[N]; int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>t;
    while(t--){
    cin>>n;
    for(int i=1;i<=n;++i){
    cin>>a[i];
    }
    sort(a+1,a+1+n);
    ll cnt1=a[n]*a[n-1]*a[n-2]*a[n-3]*a[n-4];
    ll cnt2=a[1]*a[2]*a[3]*a[4]*a[5];
    ll cnt3=a[n]*a[1]*a[2]*a[3]*a[4];
    ll cnt4=a[1]*a[2]*a[n]*a[n-1]*a[n-2];
    ll res=max(cnt1,max(cnt2,max(cnt3,cnt4)));
    cout<<res<<endl;
    } return 0;
    }

Codeforces Round #670 (Div. 2) B. Maximum Product (暴力)的更多相关文章

  1. Codeforces Round #670 (Div. 2) 深夜掉分(A - C题补题)

    1406A. Subset Mex https://codeforces.com/contest/1406/problem/A Example input 4 6 0 2 1 5 0 1 3 0 1 ...

  2. Codeforces Round #221 (Div. 1) B. Maximum Submatrix 2 dp排序

    B. Maximum Submatrix 2 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...

  3. Codeforces Round #276 (Div. 1) B. Maximum Value 筛倍数

    B. Maximum Value Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/prob ...

  4. Codeforces Round #508 (Div. 2) E. Maximum Matching(欧拉路径)

     E. Maximum Matching 题目链接:https://codeforces.com/contest/1038/problem/E 题意: 给出n个项链,每条项链左边和右边都有一种颜色(范 ...

  5. Codeforces Round #172 (Div. 2) D. Maximum Xor Secondary 单调栈应用

    http://codeforces.com/contest/281/problem/D 要求找出一个区间,使得区间内第一大的数和第二大的数异或值最大. 首先维护一个单调递减的栈,对于每个新元素a[i] ...

  6. Codeforces Round #276 (Div. 1)B. Maximum Value 筛法

    D. Maximum Value     You are given a sequence a consisting of n integers. Find the maximum possible ...

  7. Codeforces Round #445 Div. 1 C Maximum Element (dp + 组合数学)

    题目链接: http://codeforces.com/contest/889/problem/C 题意: 给你 \(n\)和 \(k\). 让你找一种全排列长度为\(n\)的 \(p\),满足存在下 ...

  8. Codeforces Round #599 (Div. 2) A. Maximum Square 水题

    A. Maximum Square Ujan decided to make a new wooden roof for the house. He has

  9. Codeforces Round #555 (Div. 3) F. Maximum Balanced Circle

    F. Maximum Balanced Circle 题目链接 题意 给出\(n\)个数,现在要从中选出最多的数\(b_i,b_{i+1},\cdots,b_k\),将这些数连成一个环,要求两两相邻的 ...

随机推荐

  1. 【Java】单例模式(Singleton)

    重新搞一波 复习巩固 简单记录 慕课网 Java工程师 文章目录 单例概述 设计模式 单例模式(Singleton) 参考资料 单例概述 Singleton Pattern 单例模式是Java中最简单 ...

  2. zabbix 监控的数据

    /usr/local/zabbix/bin/zabbix_sender --zabbix-server 192.168.1.10 --port 10051 --input-file /var/log/ ...

  3. ctfhub技能树—文件上传—前端验证

    打开靶机 查看页面信息 尝试直接上传一句话木马 提示不允许上传 查看源码 发现仅允许上传.jpg,.png,.gif三种格式的文件 上传shell.jpg并使用burpsuite抓取数据包 添加完成后 ...

  4. oracle常见进度查询脚本

    1.查看索引创建进度 /* Formatted on 2019/8/20 下午 05:08:25 (QP5 v5.163.1008.3004) */ SELECT SID, DECODE (total ...

  5. AQS之ReentrantReadWriteLock精讲分析上篇

    1.用法 1.1 定义一个安全的list集合 public class LockDemo { ArrayList<Integer> arrayList = new ArrayList< ...

  6. F4IF_INT_TABLE_VALUE_REQUEST选择屏幕自定义F4帮助

    今天在用 F4IF_INT_TABLE_VALUE_REQUEST函数写选择屏幕的自定义帮助的时候,发现了个问题,那就是 F4IF_INT_TABLE_VALUE_REQUEST中参数value_ta ...

  7. 以我的亲身经历,聊聊学python的流程,同时推荐学python的书

    因为干活要用到,所以我大概于19年5月开始学python,大概学了1个月后,我就能干公司的活了,而且这python项目还包含了机器学习等要素,大概3个月后,我还承担了项目里开发机器学习数据分析的任务. ...

  8. C#从入门到放弃治疗一:初探C#世界

    C#是一款高级的面向对象语言,运行于.NET framework之上的高级程序设计语言.其语言规范和,语法和java有着惊人的类似之处.所以如果你在学习C#之前有着java的基础,你将快速地入门.当然 ...

  9. Django orm中related_name/related_query_name区别

    related_name/related_query_name区别 class Department(models.Model): title = models.CharField(verbose_n ...

  10. Simple decorator that intercepts connection errors and ignores these if settings specify this.

    django-redis/cache.py at master · jazzband/django-redis https://github.com/jazzband/django-redis/blo ...