当前位置:网站首页>[NK] Niuke monthly race 48 D
[NK] Niuke monthly race 48 D
2022-04-23 02:08:00 【RISE_ lower】
The question
Given a n n n Of length a [ ] a[] a[], You can Arbitrary arrangement a [ ] a[] a[]
Finally make Alternating multiplication Maximum ( What is this? Look at the question )
Ideas
greedy
apparent ( Of course not. , I only say hi after the game
obviously We let And the largest number first add , Then calculate later Multiplication When , Contribution is the greatest
So we consider ( Big * Big )* Big + Small
400 400 400 Many people are greedy , Feel this greedy It's strange
code
c o s e c a n t cosecant cosecant The bosses
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;
// even numbers Used to add ( Put the small one in the back and add )
for(int i=n/2*2;i>=2;i-=2) a[i] = b[j++];
// Odd number Used to ride ( Put the big one in front of you )
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){
// When it's odd It's multiplication
s = 1ll*s*a[i]%mod;
}else{
// Even numbers are added
s = (s+a[i])%mod;
}
}
cout<<s<<endl;
}
版权声明
本文为[RISE_ lower]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230206445393.html
边栏推荐
- 每日一题(2022-04-22)——旋转函数
- 001_redis设置存活时间
- 关于局域网浅谈
- Talk about biology live broadcast: Dr. Wang Ziyuan, a lake view biology, exploring hepatitis B with gene therapy
- Is it better to use a physical machine or a virtual machine to build a website?
- LeetCode 447. Number of boomerangs (permutation and combination problem)
- Echo "new password" |passwd -- stdin user name
- How to "gracefully" measure system performance
- 拨号vps会遇到什么问题?
- Gray scale range corresponding to colors (red, yellow, green, blue, purple, pink, brick red and magenta) in HSV color space
猜你喜欢
我国科学家揭示突破水稻产量瓶颈新机制
拨号服务器是什么,有什么用处?
小程序 canvas 画布半圆环
LeetCode 447. Number of boomerangs (permutation and combination problem)
Heap overflow of kernel PWN basic tutorial
Under the pressure of sales, domestic mobile phones began to reduce prices, but they haven't put down their final face
有哪些业务会用到物理服务器?
How to write the resume of Software Test Engineer so that HR can see it?
005_redis_set集合
Is it better to use a physical machine or a virtual machine to build a website?
随机推荐
leetcode:27. 移除元素【count remove小操作】
Micro build low code zero foundation introductory course
Cc2541 emulator CC debugger tutorial
今天终于会写System.out.println()了
PHP & laravel & master several ways of generating token by API and some precautions (PIT)
使用代理IP是需要注意什么?
What should I pay attention to when using proxy IP?
Common formatting problems after word writing
什么是代理IP池,如何构建?
每日一题(2022-04-22)——旋转函数
Gray scale range corresponding to colors (red, yellow, green, blue, purple, pink, brick red and magenta) in HSV color space
How does Axure set the content of the text box to the current date when the page is loaded
Log4j2 configuration
Today will finally write system out. Println()
Shardingsphere read write separation
How to initialize "naming and surname" in C language
【Chrome扩展程序】content_script的跨域问题
Uncover floating-point operations hidden by the ARM compiler
2018 China Collegiate Programming Contest - Guilin Site J. stone game
RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio