亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

Codeforces 732E Sockets【貪心】

2019-11-06 06:32:25
字體:
來源:轉載
供稿:網友

E. Socketstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

The ICM ACPC World Finals is coming! Unfortunately, the organizers of the competition were so busy PReparing tasks that totally missed an important technical point — the organization of electricity supplement for all the participants workstations.

There are n computers for participants, thei-th of which has power equal to positive integerpi. At the same time there arem sockets available, the j-th of which has power euqal to positive integer sj. It is possible to connect thei-th computer to the j-th socket if and only if their powers are the same: pi?=?sj. It is allowed to connect no more than one computer to one socket. Thus, if the powers of all computers and sockets are distinct, then no computer can be connected to any of the sockets.

In order to fix the situation professor Puch Williams urgently ordered a wagon of adapters — power splitters. Each adapter has one plug and one socket with a voltage divider between them. After plugging an adapter to a socket with powerx, the power on the adapter's socket becomes equal to, it means that it is equal to the socket's power divided by two with rounding up, for example and.

Each adapter can be used only once. It is possible to connect several adapters in a chain plugging the first to a socket. For example, if two adapters are plugged one after enother to a socket with power10, it becomes possible to connect one computer with power3 to this socket.

The organizers should install adapters so that it will be possible to supply with electricity the maximum number of computersc at the same time. If there are several possible connection configurations, they want to find the one that uses the minimum number of adaptersu to connect c computers.

Help organizers calculate the maximum number of connected computers c and the minimum number of adapters u needed for this.

The wagon of adapters contains enough of them to do the task. It is guaranteed that it's possible to connect at least one computer.

Input

The first line contains two integers n andm (1?≤?n,?m?≤?200?000) — the number of computers and the number of sockets.

The second line contains n integers p1,?p2,?...,?pn (1?≤?pi?≤?109) — the powers of the computers.

The third line contains m integers s1,?s2,?...,?sm (1?≤?si?≤?109) — the power of the sockets.

Output

In the first line print two numbers c andu — the maximum number of computers which can at the same time be connected to electricity and the minimum number of adapters needed to connectc computers.

In the second line print m integers a1,?a2,?...,?am (0?≤?ai?≤?109), where ai equals the number of adapters orginizers need to plug into thei-th socket. The sum of all ai should be equal to u.

In third line print n integers b1,?b2,?...,?bn (0?≤?bi?≤?m), where the bj-th equals the number of the socket which thej-th computer should be connected to. bj?=?0 means that the j-th computer should not be connected to any socket. All bj that are different from0 should be distinct. The power of the j-th computer should be equal to the power of the socket bj after plugging in abj adapters. The number of non-zerobj should be equal toc.

If there are multiple answers, print any of them.

ExamplesInput
2 21 12 2Output
2 21 11 2Input
2 12 10099Output
1 661 0

題目大意:

一共有N個插座,有M臺電腦,一臺電腦和插座可以相連的要求是:pi==si.現在希望盡可能多的電腦能夠連在插排上。

現在有一種分流插座,可以使得一臺電腦的si從si變成【si/2】【15/2】=8.

對于一臺電腦,我們也可以使用多個分流插座。

問最多能夠有幾臺電腦連在插排上,同時問需要多少個分流插座。

第二行輸出每個電腦用的分流插座的數量。

第三行輸出每個插排連接的電腦編號。

思路:

首先我們將插排和電腦按照值從小到大排序。

然后我們暴力處理,將每個電腦不斷的/2.如果遇到了一個插排可以與之匹配,那么直接相連接即可。

常數大的話是會TLE的,做好底層優化,剩下的vector和map亂搞亂存就行。

Ac代碼:

