当前位置:网站首页>[nk]牛客月赛48 D
[nk]牛客月赛48 D
2022-04-23 02:07:00 【RISE_lower】
题意
给定一个 n n n长度的 a [ ] a[] a[],你可以任意排列 a [ ] a[] a[]
最后使得交替相乘最大(这个是什么看题)
思路
贪心
显然的 (当然不是,我只会赛后口嗨
显然 我们让和最大的数先加,那么后面计算乘法的时候,贡献是最大的
因此我们考虑 (大的*大的)*大的+小的
400 400 400多个人过的贪心,感觉这个贪心好怪
code
c o s e c a n t cosecant cosecant大佬的
const int N = 1e5+10 ,mod = 1e9+7;
int a[N],n,b[N];
void solve(){
cin>>n;
for(int i=1;i<=n;i++) cin>>b[i];
sort(b+1,b+1+n);
int j = 1;
//偶数 用来加 (小的放后面加)
for(int i=n/2*2;i>=2;i-=2) a[i] = b[j++];
//奇数 用来乘 (大的放前面乘)
for(int i=1;i<=n;i+=2) a[i] = b[j++];
int s = a[1];
for(int i=2;i<=n;i++){
if(i&1){
//奇数的时候 是相乘
s = 1ll*s*a[i]%mod;
}else{
//偶数的时候是相加
s = (s+a[i])%mod;
}
}
cout<<s<<endl;
}
版权声明
本文为[RISE_lower]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_34364611/article/details/124355266
边栏推荐
- 什么是代理IP池,如何构建?
- [Leetcode每日一题]396. 旋转函数
- LeetCode 349. Intersection of two arrays (simple, array) Day12
- Uncover floating-point operations hidden by the ARM compiler
- Introduction to esp32 Bluetooth controller API
- 001_redis设置存活时间
- Quel est le fichier makefile?
- What should I pay attention to when using proxy IP?
- 拨号服务器是什么,有什么用处?
- Numerical remapping method (remap)
猜你喜欢
随机推荐
代理IP可用率是不是等同于代理IP的效率?
【汇编语言】从最底层的角度理解“堆栈”
MySQL basic record
有哪些常见的代理ip问题?
Numerical remapping method (remap)
Communication summary between MCU and 4G module (EC20)
On LAN
Esp32 message queue using FreeRTOS
浅析静态代理ip的三大作用。
007_Redis_Jedis连接池
Summary of I / O knowledge points
How to initialize "naming and surname" in C language
89 logistic回歸用戶畫像用戶響應度預測
How to "gracefully" measure system performance
Keil MDK Chinese garbled code, two solutions, the font is no longer ugly
What is a dial-up server and what is its use?
89 logistic回归用户画像用户响应度预测
php 2022年4月20面试题整理
006_redis_jedis快速入门
[hands on learning] network depth v2.1 Sequence model









