当前位置:网站首页>[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
边栏推荐
- Halo open source project learning (I): project launch
- What is a dial-up server and what is its use?
- NPM yarn startup error [resolved]
- Keil MDK Chinese garbled code, two solutions, the font is no longer ugly
- How to configure iptables to realize local port forwarding
- PID refinement
- Heap overflow of kernel PWN basic tutorial
- Thinkphp内核开发盲盒商城源码v2.0 对接易支付/阿里云短信/七牛云存储
- 什么是bgp服务器,有哪些优势?
- 一些使用代理IP的小技巧。
猜你喜欢
How to write the resume of Software Test Engineer so that HR can see it?
002_Redis_String类型常见的操作命令
Virtual serial port function of j-link V9 using skills
How to classify proxy IP?
Open3d point cloud processing
LeetCode 447. Number of boomerangs (permutation and combination problem)
搭建个人主页保姆级教程(二)
How to call out services in idea and display the startup class in services
What is BGP server and what are its advantages?
postman里面使用 xdebug 断点调试
随机推荐
Why is one plus one equal to two
2018 China Collegiate Programming Contest - Guilin Site J. stone game
[Dahua cloud native] micro service chapter - service mode of five-star hotels
89 logistic regression user portrait user response prediction
What are the common proxy IP problems?
Network jitter tool clumsy
PTA: 点赞狂魔
什么是bgp服务器,有哪些优势?
2018 China Collegiate Programming Contest - Guilin Site J. stone game
使用代理IP是需要注意什么?
Use of push() and pop()
Dynamic memory management
JDBC cannot connect to MySQL, and the error is access denied for user 'root' @ '* * *' (using password: Yes)
2022.4.22-----leetcode. three hundred and ninety-six
012_ Access denied for user ‘root‘@‘localhost‘ (using password: YES)
EBS:PO_EMPLOYEE_HIERARCHIES_ALL
搭建网站是用物理机还是云主机好?
我国科学家揭示突破水稻产量瓶颈新机制
Echo "new password" |passwd -- stdin user name
Find the largest number of two-dimensional arrays