#include<stdio.h>#include<string.h>#include<algorithm>#include<vector>#include<map>using namespace std;#define ll __int64struct node{    ll pos,val;}b[200050],a[200050];vector<ll >mp[200050];ll from[200050];ll use[200050];ll ned[200050];ll ans[200050];ll cmp(node a,node b){    return a.val<b.val;}int main(){    ll n,m;    while(~scanf("%I64d%I64d",&n,&m))    {        map<ll ,ll >s;        memset(from,0,sizeof(from));        memset(use,0,sizeof(use));        memset(ans,-1,sizeof(ans));        for(int i=0;i<=n+m;i++)mp[i].clear();        for(ll i=0;i<n;i++)scanf("%I64d",&a[i].val),a[i].pos=i;        for(ll i=0;i<m;i++)scanf("%I64d",&b[i].val),b[i].pos=i;        sort(a,a+n,cmp);        sort(b,b+m,cmp);        int cnt=1;        for(int i=0;i<n;i++)        {            if(s[a[i].val]==0)            {                s[a[i].val]=cnt;                cnt++;            }            mp[s[a[i].val]].push_back(a[i].pos);        }        int num=0,tot=0;        for(int i=0;i<m;i++)        {            int contz=0;            while(b[i].val)            {                int ok=0;                if(s[b[i].val]!=0)                {                    for(int j=from[s[b[i].val]];j<mp[s[b[i].val]].size();j++)                    {                        int v=mp[s[b[i].val]][j];                        if(ans[v]==-1)                        {                            from[s[b[i].val]]=j+1;                            ok=1;                            num++;                            tot+=contz;                            ned[b[i].pos]=contz;                            ans[v]=b[i].pos;                            break;                        }                    }                }                if(ok==1)break;                if(b[i].val==1)break;                if(b[i].val%2==1)b[i].val++;                b[i].val/=2;                contz++;            }        }        printf("%d %d/n",num,tot);        for(int i=0;i<m;i++)        {            printf("%d ",ned[i]);        }        printf("/n");        for(int i=0;i<n;i++)        {            printf("%d ",ans[i]+1);        }        printf("/n");    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
午夜精品福利在线观看| 亚洲国产精品免费| 韩国v欧美v日本v亚洲| 色哟哟入口国产精品| 国产精品久久久久久亚洲影视| 亚洲男女自偷自拍图片另类| 亚洲一区美女视频在线观看免费| 国产精品丝袜一区二区三区| 美女视频黄免费的亚洲男人天堂| 国产精品久久久久久av下载红粉| 午夜欧美不卡精品aaaaa| 亚洲va久久久噜噜噜久久天堂| 日韩大陆欧美高清视频区| 国产精品极品美女在线观看免费| 国产精品免费观看在线| 亚洲乱码国产乱码精品精| 国产成人精品999| 日韩美女福利视频| 日本伊人精品一区二区三区介绍| 国产精品白嫩美女在线观看| 欧洲永久精品大片ww免费漫画| 日韩视频免费中文字幕| 国产精品视频yy9099| 日韩av在线免播放器| 亚洲精品免费网站| 91精品视频大全| 97婷婷涩涩精品一区| 91精品国产免费久久久久久| 欧美日韩不卡合集视频| 日韩视频免费观看| 欧美精品在线第一页| 黑人巨大精品欧美一区二区三区| 欧洲成人免费aa| 九九精品在线视频| 日韩不卡在线观看| 久久天天躁狠狠躁夜夜爽蜜月| 九九久久久久久久久激情| 国产精品极品尤物在线观看| 亚洲人成绝费网站色www| 亚洲天堂av女优| 成人做爽爽免费视频| 在线看国产精品| 亚洲国产私拍精品国模在线观看| 国产精品啪视频| 亚洲国产日韩欧美综合久久| 亚洲欧美日韩视频一区| 欧美午夜激情视频| www日韩中文字幕在线看| 欧美三级欧美成人高清www| 亚洲国产精品久久久久秋霞蜜臀| 不卡av日日日| 欧美色视频日本高清在线观看| 欧美日韩福利在线观看| 国产一区二区黄| 日韩精品极品视频| 成人欧美一区二区三区黑人孕妇| 亚洲成人激情图| 成人黄在线观看| 91在线精品播放| 中文字幕日韩在线播放| 日本精品久久电影| 亚洲韩国青草视频| 国产999精品久久久| 久久欧美在线电影| 色婷婷综合成人| 亚洲欧美在线一区二区| 日本精品中文字幕| 日韩av网站电影| 国产精品午夜国产小视频| 国产丝袜一区二区三区| 欧美性色19p| 亚洲男人的天堂网站| 欧美日韩亚洲视频| 成人在线精品视频| 综合久久五月天| 国产成人免费av| 91亚洲精品在线| 中文字幕日韩有码| 亚洲第一av网| 亚洲free性xxxx护士hd| 91av视频在线免费观看| 97精品一区二区视频在线观看| 亚洲国产精品免费| 久久精品成人一区二区三区| 久久久免费高清电视剧观看| 亚洲国产古装精品网站| 国产精品一香蕉国产线看观看| 欧美性受xxx| 亚洲国产精品va在线观看黑人| 国产免费成人av| 久热精品视频在线观看| 奇米四色中文综合久久| 亚洲第一精品福利| 91久久精品久久国产性色也91| 亚洲精品视频久久| 波霸ol色综合久久| 久久精品视频在线观看| 成人做爽爽免费视频| 97精品一区二区三区| 午夜精品久久久久久久久久久久| 亚洲精品国产综合久久| 久久久www成人免费精品| 国产精品一区二区三区免费视频| 亚洲精品第一页| 亚洲欧洲一区二区三区久久| 91在线播放国产| 日韩**中文字幕毛片| 欧美激情精品久久久久久免费印度| 国产视频精品免费播放| 狠狠做深爱婷婷久久综合一区| 精品性高朝久久久久久久| 亚洲国产精品嫩草影院久久| 丰满岳妇乱一区二区三区| 人妖精品videosex性欧美| 国产丝袜一区二区| 久久人人97超碰精品888| 亚洲色图50p| 欧美激情免费在线| 欧美亚洲国产日韩2020| 高清亚洲成在人网站天堂| 久久躁日日躁aaaaxxxx| 久久久久久69| 日韩精品在线免费观看| 日韩a**中文字幕| 国产精品美女久久| 日韩欧美一区二区三区| 91系列在线播放| 亚洲全黄一级网站| 91精品久久久久久综合乱菊| 国产99久久精品一区二区永久免费| 久久艳片www.17c.com| 日韩中文字幕亚洲| 久久精品一区中文字幕| 欧美日韩国产激情| 精品毛片三在线观看| 亚洲的天堂在线中文字幕| 在线日韩欧美视频| 一色桃子一区二区| 91色琪琪电影亚洲精品久久| 中文字幕av一区二区三区谷原希美| 欧美国产乱视频| 亚洲色图18p| 欧美人与性动交| 国产日韩精品综合网站| 欧美激情女人20p| 亚洲欧美制服第一页| 久久精品国产久精国产一老狼| 亚洲国产成人久久综合一区| 久久久久日韩精品久久久男男| 国产一区二区在线播放| 欧美午夜精品伦理| 亚洲伊人久久综合| 国产成人亚洲精品| 国产91在线播放九色快色| 日韩网站免费观看高清| 日本三级韩国三级久久| 国产99久久精品一区二区| 国产精品视频专区| 久久久久中文字幕2018| 红桃av永久久久| 色婷婷综合久久久久中文字幕1| 欧美激情中文字幕在线| 欧美日韩中文字幕日韩欧美| 欧美一级片久久久久久久|