日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Mike and distribution(思维)

發布時間:2023/12/15 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Mike and distribution(思维) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Mike has always been thinking about the harshness of social inequality. He’s so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A?=?[a1,?a2,?…,?an] and B?=?[b1,?b2,?…,?bn] of length n each which he uses to ask people some quite peculiar questions.

To test you on how good are you at spotting inequality in life, he wants you to find an “unfair” subset of the original sequence. To be more precise, he wants you to select k numbers P?=?[p1,?p2,?…,?pk] such that 1?≤?pi?≤?n for 1?≤?i?≤?k and elements in P are distinct. Sequence P will represent indices of elements that you’ll select from both sequences. He calls such a subset P “unfair” if and only if the following conditions are satisfied: 2·(ap1?+?…?+?apk) is greater than the sum of all elements from sequence A, and 2·(bp1?+?…?+?bpk) is greater than the sum of all elements from the sequence B. Also, k should be smaller or equal to because it will be to easy to find sequence P if he allowed you to select too many elements!

Mike guarantees you that a solution will always exist given the conditions described above, so please help him satisfy his curiosity!

Input
The first line contains integer n (1?≤?n?≤?105) — the number of elements in the sequences.

On the second line there are n space-separated integers a1,?…,?an (1?≤?ai?≤?109) — elements of sequence A.

On the third line there are also n space-separated integers b1,?…,?bn (1?≤?bi?≤?109) — elements of sequence B.

Output
On the first line output an integer k which represents the size of the found subset. k should be less or equal to .

On the next line print k integers p1,?p2,?…,?pk (1?≤?pi?≤?n) — the elements of sequence P. You can print the numbers in any order you want. Elements in sequence P should be distinct.

Example
Input
5
8 7 4 8 3
4 2 5 3 7
Output
3
1 4 5
題意:給你兩組序列a和b。讓你從中選出兩個序列中找出最多n/2+1個下標相同的數字。使得從兩個數組中選出來的這些數字和比原數組和一半要大。
思路:最多選取n/2+1個數字,貪心的思想肯定要選最多的數字。而且選的越大越好。所以我們對于a數組按著降序排序。根據a數組降序的位置去找b數組中較大的那個數。相當于把原來的數組分成了n/2的集合。
代碼如下:

#include<bits/stdc++.h> #define ll long long using namespace std;const int maxx=1e5+100; ll a[maxx]; ll b[maxx]; struct node{int pos;ll v;bool operator<(const node &c)const{return v>c.v;} }p[maxx]; int n;int main() {scanf("%d",&n);ll sum1=0,sum2=0;for(int i=1;i<=n;i++) scanf("%I64d",&a[i]),p[i].pos=i,p[i].v=a[i];for(int i=1;i<=n;i++) scanf("%I64d",&b[i]);sort(p+1,p+1+n);cout<<(n/2+1)<<endl;printf("%d",p[1].pos);//最大的數字最好選上for(int i=2;i<=n;i+=2){if(i==n) printf(" %d",p[i].pos);else printf(" %d",b[p[i].pos]>b[p[i+1].pos]?p[i].pos:p[i+1].pos);}cout<<endl; }

努力加油a啊,(o)/~

總結

以上是生活随笔為你收集整理的Mike and distribution(思维)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。