当前位置:网站首页>[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
边栏推荐
- 配置iptables实现本地端口转发的方法详解
- JDBC cannot connect to MySQL, and the error is access denied for user 'root' @ '* * *' (using password: Yes)
- 从开源爱好者到 Apache 董事,一共分几步?
- 关于局域网浅谈
- OJ daily practice - Finish
- Is it better to use a physical machine or a virtual machine to build a website?
- MySQL basic record
- Gray scale range corresponding to colors (red, yellow, green, blue, purple, pink, brick red and magenta) in HSV color space
- MySQL active / standby configuration binary log problem
- 89 régression logistique prédiction de la réponse de l'utilisateur à l'image de l'utilisateur
猜你喜欢

Realize linear regression with tensorflow (including problems and solutions in the process)

RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio

有哪些业务会用到物理服务器?

Find the largest number of two-dimensional arrays

使用代理IP是需要注意什么?

Shardingsphere introduction and sub table usage

Common formatting problems after word writing

Dynamic memory management

How to change the size of SVG pictures without width in openlayer

012_ Access denied for user ‘root‘@‘localhost‘ (using password: YES)
随机推荐
搭建个人主页保姆级教程(二)
用TensorFlow实现线性回归(包括过程中出现的问题及解决方法)
How to call out services in idea and display the startup class in services
What should I pay attention to when using proxy IP?
什么是代理IP池,如何构建?
010_StringRedisTemplate
我国科学家揭示突破水稻产量瓶颈新机制
What is an API interface?
[hands on learning] network depth v2.1 Sequence model
hyperscan --- 1
揭秘被Arm编译器所隐藏的浮点运算
Network jitter tool clumsy
How to write the resume of Software Test Engineer so that HR can see it?
单片机和4G模块通信总结(EC20)
What problems will you encounter when dialing VPS?
LeetCode 349. Intersection of two arrays (simple, array) Day12
Open3d point cloud processing
PTA: 点赞狂魔
002_Redis_String类型常见的操作命令
JDBC cannot connect to MySQL, and the error is access denied for user 'root' @ '* * *' (using password: Yes)